@gitpod/gitpod-protocol 0.1.5-main.648 → 0.1.5-main.6480

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (455) hide show
  1. package/data/gitpod-schema.json +157 -29
  2. package/lib/accounting-protocol.d.ts +19 -14
  3. package/lib/accounting-protocol.d.ts.map +1 -1
  4. package/lib/accounting-protocol.js +44 -48
  5. package/lib/accounting-protocol.js.map +1 -1
  6. package/lib/admin-protocol.d.ts +44 -5
  7. package/lib/admin-protocol.d.ts.map +1 -1
  8. package/lib/admin-protocol.js +16 -1
  9. package/lib/admin-protocol.js.map +1 -1
  10. package/lib/analytics.d.ts +44 -0
  11. package/lib/analytics.d.ts.map +1 -0
  12. package/lib/analytics.js +10 -0
  13. package/lib/analytics.js.map +1 -0
  14. package/lib/attribution.d.ts +24 -0
  15. package/lib/attribution.d.ts.map +1 -0
  16. package/lib/attribution.js +54 -0
  17. package/lib/attribution.js.map +1 -0
  18. package/lib/auth.d.ts +1 -1
  19. package/lib/auth.d.ts.map +1 -1
  20. package/lib/auth.js +1 -1
  21. package/lib/billing-mode.d.ts +45 -0
  22. package/lib/billing-mode.d.ts.map +1 -0
  23. package/lib/billing-mode.js +44 -0
  24. package/lib/billing-mode.js.map +1 -0
  25. package/lib/blocked-repositories-protocol.d.ts +13 -0
  26. package/lib/blocked-repositories-protocol.d.ts.map +1 -0
  27. package/lib/blocked-repositories-protocol.js +8 -0
  28. package/lib/blocked-repositories-protocol.js.map +1 -0
  29. package/lib/context-url.d.ts +30 -0
  30. package/lib/context-url.d.ts.map +1 -0
  31. package/lib/context-url.js +100 -0
  32. package/lib/context-url.js.map +1 -0
  33. package/lib/context-url.spec.d.ts +12 -0
  34. package/lib/context-url.spec.d.ts.map +1 -0
  35. package/lib/context-url.spec.js +81 -0
  36. package/lib/context-url.spec.js.map +1 -0
  37. package/lib/encryption/container-module.d.ts +1 -1
  38. package/lib/encryption/container-module.d.ts.map +1 -1
  39. package/lib/encryption/container-module.js +5 -5
  40. package/lib/encryption/container-module.js.map +1 -1
  41. package/lib/encryption/encryption-engine.d.ts +1 -1
  42. package/lib/encryption/encryption-engine.d.ts.map +1 -1
  43. package/lib/encryption/encryption-engine.js +26 -27
  44. package/lib/encryption/encryption-engine.js.map +1 -1
  45. package/lib/encryption/encryption-engine.spec.d.ts +1 -1
  46. package/lib/encryption/encryption-engine.spec.d.ts.map +1 -1
  47. package/lib/encryption/encryption-engine.spec.js +30 -38
  48. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  49. package/lib/encryption/encryption-service.d.ts +1 -1
  50. package/lib/encryption/encryption-service.d.ts.map +1 -1
  51. package/lib/encryption/encryption-service.js +31 -45
  52. package/lib/encryption/encryption-service.js.map +1 -1
  53. package/lib/encryption/key-provider.d.ts +1 -1
  54. package/lib/encryption/key-provider.d.ts.map +1 -1
  55. package/lib/encryption/key-provider.js +32 -39
  56. package/lib/encryption/key-provider.js.map +1 -1
  57. package/lib/env.d.ts +1 -7
  58. package/lib/env.d.ts.map +1 -1
  59. package/lib/env.js +8 -28
  60. package/lib/env.js.map +1 -1
  61. package/lib/experiments/always-default.d.ts +8 -0
  62. package/lib/experiments/always-default.d.ts.map +1 -0
  63. package/lib/experiments/always-default.js +20 -0
  64. package/lib/experiments/always-default.js.map +1 -0
  65. package/lib/experiments/configcat-server.d.ts +10 -0
  66. package/lib/experiments/configcat-server.d.ts.map +1 -0
  67. package/lib/experiments/configcat-server.js +37 -0
  68. package/lib/experiments/configcat-server.js.map +1 -0
  69. package/lib/experiments/configcat.d.ts +21 -0
  70. package/lib/experiments/configcat.d.ts.map +1 -0
  71. package/lib/experiments/configcat.js +51 -0
  72. package/lib/experiments/configcat.js.map +1 -0
  73. package/lib/experiments/types.d.ts +22 -0
  74. package/lib/experiments/types.d.ts.map +1 -0
  75. package/lib/experiments/types.js +10 -0
  76. package/lib/experiments/types.js.map +1 -0
  77. package/lib/frontend-dashboard-service.d.ts +90 -0
  78. package/lib/frontend-dashboard-service.d.ts.map +1 -0
  79. package/lib/frontend-dashboard-service.js +49 -0
  80. package/lib/frontend-dashboard-service.js.map +1 -0
  81. package/lib/gitpod-file-parser.d.ts +1 -1
  82. package/lib/gitpod-file-parser.d.ts.map +1 -1
  83. package/lib/gitpod-file-parser.js +27 -43
  84. package/lib/gitpod-file-parser.js.map +1 -1
  85. package/lib/gitpod-file-parser.spec.d.ts +1 -1
  86. package/lib/gitpod-file-parser.spec.js +146 -143
  87. package/lib/gitpod-file-parser.spec.js.map +1 -1
  88. package/lib/gitpod-service.d.ts +191 -55
  89. package/lib/gitpod-service.d.ts.map +1 -1
  90. package/lib/gitpod-service.js +204 -298
  91. package/lib/gitpod-service.js.map +1 -1
  92. package/lib/headless-workspace-log.d.ts +10 -12
  93. package/lib/headless-workspace-log.d.ts.map +1 -1
  94. package/lib/headless-workspace-log.js +7 -9
  95. package/lib/headless-workspace-log.js.map +1 -1
  96. package/lib/ide-frontend-service.d.ts +2 -2
  97. package/lib/ide-frontend-service.js +1 -1
  98. package/lib/ide-protocol.d.ts +126 -0
  99. package/lib/ide-protocol.d.ts.map +1 -0
  100. package/lib/ide-protocol.js +18 -0
  101. package/lib/ide-protocol.js.map +1 -0
  102. package/lib/index.d.ts +17 -11
  103. package/lib/index.d.ts.map +1 -1
  104. package/lib/index.js +8 -2
  105. package/lib/index.js.map +1 -1
  106. package/lib/installation-admin-protocol.d.ts +30 -0
  107. package/lib/installation-admin-protocol.d.ts.map +1 -0
  108. package/lib/installation-admin-protocol.js +31 -0
  109. package/lib/installation-admin-protocol.js.map +1 -0
  110. package/lib/license-protocol.d.ts +8 -1
  111. package/lib/license-protocol.d.ts.map +1 -1
  112. package/lib/license-protocol.js +1 -1
  113. package/lib/license-protocol.js.map +1 -1
  114. package/lib/messaging/browser/connection.d.ts +4 -6
  115. package/lib/messaging/browser/connection.d.ts.map +1 -1
  116. package/lib/messaging/browser/connection.js +176 -45
  117. package/lib/messaging/browser/connection.js.map +1 -1
  118. package/lib/messaging/browser/window-connection.d.ts +5 -5
  119. package/lib/messaging/browser/window-connection.d.ts.map +1 -1
  120. package/lib/messaging/browser/window-connection.js +43 -60
  121. package/lib/messaging/browser/window-connection.js.map +1 -1
  122. package/lib/messaging/client-call-metrics.d.ts +21 -0
  123. package/lib/messaging/client-call-metrics.d.ts.map +1 -0
  124. package/lib/messaging/client-call-metrics.js +95 -0
  125. package/lib/messaging/client-call-metrics.js.map +1 -0
  126. package/lib/messaging/error.d.ts +13 -3
  127. package/lib/messaging/error.d.ts.map +1 -1
  128. package/lib/messaging/error.js +25 -5
  129. package/lib/messaging/error.js.map +1 -1
  130. package/lib/messaging/handler.d.ts +10 -0
  131. package/lib/messaging/handler.d.ts.map +1 -1
  132. package/lib/messaging/handler.js +1 -1
  133. package/lib/messaging/node/connection.d.ts +1 -17
  134. package/lib/messaging/node/connection.d.ts.map +1 -1
  135. package/lib/messaging/node/connection.js +24 -60
  136. package/lib/messaging/node/connection.js.map +1 -1
  137. package/lib/messaging/proxy-factory.d.ts +3 -1
  138. package/lib/messaging/proxy-factory.d.ts.map +1 -1
  139. package/lib/messaging/proxy-factory.js +75 -162
  140. package/lib/messaging/proxy-factory.js.map +1 -1
  141. package/lib/oss-allowlist.d.ts +14 -0
  142. package/lib/oss-allowlist.d.ts.map +1 -0
  143. package/lib/oss-allowlist.js +8 -0
  144. package/lib/oss-allowlist.js.map +1 -0
  145. package/lib/payment-protocol.d.ts +1 -1
  146. package/lib/payment-protocol.d.ts.map +1 -1
  147. package/lib/payment-protocol.js +2 -2
  148. package/lib/payment-protocol.js.map +1 -1
  149. package/lib/permission.d.ts +14 -4
  150. package/lib/permission.d.ts.map +1 -1
  151. package/lib/permission.js +45 -32
  152. package/lib/permission.js.map +1 -1
  153. package/lib/plans.d.ts +6 -5
  154. package/lib/plans.d.ts.map +1 -1
  155. package/lib/plans.js +230 -210
  156. package/lib/plans.js.map +1 -1
  157. package/lib/protocol.d.ts +261 -105
  158. package/lib/protocol.d.ts.map +1 -1
  159. package/lib/protocol.js +346 -205
  160. package/lib/protocol.js.map +1 -1
  161. package/{src/util/without.ts → lib/protocol.spec.d.ts} +3 -4
  162. package/lib/protocol.spec.d.ts.map +1 -0
  163. package/lib/protocol.spec.js +127 -0
  164. package/lib/protocol.spec.js.map +1 -0
  165. package/lib/snapshot-url.d.ts +14 -0
  166. package/lib/snapshot-url.d.ts.map +1 -0
  167. package/lib/snapshot-url.js +26 -0
  168. package/lib/snapshot-url.js.map +1 -0
  169. package/lib/snapshot-url.spec.d.ts +7 -0
  170. package/lib/snapshot-url.spec.d.ts.map +1 -0
  171. package/lib/snapshot-url.spec.js +41 -0
  172. package/lib/snapshot-url.spec.js.map +1 -0
  173. package/lib/team-subscription-protocol.d.ts +24 -5
  174. package/lib/team-subscription-protocol.d.ts.map +1 -1
  175. package/lib/team-subscription-protocol.js +36 -18
  176. package/lib/team-subscription-protocol.js.map +1 -1
  177. package/lib/teams-projects-protocol.d.ts +137 -0
  178. package/lib/teams-projects-protocol.d.ts.map +1 -0
  179. package/lib/teams-projects-protocol.js +41 -0
  180. package/lib/teams-projects-protocol.js.map +1 -0
  181. package/lib/typings/globals.d.ts +3 -3
  182. package/lib/typings/globals.d.ts.map +1 -1
  183. package/lib/typings/globals.js +1 -1
  184. package/lib/usage.d.ts +73 -0
  185. package/lib/usage.d.ts.map +1 -0
  186. package/lib/usage.js +20 -0
  187. package/lib/usage.js.map +1 -0
  188. package/lib/util/analytics.d.ts +8 -0
  189. package/lib/util/analytics.d.ts.map +1 -0
  190. package/lib/util/analytics.js +88 -0
  191. package/lib/util/analytics.js.map +1 -0
  192. package/lib/util/async-iterator.d.ts +1 -1
  193. package/lib/util/async-iterator.d.ts.map +1 -1
  194. package/lib/util/async-iterator.js +58 -136
  195. package/lib/util/async-iterator.js.map +1 -1
  196. package/lib/util/cancelable.d.ts +1 -1
  197. package/lib/util/cancelable.js +18 -60
  198. package/lib/util/cancelable.js.map +1 -1
  199. package/lib/util/date-time.d.ts +1 -1
  200. package/lib/util/date-time.js +12 -12
  201. package/lib/util/date-time.js.map +1 -1
  202. package/lib/util/debug-app.d.ts +25 -0
  203. package/lib/util/debug-app.d.ts.map +1 -0
  204. package/lib/util/debug-app.js +100 -0
  205. package/lib/util/debug-app.js.map +1 -0
  206. package/lib/util/deep-partial.d.ts +1 -1
  207. package/lib/util/deep-partial.js +1 -1
  208. package/lib/util/deferred.d.ts +1 -1
  209. package/lib/util/deferred.js +11 -13
  210. package/lib/util/deferred.js.map +1 -1
  211. package/lib/util/disposable.d.ts.map +1 -1
  212. package/lib/util/disposable.js +27 -40
  213. package/lib/util/disposable.js.map +1 -1
  214. package/lib/util/event.d.ts.map +1 -1
  215. package/lib/util/event.js +63 -77
  216. package/lib/util/event.js.map +1 -1
  217. package/lib/util/garbage-collected-cache.d.ts +2 -1
  218. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  219. package/lib/util/garbage-collected-cache.js +33 -48
  220. package/lib/util/garbage-collected-cache.js.map +1 -1
  221. package/lib/util/generate-workspace-id.d.ts +6 -1
  222. package/lib/util/generate-workspace-id.d.ts.map +1 -1
  223. package/lib/util/generate-workspace-id.js +469 -502
  224. package/lib/util/generate-workspace-id.js.map +1 -1
  225. package/lib/util/generate-workspace-id.spec.d.ts +1 -1
  226. package/lib/util/generate-workspace-id.spec.js +69 -79
  227. package/lib/util/generate-workspace-id.spec.js.map +1 -1
  228. package/lib/util/gitpod-cookie.d.ts +20 -0
  229. package/lib/util/gitpod-cookie.d.ts.map +1 -0
  230. package/lib/util/gitpod-cookie.js +41 -0
  231. package/lib/util/gitpod-cookie.js.map +1 -0
  232. package/lib/util/gitpod-host-url.d.ts +12 -7
  233. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  234. package/lib/util/gitpod-host-url.js +132 -110
  235. package/lib/util/gitpod-host-url.js.map +1 -1
  236. package/lib/util/gitpod-host-url.spec.d.ts +7 -1
  237. package/lib/util/gitpod-host-url.spec.d.ts.map +1 -1
  238. package/lib/util/gitpod-host-url.spec.js +113 -31
  239. package/lib/util/gitpod-host-url.spec.js.map +1 -1
  240. package/lib/util/grpc.d.ts +35 -0
  241. package/lib/util/grpc.d.ts.map +1 -0
  242. package/lib/util/grpc.js +90 -0
  243. package/lib/util/grpc.js.map +1 -0
  244. package/lib/util/jaeger-client-types.d.ts +68 -0
  245. package/lib/util/jaeger-client-types.d.ts.map +1 -0
  246. package/lib/{theia-plugins.js → util/jaeger-client-types.js} +2 -2
  247. package/lib/util/jaeger-client-types.js.map +1 -0
  248. package/lib/util/logging.d.ts +50 -34
  249. package/lib/util/logging.d.ts.map +1 -1
  250. package/lib/util/logging.js +133 -130
  251. package/lib/util/logging.js.map +1 -1
  252. package/lib/util/logging.spec.d.ts +7 -0
  253. package/lib/util/logging.spec.d.ts.map +1 -0
  254. package/lib/util/logging.spec.js +52 -0
  255. package/lib/util/logging.spec.js.map +1 -0
  256. package/lib/util/make-link.d.ts +1 -1
  257. package/lib/util/make-link.js +6 -6
  258. package/lib/util/make-link.js.map +1 -1
  259. package/lib/util/nice-grpc.d.ts +9 -0
  260. package/lib/util/nice-grpc.d.ts.map +1 -0
  261. package/lib/util/nice-grpc.js +121 -0
  262. package/lib/util/nice-grpc.js.map +1 -0
  263. package/lib/util/parse-workspace-id.d.ts +11 -1
  264. package/lib/util/parse-workspace-id.d.ts.map +1 -1
  265. package/lib/util/parse-workspace-id.js +31 -8
  266. package/lib/util/parse-workspace-id.js.map +1 -1
  267. package/lib/util/parse-workspace-id.spec.d.ts +5 -1
  268. package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
  269. package/lib/util/parse-workspace-id.spec.js +124 -85
  270. package/lib/util/parse-workspace-id.spec.js.map +1 -1
  271. package/lib/util/queue.d.ts +1 -1
  272. package/lib/util/queue.js +17 -56
  273. package/lib/util/queue.js.map +1 -1
  274. package/lib/util/queue.spec.d.ts +1 -1
  275. package/lib/util/queue.spec.js +148 -289
  276. package/lib/util/queue.spec.js.map +1 -1
  277. package/lib/util/repeat.d.ts +15 -0
  278. package/lib/util/repeat.d.ts.map +1 -0
  279. package/lib/util/repeat.js +55 -0
  280. package/lib/util/repeat.js.map +1 -0
  281. package/lib/util/semaphore.d.ts +1 -1
  282. package/lib/util/semaphore.d.ts.map +1 -1
  283. package/lib/util/semaphore.js +16 -47
  284. package/lib/util/semaphore.js.map +1 -1
  285. package/lib/util/skip-if.d.ts +1 -1
  286. package/lib/util/skip-if.d.ts.map +1 -1
  287. package/lib/util/skip-if.js +7 -7
  288. package/lib/util/skip-if.js.map +1 -1
  289. package/lib/util/timeutil.d.ts +3 -1
  290. package/lib/util/timeutil.d.ts.map +1 -1
  291. package/lib/util/timeutil.js +30 -18
  292. package/lib/util/timeutil.js.map +1 -1
  293. package/lib/util/timeutil.spec.d.ts +3 -1
  294. package/lib/util/timeutil.spec.d.ts.map +1 -1
  295. package/lib/util/timeutil.spec.js +55 -24
  296. package/lib/util/timeutil.spec.js.map +1 -1
  297. package/lib/util/tracing.d.ts +53 -7
  298. package/lib/util/tracing.d.ts.map +1 -1
  299. package/lib/util/tracing.js +198 -65
  300. package/lib/util/tracing.js.map +1 -1
  301. package/lib/util/tracing.spec.d.ts +7 -0
  302. package/lib/util/tracing.spec.d.ts.map +1 -0
  303. package/lib/util/tracing.spec.js +121 -0
  304. package/lib/util/tracing.spec.js.map +1 -0
  305. package/lib/util/workspace-port-authentication.d.ts +8 -8
  306. package/lib/util/workspace-port-authentication.d.ts.map +1 -1
  307. package/lib/util/workspace-port-authentication.js +10 -13
  308. package/lib/util/workspace-port-authentication.js.map +1 -1
  309. package/lib/webhook-event.d.ts +44 -0
  310. package/lib/webhook-event.d.ts.map +1 -0
  311. package/lib/webhook-event.js +8 -0
  312. package/lib/webhook-event.js.map +1 -0
  313. package/lib/workspace-class.d.ts +14 -0
  314. package/lib/workspace-class.d.ts.map +1 -0
  315. package/lib/workspace-class.js +8 -0
  316. package/lib/workspace-class.js.map +1 -0
  317. package/lib/workspace-cluster.d.ts +28 -8
  318. package/lib/workspace-cluster.d.ts.map +1 -1
  319. package/lib/workspace-cluster.js +20 -5
  320. package/lib/workspace-cluster.js.map +1 -1
  321. package/lib/workspace-instance.d.ts +46 -6
  322. package/lib/workspace-instance.d.ts.map +1 -1
  323. package/lib/workspace-instance.js +1 -1
  324. package/lib/wsready.d.ts +8 -2
  325. package/lib/wsready.d.ts.map +1 -1
  326. package/lib/wsready.js +3 -3
  327. package/package.json +40 -18
  328. package/pkg-yarn.lock +23 -10
  329. package/provenance-bundle.jsonl +2 -0
  330. package/src/accounting-protocol.ts +67 -58
  331. package/src/admin-protocol.ts +88 -20
  332. package/src/analytics.ts +52 -0
  333. package/src/attribution.ts +63 -0
  334. package/src/auth.ts +3 -3
  335. package/src/billing-mode.ts +84 -0
  336. package/src/blocked-repositories-protocol.ts +13 -0
  337. package/src/context-url.spec.ts +49 -0
  338. package/src/context-url.ts +107 -0
  339. package/src/encryption/container-module.ts +3 -4
  340. package/src/encryption/encryption-engine.spec.ts +10 -9
  341. package/src/encryption/encryption-engine.ts +21 -17
  342. package/src/encryption/encryption-service.ts +5 -6
  343. package/src/encryption/key-provider.ts +17 -20
  344. package/src/env.ts +2 -25
  345. package/src/experiments/always-default.ts +24 -0
  346. package/src/experiments/configcat-server.ts +42 -0
  347. package/src/experiments/configcat.ts +56 -0
  348. package/src/experiments/types.ts +34 -0
  349. package/src/frontend-dashboard-service.ts +125 -0
  350. package/src/gitpod-file-parser.spec.ts +56 -62
  351. package/src/gitpod-file-parser.ts +17 -18
  352. package/src/gitpod-service.ts +369 -146
  353. package/src/headless-workspace-log.ts +13 -15
  354. package/src/ide-frontend-service.ts +3 -3
  355. package/src/ide-protocol.ts +147 -0
  356. package/src/index.ts +17 -11
  357. package/src/installation-admin-protocol.ts +45 -0
  358. package/src/license-protocol.ts +13 -7
  359. package/src/messaging/browser/connection.ts +187 -28
  360. package/src/messaging/browser/window-connection.ts +40 -30
  361. package/src/messaging/client-call-metrics.ts +94 -0
  362. package/src/messaging/error.ts +36 -8
  363. package/src/messaging/handler.ts +13 -1
  364. package/src/messaging/node/connection.ts +23 -70
  365. package/src/messaging/proxy-factory.ts +35 -34
  366. package/src/oss-allowlist.ts +15 -0
  367. package/src/payment-protocol.ts +3 -3
  368. package/src/permission.ts +47 -34
  369. package/src/plans.ts +250 -199
  370. package/src/protocol.spec.ts +97 -0
  371. package/src/protocol.ts +636 -293
  372. package/src/snapshot-url.spec.ts +27 -0
  373. package/src/snapshot-url.ts +27 -0
  374. package/src/team-subscription-protocol.ts +62 -23
  375. package/src/teams-projects-protocol.ts +181 -0
  376. package/src/typings/globals.ts +6 -5
  377. package/src/usage.ts +85 -0
  378. package/src/util/analytics.ts +109 -0
  379. package/src/util/async-iterator.ts +5 -6
  380. package/src/util/cancelable.ts +4 -4
  381. package/src/util/date-time.ts +9 -9
  382. package/src/util/debug-app.ts +81 -0
  383. package/src/util/deep-partial.ts +1 -1
  384. package/src/util/deferred.ts +7 -7
  385. package/src/util/disposable.ts +3 -6
  386. package/src/util/event.ts +9 -11
  387. package/src/util/garbage-collected-cache.ts +17 -9
  388. package/src/util/generate-workspace-id.spec.ts +38 -11
  389. package/src/util/generate-workspace-id.ts +465 -439
  390. package/src/util/gitpod-cookie.ts +38 -0
  391. package/src/util/gitpod-host-url.spec.ts +59 -8
  392. package/src/util/gitpod-host-url.ts +88 -48
  393. package/src/util/grpc.ts +107 -0
  394. package/src/util/jaeger-client-types.ts +102 -0
  395. package/src/util/logging.spec.ts +23 -0
  396. package/src/util/logging.ts +157 -75
  397. package/src/util/make-link.ts +7 -8
  398. package/src/util/nice-grpc.ts +96 -0
  399. package/src/util/parse-workspace-id.spec.ts +38 -9
  400. package/src/util/parse-workspace-id.ts +33 -8
  401. package/src/util/queue.spec.ts +28 -26
  402. package/src/util/queue.ts +1 -1
  403. package/src/util/repeat.ts +45 -0
  404. package/src/util/semaphore.ts +7 -9
  405. package/src/util/skip-if.ts +11 -8
  406. package/src/util/timeutil.spec.ts +41 -15
  407. package/src/util/timeutil.ts +32 -16
  408. package/src/util/tracing.spec.ts +88 -0
  409. package/src/util/tracing.ts +201 -32
  410. package/src/util/workspace-port-authentication.ts +11 -14
  411. package/src/webhook-event.ts +55 -0
  412. package/src/workspace-class.ts +14 -0
  413. package/src/workspace-cluster.ts +47 -17
  414. package/src/workspace-instance.ts +106 -32
  415. package/src/wsready.ts +11 -4
  416. package/data/builtin-theia-plugins.json +0 -372
  417. package/lib/email-protocol.d.ts +0 -50
  418. package/lib/email-protocol.d.ts.map +0 -1
  419. package/lib/email-protocol.js +0 -28
  420. package/lib/email-protocol.js.map +0 -1
  421. package/lib/messaging/connection-error-handler.d.ts +0 -27
  422. package/lib/messaging/connection-error-handler.d.ts.map +0 -1
  423. package/lib/messaging/connection-error-handler.js +0 -46
  424. package/lib/messaging/connection-error-handler.js.map +0 -1
  425. package/lib/theia-plugins.d.ts +0 -11
  426. package/lib/theia-plugins.d.ts.map +0 -1
  427. package/lib/theia-plugins.js.map +0 -1
  428. package/lib/util/context-url.d.ts +0 -13
  429. package/lib/util/context-url.d.ts.map +0 -1
  430. package/lib/util/context-url.js +0 -26
  431. package/lib/util/context-url.js.map +0 -1
  432. package/lib/util/context-url.spec.d.ts +0 -10
  433. package/lib/util/context-url.spec.d.ts.map +0 -1
  434. package/lib/util/context-url.spec.js +0 -52
  435. package/lib/util/context-url.spec.js.map +0 -1
  436. package/lib/util/repeater.d.ts +0 -22
  437. package/lib/util/repeater.d.ts.map +0 -1
  438. package/lib/util/repeater.js +0 -118
  439. package/lib/util/repeater.js.map +0 -1
  440. package/lib/util/safe-promise.d.ts +0 -11
  441. package/lib/util/safe-promise.d.ts.map +0 -1
  442. package/lib/util/safe-promise.js +0 -34
  443. package/lib/util/safe-promise.js.map +0 -1
  444. package/lib/util/without.d.ts +0 -7
  445. package/lib/util/without.d.ts.map +0 -1
  446. package/lib/util/without.js +0 -8
  447. package/lib/util/without.js.map +0 -1
  448. package/src/email-protocol.ts +0 -67
  449. package/src/messaging/connection-error-handler.ts +0 -62
  450. package/src/theia-plugins.ts +0 -11
  451. package/src/util/context-url.spec.ts +0 -25
  452. package/src/util/context-url.ts +0 -23
  453. package/src/util/jaeger-client.d.ts +0 -105
  454. package/src/util/repeater.ts +0 -49
  455. package/src/util/safe-promise.ts +0 -26
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
- const inspect: (object: any) => string = require('util').inspect; // undefined in frontend
7
+ const inspect: (object: any) => string = require("util").inspect; // undefined in frontend
8
8
 
9
+ let plainLogging: boolean = false; // set to true during development to get non JSON output
9
10
  let jsonLogging: boolean = false;
10
11
  let component: string | undefined;
11
12
  let version: string | undefined;
@@ -15,81 +16,81 @@ export interface LogContext {
15
16
  sessionId?: string;
16
17
  userId?: string;
17
18
  workspaceId?: string;
18
- };
19
+ }
19
20
  export namespace LogContext {
20
- export function from(params : { userId?: string, user?: any, request?: any } ) {
21
+ export function from(params: { userId?: string; user?: any; request?: any }) {
21
22
  return <LogContext>{
22
23
  sessionId: params.request?.requestID,
23
- userId: params.userId || params.user?.id
24
- }
24
+ userId: params.userId || params.user?.id,
25
+ };
25
26
  }
26
27
  }
27
28
 
28
29
  export interface LogPayload {
29
30
  // placeholder to indicate that only dictionary-style objects should be passed as payload
30
- };
31
+ }
31
32
 
32
33
  export namespace log {
33
- export function error(context: LogContext, message: string, error: Error, payload: LogPayload): void;
34
- export function error(context: LogContext, message: string, error: Error): void;
34
+ export function error(context: LogContext, message: string, error: any, payload: LogPayload): void;
35
+ export function error(context: LogContext, message: string, error: any): void;
35
36
  export function error(context: LogContext, message: string, payload: LogPayload): void;
36
37
  export function error(context: LogContext, message: string): void;
37
- export function error(context: LogContext, error: Error, payload: LogPayload): void;
38
- export function error(context: LogContext, error: Error): void;
39
- export function error(message: string, error: Error, payload: LogPayload): void;
40
- export function error(message: string, error: Error): void;
38
+ export function error(context: LogContext, error: any, payload: LogPayload): void;
39
+ export function error(context: LogContext, error: any): void;
40
+ export function error(message: string, error: any, payload: LogPayload): void;
41
+ export function error(message: string, error: any): void;
41
42
  export function error(message: string, payload: LogPayload): void;
42
43
  export function error(message: string): void;
43
- export function error(error: Error, payload: LogPayload): void;
44
- export function error(error: Error): void;
44
+ export function error(error: any, payload: LogPayload): void;
45
+ export function error(error: any): void;
45
46
  export function error(...args: any[]): void {
46
47
  errorLog(false, args);
47
48
  }
48
49
 
49
- export function warn(context: LogContext, message: string, error: Error, payload: LogPayload): void;
50
- export function warn(context: LogContext, message: string, error: Error): void;
50
+ export function warn(context: LogContext, message: string, error: any, payload: LogPayload): void;
51
+ export function warn(context: LogContext, message: string, error: any): void;
51
52
  export function warn(context: LogContext, message: string, payload: LogPayload): void;
52
53
  export function warn(context: LogContext, message: string): void;
53
- export function warn(context: LogContext, error: Error, payload: LogPayload): void;
54
- export function warn(context: LogContext, error: Error): void;
55
- export function warn(message: string, error: Error, payload: LogPayload): void;
56
- export function warn(message: string, error: Error): void;
54
+ export function warn(context: LogContext, error: any, payload: LogPayload): void;
55
+ export function warn(context: LogContext, error: any): void;
56
+ export function warn(message: string, error: any, payload: LogPayload): void;
57
+ export function warn(message: string, error: any): void;
57
58
  export function warn(message: string, payload: LogPayload): void;
58
59
  export function warn(message: string): void;
59
- export function warn(error: Error, payload: LogPayload): void;
60
- export function warn(error: Error): void;
60
+ export function warn(error: any, payload: LogPayload): void;
61
+ export function warn(error: any): void;
61
62
  export function warn(...args: any[]): void {
62
63
  warnLog(false, args);
63
64
  }
64
65
 
65
- export function info(context: LogContext, message: string, error: Error, payload: LogPayload): void;
66
- export function info(context: LogContext, message: string, error: Error): void;
66
+ export function info(context: LogContext, message: string, error: any, payload: LogPayload): void;
67
+ export function info(context: LogContext, message: string, error: any): void;
67
68
  export function info(context: LogContext, message: string, payload: LogPayload): void;
68
69
  export function info(context: LogContext, message: string): void;
69
- export function info(context: LogContext, error: Error, payload: LogPayload): void;
70
- export function info(context: LogContext, error: Error): void;
71
- export function info(message: string, error: Error, payload: LogPayload): void;
72
- export function info(message: string, error: Error): void;
70
+ export function info(context: LogContext, error: any, payload: LogPayload): void;
71
+ export function info(context: LogContext, error: any): void;
72
+ export function info(message: string, error: any, payload: LogPayload): void;
73
+ export function info(message: string, error: any): void;
73
74
  export function info(message: string, payload: LogPayload): void;
74
75
  export function info(message: string): void;
75
- export function info(error: Error, payload: LogPayload): void;
76
- export function info(error: Error): void;
76
+ export function info(error: any, payload: LogPayload): void;
77
+ export function info(error: any): void;
77
78
  export function info(...args: any[]): void {
78
79
  infoLog(false, args);
79
80
  }
80
81
 
81
- export function debug(context: LogContext, message: string, error: Error, payload: LogPayload): void;
82
- export function debug(context: LogContext, message: string, error: Error): void;
82
+ export function debug(context: LogContext, message: string, error: any, payload: LogPayload): void;
83
+ export function debug(context: LogContext, message: string, error: any): void;
83
84
  export function debug(context: LogContext, message: string, payload: LogPayload): void;
84
85
  export function debug(context: LogContext, message: string): void;
85
- export function debug(context: LogContext, error: Error, payload: LogPayload): void;
86
- export function debug(context: LogContext, error: Error): void;
87
- export function debug(message: string, error: Error, payload: LogPayload): void;
88
- export function debug(message: string, error: Error): void;
86
+ export function debug(context: LogContext, error: any, payload: LogPayload): void;
87
+ export function debug(context: LogContext, error: any): void;
88
+ export function debug(message: string, error: any, payload: LogPayload): void;
89
+ export function debug(message: string, error: any): void;
89
90
  export function debug(message: string, payload: LogPayload): void;
90
91
  export function debug(message: string): void;
91
- export function debug(error: Error, payload: LogPayload): void;
92
- export function debug(error: Error): void;
92
+ export function debug(error: any, payload: LogPayload): void;
93
+ export function debug(error: any): void;
93
94
  export function debug(...args: any[]): void {
94
95
  debugLog(false, args);
95
96
  }
@@ -97,26 +98,46 @@ export namespace log {
97
98
  /**
98
99
  * Do not use in frontend.
99
100
  */
100
- export function enableJSONLogging(componentArg: string, versionArg: string | undefined): void {
101
+ export function enableJSONLogging(
102
+ componentArg: string,
103
+ versionArg: string | undefined,
104
+ logLevel?: LogrusLogLevel,
105
+ ): void {
101
106
  component = componentArg;
102
107
  version = versionArg;
103
108
 
109
+ setLogLevel(logLevel);
110
+ }
111
+
112
+ export function setLogLevel(logLevel: LogrusLogLevel | undefined) {
104
113
  jsonLogging = true;
105
114
 
106
115
  console.error = function (...args: any[]): void {
107
116
  errorLog(true, args);
108
- }
117
+ };
109
118
  console.warn = function (...args: any[]): void {
110
119
  warnLog(true, args);
111
- }
120
+ };
112
121
  console.info = function (...args: any[]): void {
113
122
  infoLog(true, args);
114
- }
123
+ };
115
124
  console.debug = function (...args: any[]): void {
116
125
  debugLog(true, args);
117
- }
126
+ };
127
+
118
128
  console.log = console.info;
119
129
  // FIXME wrap also other console methods (e.g. trace())
130
+
131
+ // set/unset log functions based on loglevel so we only have to evaluate once, not every call
132
+ const noop = () => {};
133
+ const setLog = (logFunc: DoLogFunction, funcLevel: LogrusLogLevel): DoLogFunction => {
134
+ return LogrusLogLevel.isGreatherOrEqual(funcLevel, logLevel) ? logFunc : noop;
135
+ };
136
+
137
+ errorLog = setLog(doErrorLog, "error");
138
+ warnLog = setLog(doWarnLog, "warning");
139
+ infoLog = setLog(doInfoLog, "info");
140
+ debugLog = setLog(doDebugLog, "debug");
120
141
  }
121
142
 
122
143
  export function resetToDefaultLogging(): void {
@@ -128,31 +149,79 @@ export namespace log {
128
149
  console.info = infoConsoleLog;
129
150
  console.debug = debugConsoleLog;
130
151
  }
152
+
153
+ export function setVersion(versionArg: string) {
154
+ version = versionArg;
155
+ }
131
156
  }
132
157
 
133
- function errorLog(calledViaConsole: boolean, args: any[]): void {
134
- doLog(calledViaConsole, errorConsoleLog, 'ERROR', args);
158
+ type DoLogFunction = (calledViaConsole: boolean, args: any[]) => void;
159
+
160
+ let errorLog = doErrorLog;
161
+ function doErrorLog(calledViaConsole: boolean, args: any[]): void {
162
+ doLog(calledViaConsole, errorConsoleLog, "ERROR", args);
135
163
  }
136
164
 
137
- function warnLog(calledViaConsole: boolean, args: any[]): void {
138
- doLog(calledViaConsole, warnConsoleLog, 'WARNING', args);
165
+ let warnLog = doWarnLog;
166
+ function doWarnLog(calledViaConsole: boolean, args: any[]): void {
167
+ doLog(calledViaConsole, warnConsoleLog, "WARNING", args);
139
168
  }
140
169
 
141
- function infoLog(calledViaConsole: boolean, args: any[]): void {
142
- doLog(calledViaConsole, infoConsoleLog, 'INFO', args);
170
+ let infoLog = doInfoLog;
171
+ function doInfoLog(calledViaConsole: boolean, args: any[]): void {
172
+ doLog(calledViaConsole, infoConsoleLog, "INFO", args);
143
173
  }
144
174
 
145
- function debugLog(calledViaConsole: boolean, args: any[]): void {
146
- doLog(calledViaConsole, debugConsoleLog, 'DEBUG', args);
175
+ let debugLog = doDebugLog;
176
+ function doDebugLog(calledViaConsole: boolean, args: any[]): void {
177
+ doLog(calledViaConsole, debugConsoleLog, "DEBUG", args);
178
+ }
179
+
180
+ // Ref: https://github.com/sirupsen/logrus#level-logging
181
+ export type LogrusLogLevel = keyof typeof LogrusLogLevels;
182
+ export const LogrusLogLevels = {
183
+ trace: true,
184
+ debug: true,
185
+ info: true,
186
+ warning: true,
187
+ error: true,
188
+ fatal: true,
189
+ panic: true,
190
+ };
191
+ export namespace LogrusLogLevel {
192
+ export function isGreatherOrEqual(lvl: LogrusLogLevel | undefined, ref: LogrusLogLevel | undefined): boolean {
193
+ if (lvl === undefined) {
194
+ return false;
195
+ }
196
+ if (ref === undefined) {
197
+ return true;
198
+ }
199
+ return getLevelArity(lvl) >= getLevelArity(ref);
200
+ }
201
+ function getLevelArity(lvl: LogrusLogLevel): number {
202
+ return Object.keys(LogrusLogLevels).findIndex((l) => l === lvl);
203
+ }
204
+ export function getFromEnv(): LogrusLogLevel | undefined {
205
+ const lvlStr = process.env.LOG_LEVEL;
206
+ if (!lvlStr) {
207
+ return undefined;
208
+ }
209
+ const lvl = lvlStr as LogrusLogLevel;
210
+ const exists = LogrusLogLevels[lvl];
211
+ if (!exists) {
212
+ return undefined;
213
+ }
214
+ return lvl;
215
+ }
147
216
  }
148
217
 
149
218
  // Source: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity
150
- type GoogleLogSeverity = 'EMERGENCY' | 'ALERT' | 'CRITICAL' | 'ERROR' | 'WARNING' | 'INFO' | 'DEBUG';
219
+ type GoogleLogSeverity = "EMERGENCY" | "ALERT" | "CRITICAL" | "ERROR" | "WARNING" | "INFO" | "DEBUG";
151
220
  namespace GoogleLogSeverity {
152
221
  export const isGreaterOrEqualThanWarning = (severity: GoogleLogSeverity) => {
153
222
  switch (severity) {
154
- case 'INFO':
155
- case 'DEBUG':
223
+ case "INFO":
224
+ case "DEBUG":
156
225
  return false;
157
226
  default:
158
227
  return true;
@@ -180,7 +249,7 @@ function doLog(calledViaConsole: boolean, consoleLog: ConsoleLog, severity: Goog
180
249
  // console.xyz(Error, ...any) / log.xyz(Error) / log.xyz(Error, LogPayload)
181
250
  error = args[0];
182
251
  payloadArgs = args.slice(1);
183
- } else if (typeof args[0] === 'string') {
252
+ } else if (typeof args[0] === "string") {
184
253
  message = args[0];
185
254
  if (args.length < 2 || !(args[1] instanceof Error)) {
186
255
  // console.xyz(string) / console.xyz(string, !Error, ...any) / log.xyz(string) / log.xyz(string, LogPayload)
@@ -200,7 +269,7 @@ function doLog(calledViaConsole: boolean, consoleLog: ConsoleLog, severity: Goog
200
269
  // log.xyz(LogContext, Error) / log.xyz(LogContext, Error, LogPayload)
201
270
  error = args[1];
202
271
  payloadArgs = args.slice(2);
203
- } else if (typeof args[1] === 'string') {
272
+ } else if (typeof args[1] === "string") {
204
273
  message = args[1];
205
274
  if (args.length < 3 || !(args[2] instanceof Error)) {
206
275
  // log.xyz(LogContext, string) / log.xyz(LogContext, string, LogPayload)
@@ -223,9 +292,14 @@ function doLog(calledViaConsole: boolean, consoleLog: ConsoleLog, severity: Goog
223
292
  }
224
293
  }
225
294
 
226
- function makeLogItem(severity: GoogleLogSeverity, context: LogContext | undefined, message: string | undefined,
227
- error: Error | undefined, payloadArgs: any[], calledViaConsole: boolean): string | undefined {
228
-
295
+ function makeLogItem(
296
+ severity: GoogleLogSeverity,
297
+ context: LogContext | undefined,
298
+ message: string | undefined,
299
+ error: Error | undefined,
300
+ payloadArgs: any[],
301
+ calledViaConsole: boolean,
302
+ ): string | undefined {
229
303
  if (context !== undefined && Object.keys(context).length == 0) {
230
304
  context = undefined;
231
305
  }
@@ -236,34 +310,40 @@ function makeLogItem(severity: GoogleLogSeverity, context: LogContext | undefine
236
310
  }
237
311
 
238
312
  const payload: any = payloadArgs.length == 0 ? undefined : payloadArgs.length == 1 ? payloadArgs[0] : payloadArgs;
239
- const logItem: any = {
313
+ const logItem = {
240
314
  // undefined fields get eliminated in JSON.stringify()
241
315
  ...reportedErrorEvent,
242
316
  component,
243
317
  severity,
244
318
  time: new Date().toISOString(),
245
- environment: process.env.KUBE_STAGE,
246
- region: process.env.GITPOD_REGION,
247
319
  context,
248
320
  message,
249
321
  error,
250
322
  payload,
251
- loggedViaConsole: calledViaConsole ? true : undefined
323
+ loggedViaConsole: calledViaConsole ? true : undefined,
252
324
  };
325
+ if (plainLogging) {
326
+ return `[${logItem.severity}] [${logItem.component}] ${logItem.message}
327
+ ${JSON.stringify(payload || "", undefined, " ")}
328
+ ${error || ""}
329
+ `.trim();
330
+ }
253
331
  let result: string = stringifyLogItem(logItem);
254
332
 
255
333
  if (result.length > maxAllowedLogItemLength && payload !== undefined) {
256
334
  delete logItem.payload;
257
- logItem.payloadStub = `Payload stripped as log item was longer than ${maxAllowedLogItemLength} characters`;
335
+ (<any>(
336
+ logItem
337
+ )).payloadStub = `Payload stripped as log item was longer than ${maxAllowedLogItemLength} characters`;
258
338
 
259
339
  result = stringifyLogItem(logItem);
260
340
 
261
341
  if (result.length <= maxAllowedLogItemLength) {
262
- log.warn('Log item too large, stripping payload', { logItemStub: makeLogItemStub(logItem) });
342
+ log.warn("Log item too large, stripping payload", { logItemStub: makeLogItemStub(logItem) });
263
343
  }
264
344
  }
265
345
  if (result.length > maxAllowedLogItemLength) {
266
- log.error('Log item too large w/o payload, discarding', { logItemStub: makeLogItemStub(logItem) });
346
+ log.error("Log item too large w/o payload, discarding", { logItemStub: makeLogItemStub(logItem) });
267
347
  return undefined;
268
348
  }
269
349
 
@@ -277,10 +357,10 @@ function makeReportedErrorEvent(error: Error | undefined) {
277
357
  // Serves as marker only
278
358
  "@type": "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent",
279
359
  // This is useful for filtering in the UI
280
- "serviceContext": {
281
- "service": component || "<ts-not-set>",
282
- "version": version || "<ts-not-set>",
283
- }
360
+ serviceContext: {
361
+ service: component || "<ts-not-set>",
362
+ version: version || "<ts-not-set>",
363
+ },
284
364
  };
285
365
 
286
366
  if (error) {
@@ -300,9 +380,9 @@ function makeLogItemStub(logItem: any): any {
300
380
  severity: logItem.severity,
301
381
  time: logItem.time,
302
382
  environment: logItem.environment,
303
- region: logItem.region
383
+ region: logItem.region,
304
384
  };
305
- if (typeof (logItem.message) === 'string') {
385
+ if (typeof logItem.message === "string") {
306
386
  if (logItem.message.length <= maxMessageStubLength) {
307
387
  result.message = logItem.message;
308
388
  } else {
@@ -336,10 +416,12 @@ function stringifyLogItem(logItem: any): string {
336
416
  * Jsonifies Errors properly, not as {} only.
337
417
  */
338
418
  function jsonStringifyWithErrors(value: any): string {
339
- return JSON.stringify(value, (key: string, value: any): any => { return value instanceof Error ? value.stack : value });
419
+ return JSON.stringify(value, (key: string, value: any): any => {
420
+ return value instanceof Error ? value.stack : value;
421
+ });
340
422
  }
341
423
 
342
- type ConsoleLog = (message?: any, ...optionalArgs: any[]) => void; // signature of console.xyz
424
+ type ConsoleLog = (message?: any, ...optionalArgs: any[]) => void; // signature of console.xyz
343
425
  const logConsoleLog: ConsoleLog = console.log;
344
426
  const errorConsoleLog: ConsoleLog = console.error;
345
427
  const warnConsoleLog: ConsoleLog = console.warn;
@@ -1,22 +1,21 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  function isOpenNewTab(event: MouseEvent): boolean {
8
- return event.metaKey || (event.ctrlKey);
8
+ return event.metaKey || event.ctrlKey;
9
9
  }
10
10
 
11
11
  export function makeLink(node: HTMLElement, url: string, hover: string): void {
12
- node.onclick = event => {
13
- let target = '_self';
12
+ node.onclick = (event) => {
13
+ let target = "_self";
14
14
  if (isOpenNewTab(event)) {
15
- target = '_blank';
15
+ target = "_blank";
16
16
  }
17
17
  window.open(url, target);
18
- }
19
- node.style.cursor = 'pointer';
18
+ };
19
+ node.style.cursor = "pointer";
20
20
  node.title = hover;
21
21
  }
22
-
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
+ * Licensed under the GNU Affero General Public License (AGPL).
4
+ * See License.AGPL.txt in the project root for license information.
5
+ */
6
+
7
+ import { isAbortError } from "abort-controller-x";
8
+ import {
9
+ CallOptions,
10
+ ClientError,
11
+ ClientMiddleware,
12
+ ClientMiddlewareCall,
13
+ Status,
14
+ MethodDescriptor,
15
+ } from "nice-grpc-common";
16
+ import { GrpcMethodType, IClientCallMetrics } from "./grpc";
17
+
18
+ function getLabels(method: MethodDescriptor) {
19
+ const callType = method.requestStream
20
+ ? method.responseStream
21
+ ? "bidi_stream"
22
+ : "client_stream"
23
+ : method.responseStream
24
+ ? "server_stream"
25
+ : "unary";
26
+ const { path } = method;
27
+ const [serviceName, methodName] = path.split("/").slice(1);
28
+
29
+ return {
30
+ type: callType as GrpcMethodType,
31
+ service: serviceName,
32
+ method: methodName,
33
+ };
34
+ }
35
+
36
+ async function* incrementStreamMessagesCounter<T>(iterable: AsyncIterable<T>, callback: () => void): AsyncIterable<T> {
37
+ for await (const item of iterable) {
38
+ callback();
39
+ yield item;
40
+ }
41
+ }
42
+
43
+ export function prometheusClientMiddleware(metrics: IClientCallMetrics): ClientMiddleware {
44
+ return async function* prometheusClientMiddlewareGenerator<Request, Response>(
45
+ call: ClientMiddlewareCall<Request, Response>,
46
+ options: CallOptions,
47
+ ): AsyncGenerator<Response, Response | void, undefined> {
48
+ const labels = getLabels(call.method);
49
+
50
+ metrics.started(labels);
51
+
52
+ const stopTimer = metrics.startHandleTimer(labels);
53
+
54
+ let settled = false;
55
+ let status: Status = Status.OK;
56
+
57
+ try {
58
+ let request;
59
+
60
+ if (!call.requestStream) {
61
+ request = call.request;
62
+ } else {
63
+ request = incrementStreamMessagesCounter(call.request, metrics.sent.bind(metrics, labels));
64
+ }
65
+
66
+ if (!call.responseStream) {
67
+ const response = yield* call.next(request, options);
68
+ settled = true;
69
+ return response;
70
+ } else {
71
+ yield* incrementStreamMessagesCounter(
72
+ call.next(request, options),
73
+ metrics.received.bind(metrics, labels),
74
+ );
75
+ settled = true;
76
+ return;
77
+ }
78
+ } catch (err) {
79
+ settled = true;
80
+ if (err instanceof ClientError) {
81
+ status = err.code;
82
+ } else if (isAbortError(err)) {
83
+ status = Status.CANCELLED;
84
+ } else {
85
+ status = Status.UNKNOWN;
86
+ }
87
+ throw err;
88
+ } finally {
89
+ if (!settled) {
90
+ status = Status.CANCELLED;
91
+ }
92
+ stopTimer({ grpc_code: Status[status] });
93
+ metrics.handled({ ...labels, code: Status[status] });
94
+ }
95
+ };
96
+ }
@@ -1,17 +1,20 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
- import * as chai from 'chai';
8
- import { suite, test } from 'mocha-typescript';
9
- import { parseWorkspaceIdFromHostname } from './parse-workspace-id';
7
+ import * as chai from "chai";
8
+ import { suite, test } from "mocha-typescript";
9
+ import {
10
+ matchesInstanceIdOrLegacyWorkspaceIdExactly,
11
+ matchesNewWorkspaceIdExactly,
12
+ parseWorkspaceIdFromHostname,
13
+ } from "./parse-workspace-id";
10
14
  const expect = chai.expect;
11
15
 
12
16
  @suite
13
17
  export class ParseWorkspaceIdTest {
14
-
15
18
  @test public parseWorkspaceIdFromHostname_fromWorkspaceLocation() {
16
19
  const actual = parseWorkspaceIdFromHostname("moccasin-ferret-155799b3.ws-eu01.gitpod.io");
17
20
  expect(actual).to.equal("moccasin-ferret-155799b3");
@@ -28,7 +31,9 @@ export class ParseWorkspaceIdTest {
28
31
  }
29
32
 
30
33
  @test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
31
- const actual = parseWorkspaceIdFromHostname("webview-3000-moccasin-ferret-155799b3.ws-eu01.some.subdomain.somehost.com");
34
+ const actual = parseWorkspaceIdFromHostname(
35
+ "webview-3000-moccasin-ferret-155799b3.ws-eu01.some.subdomain.somehost.com",
36
+ );
32
37
  expect(actual).to.equal("moccasin-ferret-155799b3");
33
38
  }
34
39
 
@@ -44,13 +49,37 @@ export class ParseWorkspaceIdTest {
44
49
  }
45
50
 
46
51
  @test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefix() {
47
- const actual = parseWorkspaceIdFromHostname("webview-3000-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
52
+ const actual = parseWorkspaceIdFromHostname(
53
+ "webview-3000-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io",
54
+ );
48
55
  expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
49
56
  }
50
57
 
51
58
  @test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
52
- const actual = parseWorkspaceIdFromHostname("webview-3000-ca81a50f-09d7-465c-acd9-264a747d5351.ws-eu01.some.subdomain.somehost.com");
59
+ const actual = parseWorkspaceIdFromHostname(
60
+ "webview-3000-ca81a50f-09d7-465c-acd9-264a747d5351.ws-eu01.some.subdomain.somehost.com",
61
+ );
53
62
  expect(actual).to.equal("ca81a50f-09d7-465c-acd9-264a747d5351");
54
63
  }
64
+
65
+ // match - instance ID
66
+ @test public matchesInstanceIdOrLegacyWorkspaceIdExactly_positive() {
67
+ const actual = matchesInstanceIdOrLegacyWorkspaceIdExactly("b7e0eaf8-ec73-44ec-81ea-04859263b656");
68
+ expect(actual).to.be.true;
69
+ }
70
+ @test public matchesInstanceIdOrLegacyWorkspaceIdExactly_negative() {
71
+ const actual = matchesInstanceIdOrLegacyWorkspaceIdExactly("b7e0eaf8-ec73-44ec-81a-04859263b656");
72
+ expect(actual).to.be.false;
73
+ }
74
+
75
+ // match - new workspace ID
76
+ @test public matchesWorkspaceIdExactly_new_positive() {
77
+ const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-155799b3");
78
+ expect(actual).to.be.true;
79
+ }
80
+ @test public matchesWorkspaceIdExactly_new_negative() {
81
+ const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-15599b3");
82
+ expect(actual).to.be.false;
83
+ }
55
84
  }
56
- module.exports = new ParseWorkspaceIdTest()
85
+ module.exports = new ParseWorkspaceIdTest();
@@ -1,9 +1,17 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
+ const REGEX_WORKSPACE_ID = /[0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8,11}/;
8
+ const REGEX_WORKSPACE_ID_EXACT = new RegExp(`^${REGEX_WORKSPACE_ID.source}$`);
9
+ // We need to parse the workspace id precisely here to get the case '<some-str>-<port>-<wsid>.ws.' right
10
+ const REGEX_WORKSPACE_ID_FROM_HOSTNAME = new RegExp(`(${REGEX_WORKSPACE_ID.source})\.ws`);
11
+
12
+ const REGEX_WORKSPACE_ID_LEGACY = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
13
+ const REGEX_WORKSPACE_ID_LEGACY_EXACT = new RegExp(`^${REGEX_WORKSPACE_ID_LEGACY.source}$`);
14
+ const REGEX_WORKSPACE_ID_LEGACY_FROM_HOSTNAME = new RegExp(`(${REGEX_WORKSPACE_ID_LEGACY.source})\.ws`);
7
15
 
8
16
  /**
9
17
  * Hostname may be of the form:
@@ -12,18 +20,35 @@
12
20
  * - webview-1234-moccasin-ferret-155799b3.ws-eu01.gitpod.io (or any other string replacing webview)
13
21
  * @param hostname The hostname the request is headed to
14
22
  */
15
- export const parseWorkspaceIdFromHostname = function(hostname: string) {
16
- // We need to parse the workspace id precisely here to get the case '<some-str>-<port>-<wsid>.ws.' right
17
- const wsIdExpression = /([0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8})\.ws/g;
18
- const match = wsIdExpression.exec(hostname);
23
+ export const parseWorkspaceIdFromHostname = function (hostname: string) {
24
+ const match = REGEX_WORKSPACE_ID_FROM_HOSTNAME.exec(hostname);
19
25
  if (match && match.length >= 2) {
20
26
  return match[1];
21
27
  } else {
22
- const legacyUrlFormat = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.ws/g;
23
- const legacyMatch = legacyUrlFormat.exec(hostname);
28
+ const legacyMatch = REGEX_WORKSPACE_ID_LEGACY_FROM_HOSTNAME.exec(hostname);
24
29
  if (legacyMatch && legacyMatch.length >= 2) {
25
30
  return legacyMatch[1];
26
31
  }
27
32
  return undefined;
28
33
  }
29
- }
34
+ };
35
+
36
+ /** Equalls UUIDv4 (and REGEX_WORKSPACE_ID_LEGACY!) */
37
+ const REGEX_INSTANCE_ID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
38
+ const REGEX_INSTANCE_ID_EXACT = new RegExp(`^${REGEX_INSTANCE_ID.source}$`);
39
+
40
+ /**
41
+ * @param maybeId
42
+ * @returns
43
+ */
44
+ export const matchesInstanceIdOrLegacyWorkspaceIdExactly = function (maybeId: string): boolean {
45
+ return REGEX_INSTANCE_ID_EXACT.test(maybeId) || REGEX_WORKSPACE_ID_LEGACY_EXACT.test(maybeId);
46
+ };
47
+
48
+ /**
49
+ * @param maybeWorkspaceId
50
+ * @returns
51
+ */
52
+ export const matchesNewWorkspaceIdExactly = function (maybeWorkspaceId: string): boolean {
53
+ return REGEX_WORKSPACE_ID_EXACT.test(maybeWorkspaceId);
54
+ };