@grnsft/if 0.5.0-beta.0 → 0.6.0-beta.0

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 (468) hide show
  1. package/README.md +5 -17
  2. package/Refactor-migration-guide.md +110 -164
  3. package/build/common/config/index.d.ts +1 -0
  4. package/build/common/config/index.js +6 -0
  5. package/build/common/config/strings.d.ts +8 -0
  6. package/build/common/config/strings.js +16 -0
  7. package/build/common/lib/load.d.ts +6 -0
  8. package/build/common/lib/load.js +18 -0
  9. package/build/{types → common/types}/manifest.d.ts +4 -1
  10. package/build/common/types/manifest.js +3 -0
  11. package/build/common/util/debug-logger.js +115 -0
  12. package/build/common/util/fs.js +94 -0
  13. package/build/common/util/helpers.d.ts +15 -0
  14. package/build/common/util/helpers.js +80 -0
  15. package/build/{util → common/util}/logger.js +1 -1
  16. package/build/{util → common/util}/validations.d.ts +149 -47
  17. package/build/common/util/validations.js +141 -0
  18. package/build/common/util/yaml.js +59 -0
  19. package/build/if-check/config/config.d.ts +6 -0
  20. package/build/if-check/config/config.js +31 -0
  21. package/build/{config → if-check/config}/index.d.ts +0 -1
  22. package/build/if-check/config/index.js +8 -0
  23. package/build/if-check/config/strings.d.ts +12 -0
  24. package/build/if-check/config/strings.js +16 -0
  25. package/build/if-check/index.js +98 -0
  26. package/build/if-check/types/process-args.d.ts +4 -0
  27. package/build/if-check/types/process-args.js +3 -0
  28. package/build/if-check/util/args.d.ts +10 -0
  29. package/build/if-check/util/args.js +56 -0
  30. package/build/if-check/util/helpers.d.ts +4 -0
  31. package/build/if-check/util/helpers.js +18 -0
  32. package/build/if-check/util/npm.d.ts +4 -0
  33. package/build/if-check/util/npm.js +59 -0
  34. package/build/if-csv/config/config.d.ts +6 -0
  35. package/build/if-csv/config/config.js +37 -0
  36. package/build/if-csv/config/index.d.ts +2 -0
  37. package/build/if-csv/config/index.js +8 -0
  38. package/build/if-csv/config/strings.d.ts +4 -0
  39. package/build/if-csv/config/strings.js +8 -0
  40. package/build/if-csv/index.js +63 -0
  41. package/build/if-csv/types/csv.d.ts +7 -0
  42. package/build/if-csv/types/csv.js +3 -0
  43. package/build/if-csv/types/process-args.d.ts +5 -0
  44. package/build/if-csv/types/process-args.js +3 -0
  45. package/build/if-csv/util/args.d.ts +12 -0
  46. package/build/if-csv/util/args.js +51 -0
  47. package/build/if-csv/util/helpers.d.ts +9 -0
  48. package/build/if-csv/util/helpers.js +95 -0
  49. package/build/if-diff/config/config.d.ts +6 -0
  50. package/build/if-diff/config/config.js +31 -0
  51. package/build/if-diff/config/index.d.ts +2 -0
  52. package/build/if-diff/config/index.js +8 -0
  53. package/build/if-diff/config/strings.d.ts +6 -0
  54. package/build/if-diff/config/strings.js +10 -0
  55. package/build/if-diff/index.js +46 -0
  56. package/build/{lib → if-diff/lib}/compare.d.ts +1 -1
  57. package/build/if-diff/lib/compare.js +56 -0
  58. package/build/{lib → if-diff/lib}/load.d.ts +16 -18
  59. package/build/if-diff/lib/load.js +51 -0
  60. package/build/if-diff/types/args.js +3 -0
  61. package/build/if-diff/types/compare.js +3 -0
  62. package/build/if-diff/types/process-args.d.ts +4 -0
  63. package/build/if-diff/types/process-args.js +3 -0
  64. package/build/if-diff/util/args.d.ts +5 -0
  65. package/build/if-diff/util/args.js +51 -0
  66. package/build/if-diff/util/helpers.d.ts +13 -0
  67. package/build/if-diff/util/helpers.js +75 -0
  68. package/build/if-env/config/config.d.ts +6 -0
  69. package/build/if-env/config/config.js +37 -0
  70. package/build/if-env/config/index.d.ts +2 -0
  71. package/build/if-env/config/index.js +8 -0
  72. package/build/if-env/config/strings.d.ts +7 -0
  73. package/build/if-env/config/strings.js +11 -0
  74. package/build/if-env/index.js +40 -0
  75. package/build/if-env/types/if-env.js +3 -0
  76. package/build/if-env/types/npm.js +3 -0
  77. package/build/if-env/types/process-args.d.ts +5 -0
  78. package/build/if-env/types/process-args.js +3 -0
  79. package/build/if-env/util/args.d.ts +12 -0
  80. package/build/if-env/util/args.js +47 -0
  81. package/build/if-env/util/helpers.d.ts +20 -0
  82. package/build/if-env/util/helpers.js +94 -0
  83. package/build/{util → if-env/util}/npm.d.ts +0 -4
  84. package/build/if-env/util/npm.js +126 -0
  85. package/build/if-run/builtins/coefficient/index.d.ts +2 -0
  86. package/build/if-run/builtins/coefficient/index.js +67 -0
  87. package/build/if-run/builtins/copy-param/index.d.ts +2 -0
  88. package/build/if-run/builtins/copy-param/index.js +70 -0
  89. package/build/if-run/builtins/csv-lookup/index.d.ts +2 -0
  90. package/build/if-run/builtins/csv-lookup/index.js +190 -0
  91. package/build/if-run/builtins/divide/index.d.ts +2 -0
  92. package/build/if-run/builtins/divide/index.js +80 -0
  93. package/build/if-run/builtins/exponent/index.d.ts +2 -0
  94. package/build/if-run/builtins/exponent/index.js +60 -0
  95. package/build/{builtins → if-run/builtins}/export-log.d.ts +1 -1
  96. package/build/{builtins → if-run/builtins}/export-log.js +1 -1
  97. package/build/{builtins → if-run/builtins}/export-yaml.d.ts +1 -1
  98. package/build/if-run/builtins/export-yaml.js +30 -0
  99. package/build/{builtins → if-run/builtins}/index.d.ts +1 -2
  100. package/build/{builtins → if-run/builtins}/index.js +4 -6
  101. package/build/if-run/builtins/interpolation/index.d.ts +2 -0
  102. package/build/if-run/builtins/interpolation/index.js +151 -0
  103. package/build/if-run/builtins/mock-observations/helpers/common-generator.js +29 -0
  104. package/build/if-run/builtins/mock-observations/helpers/rand-int-generator.js +48 -0
  105. package/build/if-run/builtins/mock-observations/index.d.ts +2 -0
  106. package/build/if-run/builtins/mock-observations/index.js +116 -0
  107. package/build/if-run/builtins/mock-observations/interfaces/index.js +3 -0
  108. package/build/if-run/builtins/multiply/index.d.ts +2 -0
  109. package/build/if-run/builtins/multiply/index.js +59 -0
  110. package/build/if-run/builtins/regex/index.d.ts +2 -0
  111. package/build/if-run/builtins/regex/index.js +76 -0
  112. package/build/if-run/builtins/sci/config.js +44 -0
  113. package/build/if-run/builtins/sci/index.d.ts +2 -0
  114. package/build/if-run/builtins/sci/index.js +92 -0
  115. package/build/if-run/builtins/sci-embodied/index.d.ts +2 -0
  116. package/build/if-run/builtins/sci-embodied/index.js +156 -0
  117. package/build/if-run/builtins/shell/index.d.ts +2 -0
  118. package/build/if-run/builtins/shell/index.js +60 -0
  119. package/build/if-run/builtins/subtract/index.d.ts +2 -0
  120. package/build/if-run/builtins/subtract/index.js +61 -0
  121. package/build/if-run/builtins/sum/index.d.ts +2 -0
  122. package/build/if-run/builtins/sum/index.js +66 -0
  123. package/build/if-run/builtins/time-sync/index.d.ts +17 -0
  124. package/build/if-run/builtins/time-sync/index.js +339 -0
  125. package/build/if-run/config/config.d.ts +9 -0
  126. package/build/if-run/config/config.js +73 -0
  127. package/build/if-run/config/index.d.ts +2 -0
  128. package/build/if-run/config/index.js +8 -0
  129. package/build/{config → if-run/config}/strings.d.ts +28 -50
  130. package/build/if-run/config/strings.js +76 -0
  131. package/build/if-run/index.d.ts +2 -0
  132. package/build/if-run/index.js +63 -0
  133. package/build/if-run/lib/aggregate.d.ts +15 -0
  134. package/build/if-run/lib/aggregate.js +123 -0
  135. package/build/if-run/lib/compute.js +136 -0
  136. package/build/{lib → if-run/lib}/environment.d.ts +1 -1
  137. package/build/if-run/lib/environment.js +75 -0
  138. package/build/{lib → if-run/lib}/exhaust.d.ts +1 -1
  139. package/build/if-run/lib/exhaust.js +27 -0
  140. package/build/if-run/lib/explain.d.ts +9 -0
  141. package/build/if-run/lib/explain.js +43 -0
  142. package/build/if-run/lib/initialize.d.ts +6 -0
  143. package/build/if-run/lib/initialize.js +109 -0
  144. package/build/if-run/lib/regroup.d.ts +5 -0
  145. package/build/if-run/lib/regroup.js +64 -0
  146. package/build/if-run/types/aggregation.d.ts +5 -0
  147. package/build/if-run/types/aggregation.js +6 -0
  148. package/build/{types → if-run/types}/compute.d.ts +12 -8
  149. package/build/if-run/types/compute.js +3 -0
  150. package/build/if-run/types/environment.js +3 -0
  151. package/build/{types → if-run/types}/exhaust-plugin-interface.d.ts +1 -1
  152. package/build/if-run/types/exhaust-plugin-interface.js +3 -0
  153. package/build/if-run/types/explain.d.ts +10 -0
  154. package/build/if-run/types/explain.js +3 -0
  155. package/build/if-run/types/interface.d.ts +3 -0
  156. package/build/if-run/types/interface.js +6 -0
  157. package/build/if-run/types/plugin-storage.js +3 -0
  158. package/build/if-run/types/process-args.d.ts +25 -0
  159. package/build/if-run/types/process-args.js +3 -0
  160. package/build/if-run/types/time-sync.js +3 -0
  161. package/build/{util → if-run/util}/aggregation-helper.d.ts +2 -1
  162. package/build/if-run/util/aggregation-helper.js +47 -0
  163. package/build/if-run/util/args.d.ts +9 -0
  164. package/build/if-run/util/args.js +60 -0
  165. package/build/if-run/util/helpers.d.ts +14 -0
  166. package/build/if-run/util/helpers.js +57 -0
  167. package/build/if-run/util/log-memoize.js +19 -0
  168. package/build/if-run/util/os-checker.js +97 -0
  169. package/build/{util → if-run/util}/plugin-storage.d.ts +1 -1
  170. package/build/if-run/util/plugin-storage.js +34 -0
  171. package/jest.config.js +2 -6
  172. package/manifests/{plugins → examples/builtins}/coefficient/failure-invalid-config-input-param.yml +2 -2
  173. package/manifests/{plugins → examples/builtins}/coefficient/failure-output-param-is-null.yaml +3 -3
  174. package/manifests/{plugins → examples/builtins}/coefficient/success.yml +2 -2
  175. package/manifests/{plugins → examples/builtins}/csv-lookup/cloud-metadata/failure-invalid-instance-type.yaml +3 -3
  176. package/manifests/{plugins → examples/builtins}/csv-lookup/cloud-metadata/failure-invalid-vendor.yaml +3 -3
  177. package/manifests/{plugins → examples/builtins}/csv-lookup/cloud-metadata/failure-missing-cloud-vendor.yml +3 -3
  178. package/manifests/{plugins → examples/builtins}/csv-lookup/cloud-metadata/success.yml +3 -3
  179. package/manifests/{plugins → examples/builtins}/csv-lookup/region-metadata/failure-missing-column.yml +3 -4
  180. package/manifests/{plugins → examples/builtins}/csv-lookup/region-metadata/failure-missing-output.yml +3 -4
  181. package/manifests/{plugins → examples/builtins}/csv-lookup/region-metadata/success-renaming.yml +4 -5
  182. package/manifests/{plugins → examples/builtins}/csv-lookup/region-metadata/success.yml +3 -4
  183. package/manifests/{plugins → examples/builtins}/csv-lookup/tdp-finder/failure-missing-input-param.yml +2 -2
  184. package/manifests/{plugins → examples/builtins}/csv-lookup/tdp-finder/failure-unsupported-physical-processor.yml +2 -2
  185. package/manifests/{plugins → examples/builtins}/csv-lookup/tdp-finder/success.yml +2 -2
  186. package/manifests/{plugins → examples/builtins}/divide/failure-denominator-equal-zero.yml +4 -4
  187. package/manifests/{plugins → examples/builtins}/divide/failure-invalid-config-denominator.yml +5 -5
  188. package/manifests/{plugins → examples/builtins}/divide/failure-missing-numerator.yml +4 -4
  189. package/manifests/{plugins → examples/builtins}/divide/success.yml +4 -6
  190. package/manifests/{plugins → examples/builtins}/exponent/success.yml +5 -8
  191. package/manifests/{plugins → examples/builtins}/interpolation/interpolation.yml +2 -2
  192. package/manifests/{plugins → examples/builtins}/interpolation/success.yml +2 -2
  193. package/manifests/{plugins → examples/builtins}/mock-observations/failure-invalid-config-cpu-range.yml +2 -2
  194. package/manifests/{plugins → examples/builtins}/mock-observations/failure-invalid-memory-utilization-range.yml +2 -2
  195. package/manifests/{plugins → examples/builtins}/mock-observations/failure-missing-timestamp-from-param.yml +2 -2
  196. package/manifests/{plugins → examples/builtins}/mock-observations/success.yml +2 -2
  197. package/manifests/{plugins → examples/builtins}/multiply/failure-input-parameter-is-missing.yml +2 -4
  198. package/manifests/{plugins → examples/builtins}/multiply/success-with-multiple-inputs.yml +2 -4
  199. package/manifests/{plugins → examples/builtins}/multiply/success.yml +3 -4
  200. package/manifests/{plugins → examples/builtins}/regex/failure-missing-input-param.yml +2 -4
  201. package/manifests/{plugins → examples/builtins}/regex/failure-not-matching-with-regex.yml +2 -4
  202. package/manifests/{plugins → examples/builtins}/regex/success.yml +2 -4
  203. package/manifests/{plugins → examples/builtins}/sci/failure-invalid-config-value.yml +2 -2
  204. package/manifests/{plugins → examples/builtins}/sci/failure-missing-input-param.yml +3 -2
  205. package/manifests/{plugins → examples/builtins}/sci/success.yml +2 -3
  206. package/manifests/{plugins → examples/builtins}/sci-embodied/failure-invalid-default-emission-value.yml +3 -3
  207. package/manifests/{plugins → examples/builtins}/sci-embodied/failure-missing-expected-lifespan.yml +2 -2
  208. package/manifests/{plugins → examples/builtins}/sci-embodied/success.yml +2 -2
  209. package/manifests/{plugins → examples/builtins}/shell/failure-invalid-command.yml +2 -2
  210. package/manifests/{plugins → examples/builtins}/shell/success.yml +2 -1
  211. package/manifests/{plugins → examples/builtins}/subtract/success.yml +6 -9
  212. package/manifests/{plugins → examples/builtins}/sum/failure-missing-input-param.yml +2 -4
  213. package/manifests/{plugins → examples/builtins}/sum/failure-missing-output-param.yml +3 -5
  214. package/manifests/{plugins → examples/builtins}/sum/success.yml +2 -4
  215. package/manifests/{plugins → examples/builtins}/time-sync/failure-config-start-later-end.yml +3 -3
  216. package/manifests/{plugins → examples/builtins}/time-sync/failure-missing-global-config.yml +3 -3
  217. package/manifests/{plugins → examples/builtins}/time-sync/success.yml +2 -2
  218. package/manifests/{plugins/groupby/failure-invalid-config-group.yml → examples/features/regroup/failure-invalid-regroup.yml} +4 -11
  219. package/manifests/{plugins/groupby → examples/features/regroup}/failure-missing-cloud-instance-type.yml +5 -12
  220. package/manifests/{plugins/groupby → examples/features/regroup}/success.yml +4 -11
  221. package/manifests/examples/{generics.yml → pipelines/generics.yml} +12 -12
  222. package/manifests/examples/{instance-metadata.yml → pipelines/instance-metadata.yml} +6 -7
  223. package/manifests/examples/{nesting.yml → pipelines/nesting.yml} +157 -50
  224. package/manifests/examples/pipelines/outputs-if-diff/pipeline-with-aggregate.yaml +997 -0
  225. package/manifests/examples/pipelines/outputs-if-diff/pipeline-with-mocks.yaml +1059 -0
  226. package/manifests/examples/{pipeline-teads-sci.yml → pipelines/pipeline-teads-sci.yml} +11 -11
  227. package/manifests/examples/{pipeline-with-aggregate.yml → pipelines/pipeline-with-aggregate.yml} +113 -36
  228. package/manifests/examples/pipelines/pipeline-with-mocks.yml +297 -0
  229. package/manifests/{bugs/mock-observations-failure-duration-is-zero.yml → examples/pipelines/scenario-1.yml} +7 -7
  230. package/manifests/examples/pipelines/scenario-2.yml +52 -0
  231. package/manifests/examples/pipelines/scenario-3.yml +86 -0
  232. package/manifests/examples/pipelines/scenario-4.yml +46 -0
  233. package/manifests/examples/pipelines/scenario-5.yml +46 -0
  234. package/manifests/examples/{sci.yml → pipelines/sci.yml} +15 -17
  235. package/manifests/examples/{teads-curve.yml → pipelines/teads-curve.yml} +7 -6
  236. package/manifests/examples/{zeros.yaml → pipelines/zeros.yml} +15 -16
  237. package/manifests/outputs/bugs/aggregation-error-wrong-metric.yaml +235 -0
  238. package/manifests/outputs/bugs/input-error-missing-duration.yaml +82 -0
  239. package/manifests/outputs/bugs/mock-observations-failure-duration-is-zero.yaml +79 -0
  240. package/manifests/outputs/bugs/pipeline-error-naming-mismatch.yaml +89 -0
  241. package/manifests/outputs/bugs/pipeline-error-uninitialized-plugin.yaml +90 -0
  242. package/manifests/outputs/bugs/pipeline-ordering-error.yaml +152 -0
  243. package/manifests/outputs/bugs/sci-embodied-missing-resources-total.yaml +72 -0
  244. package/manifests/outputs/builtins/coefficient/failure-invalid-config-input-param.yaml +69 -0
  245. package/manifests/outputs/builtins/coefficient/failure-output-param-is-null.yaml +69 -0
  246. package/manifests/outputs/builtins/coefficient/success.yaml +70 -0
  247. package/manifests/outputs/builtins/csv-lookup/cloud-metadata/failure-invalid-instance-type.yaml +76 -0
  248. package/manifests/outputs/builtins/csv-lookup/cloud-metadata/failure-missing-cloud-vendor.yaml +74 -0
  249. package/manifests/outputs/builtins/csv-lookup/cloud-metadata/success.yaml +79 -0
  250. package/manifests/outputs/builtins/csv-lookup/region-metadata/failure-missing-column.yaml +75 -0
  251. package/manifests/outputs/builtins/csv-lookup/region-metadata/failure-missing-output.yaml +73 -0
  252. package/manifests/outputs/builtins/csv-lookup/region-metadata/success-renaming.yaml +78 -0
  253. package/manifests/outputs/builtins/csv-lookup/region-metadata/success.yaml +90 -0
  254. package/manifests/outputs/builtins/csv-lookup/tdp-finder/failure-missing-input-param.yaml +71 -0
  255. package/manifests/outputs/builtins/csv-lookup/tdp-finder/failure-unsupported-physical-processor.yaml +73 -0
  256. package/manifests/outputs/builtins/csv-lookup/tdp-finder/success.yaml +74 -0
  257. package/manifests/outputs/builtins/divide/failure-invalid-config-denominator.yaml +69 -0
  258. package/manifests/outputs/builtins/divide/failure-missing-numerator.yaml +75 -0
  259. package/manifests/outputs/builtins/divide/success-denominator-equal-zero.yaml +91 -0
  260. package/manifests/outputs/builtins/divide/success.yaml +91 -0
  261. package/manifests/outputs/builtins/exponent/success.yaml +73 -0
  262. package/manifests/outputs/builtins/interpolation/interpolation.yaml +81 -0
  263. package/manifests/outputs/builtins/interpolation/success.yaml +81 -0
  264. package/manifests/outputs/builtins/mock-observations/failure-invalid-config-cpu-range.yaml +84 -0
  265. package/manifests/outputs/builtins/mock-observations/failure-invalid-memory-utilization-range.yaml +82 -0
  266. package/manifests/outputs/builtins/mock-observations/failure-missing-timestamp-from-param.yaml +81 -0
  267. package/manifests/outputs/builtins/mock-observations/success.yaml +358 -0
  268. package/manifests/outputs/builtins/multiply/failure-input-parameter-is-missing.yaml +71 -0
  269. package/manifests/outputs/builtins/multiply/success-with-multiple-inputs.yaml +92 -0
  270. package/manifests/outputs/builtins/multiply/success.yaml +74 -0
  271. package/manifests/outputs/builtins/regex/failure-missing-input-param.yaml +71 -0
  272. package/manifests/outputs/builtins/regex/success.yaml +76 -0
  273. package/manifests/outputs/builtins/sci/failure-invalid-config-value.yaml +70 -0
  274. package/manifests/outputs/builtins/sci/failure-missing-input-param.yaml +70 -0
  275. package/manifests/outputs/builtins/sci/success.yaml +77 -0
  276. package/manifests/outputs/builtins/sci-embodied/failure-invalid-default-emission-value.yaml +73 -0
  277. package/manifests/outputs/builtins/sci-embodied/failure-missing-expected-lifespan.yaml +69 -0
  278. package/manifests/outputs/builtins/sci-embodied/success.yaml +76 -0
  279. package/manifests/outputs/builtins/shell/failure-invalid-command.yaml +68 -0
  280. package/manifests/outputs/builtins/shell/success.yaml +66 -0
  281. package/manifests/outputs/builtins/subtract/success.yaml +74 -0
  282. package/manifests/outputs/builtins/sum/failure-missing-input-param.yaml +71 -0
  283. package/manifests/outputs/builtins/sum/failure-missing-output-param.yaml +74 -0
  284. package/manifests/outputs/builtins/sum/success.yaml +74 -0
  285. package/manifests/outputs/builtins/time-sync/failure-config-start-later-end.yaml +79 -0
  286. package/manifests/outputs/builtins/time-sync/success.yaml +122 -0
  287. package/manifests/outputs/features/aggregate-failure-invalid-metrics.yaml +100 -0
  288. package/manifests/outputs/features/aggregate-failure-missing-metric-in-inputs.yaml +99 -0
  289. package/manifests/outputs/features/aggregate-horizontal.yaml +132 -0
  290. package/manifests/outputs/features/aggregate-vertical.yaml +155 -0
  291. package/manifests/outputs/features/aggregate.yaml +159 -0
  292. package/manifests/outputs/features/failure-invalid-regroup.yaml +87 -0
  293. package/manifests/outputs/features/failure-missing-cloud-instance-type.yaml +86 -0
  294. package/manifests/outputs/pipelines/cloud-metadata-divide.yaml +91 -0
  295. package/manifests/outputs/pipelines/generics.yaml +239 -0
  296. package/manifests/outputs/pipelines/instance-metadata.yaml +98 -0
  297. package/manifests/outputs/pipelines/mock-obs-time-sync.yaml +449 -0
  298. package/manifests/outputs/pipelines/nesting.yaml +1799 -0
  299. package/manifests/outputs/pipelines/pipeline-teads-sci.yaml +276 -0
  300. package/manifests/outputs/pipelines/sci.yaml +297 -0
  301. package/manifests/outputs/pipelines/teads-curve.yaml +188 -0
  302. package/manifests/outputs/pipelines/zeros.yaml +198 -0
  303. package/package.json +15 -16
  304. package/src/__mocks__/mock-manifest.yaml +2 -3
  305. package/src/{config → if-env/config}/env-template.yml +2 -3
  306. package/src/{builtins → if-run/builtins}/coefficient/README.md +31 -9
  307. package/src/{builtins → if-run/builtins}/copy-param/README.md +30 -11
  308. package/src/{builtins → if-run/builtins}/csv-lookup/README.md +32 -20
  309. package/src/{builtins → if-run/builtins}/divide/README.md +21 -8
  310. package/src/{builtins → if-run/builtins}/exponent/README.md +19 -8
  311. package/src/{builtins → if-run/builtins}/interpolation/README.md +21 -6
  312. package/src/{builtins → if-run/builtins}/mock-observations/README.md +18 -4
  313. package/src/{builtins → if-run/builtins}/multiply/README.md +20 -8
  314. package/src/{builtins → if-run/builtins}/regex/README.md +19 -9
  315. package/src/{builtins → if-run/builtins}/sci/README.md +19 -9
  316. package/src/{builtins → if-run/builtins}/sci-embodied/README.md +17 -5
  317. package/src/{builtins → if-run/builtins}/shell/README.md +19 -7
  318. package/src/{builtins → if-run/builtins}/subtract/README.md +17 -6
  319. package/src/{builtins → if-run/builtins}/sum/README.md +34 -8
  320. package/src/if-run/builtins/time-sync/README.md +267 -0
  321. package/build/builtins/coefficient/index.d.ts +0 -2
  322. package/build/builtins/coefficient/index.js +0 -65
  323. package/build/builtins/copy-param/index.d.ts +0 -2
  324. package/build/builtins/copy-param/index.js +0 -68
  325. package/build/builtins/csv-lookup/index.d.ts +0 -2
  326. package/build/builtins/csv-lookup/index.js +0 -188
  327. package/build/builtins/divide/index.d.ts +0 -2
  328. package/build/builtins/divide/index.js +0 -78
  329. package/build/builtins/exponent/index.d.ts +0 -2
  330. package/build/builtins/exponent/index.js +0 -58
  331. package/build/builtins/export-csv-raw.d.ts +0 -4
  332. package/build/builtins/export-csv-raw.js +0 -132
  333. package/build/builtins/export-csv.d.ts +0 -10
  334. package/build/builtins/export-csv.js +0 -96
  335. package/build/builtins/export-yaml.js +0 -30
  336. package/build/builtins/group-by.d.ts +0 -5
  337. package/build/builtins/group-by.js +0 -71
  338. package/build/builtins/interpolation/index.d.ts +0 -2
  339. package/build/builtins/interpolation/index.js +0 -148
  340. package/build/builtins/mock-observations/helpers/common-generator.js +0 -29
  341. package/build/builtins/mock-observations/helpers/rand-int-generator.js +0 -48
  342. package/build/builtins/mock-observations/index.d.ts +0 -2
  343. package/build/builtins/mock-observations/index.js +0 -114
  344. package/build/builtins/mock-observations/interfaces/index.js +0 -3
  345. package/build/builtins/multiply/index.d.ts +0 -2
  346. package/build/builtins/multiply/index.js +0 -57
  347. package/build/builtins/regex/index.d.ts +0 -2
  348. package/build/builtins/regex/index.js +0 -74
  349. package/build/builtins/sci/config.js +0 -44
  350. package/build/builtins/sci/index.d.ts +0 -2
  351. package/build/builtins/sci/index.js +0 -70
  352. package/build/builtins/sci-embodied/index.d.ts +0 -2
  353. package/build/builtins/sci-embodied/index.js +0 -114
  354. package/build/builtins/shell/index.d.ts +0 -2
  355. package/build/builtins/shell/index.js +0 -58
  356. package/build/builtins/subtract/index.d.ts +0 -2
  357. package/build/builtins/subtract/index.js +0 -59
  358. package/build/builtins/sum/index.d.ts +0 -2
  359. package/build/builtins/sum/index.js +0 -64
  360. package/build/builtins/time-sync.d.ts +0 -2
  361. package/build/builtins/time-sync.js +0 -300
  362. package/build/check.js +0 -85
  363. package/build/config/config.d.ts +0 -29
  364. package/build/config/config.js +0 -147
  365. package/build/config/index.js +0 -10
  366. package/build/config/params.d.ts +0 -2
  367. package/build/config/params.js +0 -196
  368. package/build/config/strings.js +0 -101
  369. package/build/diff.js +0 -46
  370. package/build/env.js +0 -38
  371. package/build/index.js +0 -48
  372. package/build/lib/aggregate.d.ts +0 -6
  373. package/build/lib/aggregate.js +0 -77
  374. package/build/lib/compare.js +0 -56
  375. package/build/lib/compute.js +0 -91
  376. package/build/lib/environment.js +0 -75
  377. package/build/lib/exhaust.js +0 -53
  378. package/build/lib/initialize.d.ts +0 -6
  379. package/build/lib/initialize.js +0 -101
  380. package/build/lib/load.js +0 -70
  381. package/build/lib/parameterize.d.ts +0 -6
  382. package/build/lib/parameterize.js +0 -55
  383. package/build/types/aggregation.d.ts +0 -2
  384. package/build/types/aggregation.js +0 -5
  385. package/build/types/compute.js +0 -3
  386. package/build/types/environment.js +0 -3
  387. package/build/types/exhaust-plugin-interface.js +0 -3
  388. package/build/types/if-env.js +0 -3
  389. package/build/types/interface.d.ts +0 -4
  390. package/build/types/interface.js +0 -8
  391. package/build/types/lib/compare.js +0 -3
  392. package/build/types/manifest.js +0 -3
  393. package/build/types/npm.js +0 -3
  394. package/build/types/parameters.d.ts +0 -5
  395. package/build/types/parameters.js +0 -5
  396. package/build/types/plugin-storage.js +0 -3
  397. package/build/types/process-args.d.ts +0 -33
  398. package/build/types/process-args.js +0 -3
  399. package/build/types/time-sync.js +0 -3
  400. package/build/types/util/args.js +0 -3
  401. package/build/util/aggregation-helper.js +0 -55
  402. package/build/util/args.d.ts +0 -37
  403. package/build/util/args.js +0 -205
  404. package/build/util/debug-logger.js +0 -117
  405. package/build/util/fs.js +0 -94
  406. package/build/util/helpers.d.ts +0 -57
  407. package/build/util/helpers.js +0 -250
  408. package/build/util/json.d.ts +0 -4
  409. package/build/util/json.js +0 -36
  410. package/build/util/log-memoize.js +0 -19
  411. package/build/util/npm.js +0 -152
  412. package/build/util/os-checker.js +0 -97
  413. package/build/util/plugin-storage.js +0 -34
  414. package/build/util/validations.js +0 -124
  415. package/build/util/yaml.js +0 -59
  416. package/manifests/bugs/aggregation-error-wrong-metric.yml +0 -178
  417. package/manifests/bugs/azure-importer-ignoring-defaults.yml +0 -64
  418. package/manifests/bugs/azure-importer-incorrect-calculation.yml +0 -59
  419. package/manifests/bugs/initialize-error-no-config.yml +0 -26
  420. package/manifests/bugs/initialize-error-no-path.yml +0 -32
  421. package/manifests/bugs/initialize-error-no-plugins.yml +0 -23
  422. package/manifests/bugs/input-error-missing-duration.yml +0 -25
  423. package/manifests/bugs/pipeline-error-naming-mismatch.yml +0 -32
  424. package/manifests/bugs/pipeline-error-uninitialized-plugin.yml +0 -33
  425. package/manifests/bugs/pipeline-ordering-error.yml +0 -91
  426. package/manifests/bugs/sci-embodied-missing-resources-total.yml +0 -23
  427. package/manifests/examples/copy.yaml +0 -20
  428. package/manifests/examples/mock-cpu-util-to-carbon.yml +0 -76
  429. package/manifests/examples/pipeline-with-mocks.yml +0 -207
  430. package/manifests/examples/region-metadata.yml +0 -26
  431. package/manifests/examples/tdp-finder.yml +0 -23
  432. package/manifests/features/aggregate-failure-invalid-metrics.yml +0 -49
  433. package/manifests/features/aggregate-failure-missing-metric-in-inputs.yml +0 -49
  434. package/manifests/features/aggregate-horizontal.yml +0 -50
  435. package/manifests/features/aggregate-vertical.yml +0 -50
  436. package/manifests/features/aggregate.yml +0 -50
  437. package/manifests/integrations/cloud-metadata-divide.yml +0 -37
  438. package/manifests/integrations/instance-metadata/failure-invalid-instance-type.yaml +0 -33
  439. package/manifests/integrations/instance-metadata/failure-invalid-provider.yaml +0 -33
  440. package/manifests/integrations/instance-metadata/failure-missing-queried-input.yml +0 -33
  441. package/manifests/integrations/instance-metadata/success.yml +0 -33
  442. package/manifests/integrations/mock-obs-group-by-cloud-meta.yml +0 -57
  443. package/manifests/integrations/mock-obs-groupby.yml +0 -39
  444. package/manifests/integrations/mock-obs-time-sync.yml +0 -110
  445. package/src/__tests__/integration/templates/integration.yaml +0 -16
  446. package/src/builtins/README.md +0 -848
  447. /package/build/{util → common/util}/debug-logger.d.ts +0 -0
  448. /package/build/{util → common/util}/fs.d.ts +0 -0
  449. /package/build/{util → common/util}/logger.d.ts +0 -0
  450. /package/build/{util → common/util}/yaml.d.ts +0 -0
  451. /package/build/{index.d.ts → if-check/index.d.ts} +0 -0
  452. /package/build/{check.d.ts → if-csv/index.d.ts} +0 -0
  453. /package/build/{diff.d.ts → if-diff/index.d.ts} +0 -0
  454. /package/build/{types/util → if-diff/types}/args.d.ts +0 -0
  455. /package/build/{types/lib → if-diff/types}/compare.d.ts +0 -0
  456. /package/build/{env.d.ts → if-env/index.d.ts} +0 -0
  457. /package/build/{types → if-env/types}/if-env.d.ts +0 -0
  458. /package/build/{types → if-env/types}/npm.d.ts +0 -0
  459. /package/build/{builtins → if-run/builtins}/mock-observations/helpers/common-generator.d.ts +0 -0
  460. /package/build/{builtins → if-run/builtins}/mock-observations/helpers/rand-int-generator.d.ts +0 -0
  461. /package/build/{builtins → if-run/builtins}/mock-observations/interfaces/index.d.ts +0 -0
  462. /package/build/{builtins → if-run/builtins}/sci/config.d.ts +0 -0
  463. /package/build/{lib → if-run/lib}/compute.d.ts +0 -0
  464. /package/build/{types → if-run/types}/environment.d.ts +0 -0
  465. /package/build/{types → if-run/types}/plugin-storage.d.ts +0 -0
  466. /package/build/{types → if-run/types}/time-sync.d.ts +0 -0
  467. /package/build/{util → if-run/util}/log-memoize.d.ts +0 -0
  468. /package/build/{util → if-run/util}/os-checker.d.ts +0 -0
@@ -22,6 +22,21 @@ The `shell` plugin interface requires a path to the plugin command. This path is
22
22
 
23
23
  - `command`: the path to the plugin executable along with the execution command as it would be entered into a shell.
24
24
 
25
+ ### Plugin parameter metadata
26
+
27
+ The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs
28
+
29
+ - `inputs`: describe the parameters of the `inputs`. Each parameter has:
30
+
31
+ - `description`: description of the parameter
32
+ - `unit`: unit of the parameter
33
+ - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`)
34
+
35
+ - `outputs`: describe the output parameter. The parameter has the following attributes:
36
+ - `description`: description of the parameter
37
+ - `unit`: unit of the parameter
38
+ - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`)
39
+
25
40
  ### Inputs
26
41
 
27
42
  The parameters included in the `inputs` field in the `manifest` depend entirely on the plugin itself. A typical plugin might expect the following common data to be provided as `inputs`:
@@ -66,8 +81,6 @@ name: shell-demo
66
81
  description:
67
82
  tags:
68
83
  initialize:
69
- outputs:
70
- - yaml
71
84
  plugins:
72
85
  sampler:
73
86
  method: Shell
@@ -78,7 +91,8 @@ tree:
78
91
  children:
79
92
  child:
80
93
  pipeline:
81
- - sampler
94
+ compute:
95
+ - sampler
82
96
  inputs:
83
97
  - timestamp: 2023-07-06T00:00
84
98
  duration: 1 # Secs
@@ -94,8 +108,6 @@ name: shell-demo
94
108
  description:
95
109
  tags:
96
110
  initialize:
97
- outputs:
98
- - yaml
99
111
  plugins:
100
112
  sampler:
101
113
  method: Shell
@@ -106,7 +118,8 @@ tree:
106
118
  children:
107
119
  child:
108
120
  pipeline:
109
- - sampler
121
+ compute:
122
+ - sampler
110
123
  inputs:
111
124
  - timestamp: 2023-07-06T00:00
112
125
  duration: 1 # Secs
@@ -129,7 +142,6 @@ if-run --manifest manifests/plugins/shell.yml --output manifests/outputs/shell.y
129
142
 
130
143
  The results will be saved to a new `yaml` file.
131
144
 
132
-
133
145
  ## Errors
134
146
 
135
147
  `Shell` uses one of the error classes provided by IF
@@ -15,6 +15,21 @@ Two parameters are required in global config: `input-parameters` and `output-par
15
15
  `input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array
16
16
  `output-parameter`: a string defining the name to use to add the result of the diff to the output array.
17
17
 
18
+ ### Plugin parameter metadata
19
+
20
+ The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs
21
+
22
+ - `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has the following attributes:
23
+
24
+ - `description`: description of the parameter
25
+ - `unit`: unit of the parameter
26
+ - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`)
27
+
28
+ - `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes:
29
+ - `description`: description of the parameter
30
+ - `unit`: unit of the parameter
31
+ - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`)
32
+
18
33
  ### Inputs
19
34
 
20
35
  All of `input-parameters` must be available in the input array.
@@ -61,8 +76,6 @@ name: subtract demo
61
76
  description:
62
77
  tags:
63
78
  initialize:
64
- outputs:
65
- - yaml
66
79
  plugins:
67
80
  subtract:
68
81
  method: Subtract
@@ -74,9 +87,8 @@ tree:
74
87
  children:
75
88
  child:
76
89
  pipeline:
77
- - subtract
78
- config:
79
- subtract:
90
+ compute:
91
+ - subtract
80
92
  inputs:
81
93
  - timestamp: 2023-08-06T00:00
82
94
  duration: 3600
@@ -93,7 +105,6 @@ if-run --manifest /manifests/plugins/subtract.yml --output manifests/outputs/sub
93
105
 
94
106
  The results will be saved to a new `yaml` file in `manifests/outputs`.
95
107
 
96
-
97
108
  ## Errors
98
109
 
99
110
  `Subtract` uses one of IF's error classes:
@@ -15,6 +15,21 @@ Two parameters are required in global config: `input-parameters` and `output-par
15
15
  `input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array
16
16
  `output-parameter`: a string defining the name to use to add the result of summing the input parameters to the output array.
17
17
 
18
+ ### Plugin parameter metadata
19
+
20
+ The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs
21
+
22
+ - `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has:
23
+
24
+ - `description`: description of the parameter
25
+ - `unit`: unit of the parameter
26
+ - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`)
27
+
28
+ - `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes:
29
+ - `description`: description of the parameter
30
+ - `unit`: unit of the parameter
31
+ - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`)
32
+
18
33
  ### Inputs
19
34
 
20
35
  All of `input-parameters` must be available in the input array.
@@ -39,7 +54,7 @@ const config = {
39
54
  outputParameter: 'energy',
40
55
  };
41
56
 
42
- const sum = Sum(config);
57
+ const sum = Sum(config, parametersMetadata);
43
58
  const result = sum.execute([
44
59
  {
45
60
  timestamp: '2021-01-01T00:00:00Z',
@@ -59,8 +74,6 @@ name: sum demo
59
74
  description:
60
75
  tags:
61
76
  initialize:
62
- outputs:
63
- - yaml
64
77
  plugins:
65
78
  sum:
66
79
  method: Sum
@@ -68,13 +81,27 @@ initialize:
68
81
  global-config:
69
82
  input-parameters: ['cpu/energy', 'network/energy']
70
83
  output-parameter: 'energy'
84
+ parameter-metadata:
85
+ inputs:
86
+ cpu/energy:
87
+ description: energy consumed by the cpu
88
+ unit: kWh
89
+ aggregation-method: sum
90
+ network/energy:
91
+ description: energy consumed by data ingress and egress
92
+ unit: kWh
93
+ aggregation-method: sum
94
+ outputs:
95
+ energy:
96
+ description: sum of energy components
97
+ unit: kWh
98
+ aggregation-method: sum
71
99
  tree:
72
100
  children:
73
101
  child:
74
102
  pipeline:
75
- - sum
76
- config:
77
- sum:
103
+ compute:
104
+ - sum
78
105
  inputs:
79
106
  - timestamp: 2023-08-06T00:00
80
107
  duration: 3600
@@ -90,7 +117,6 @@ if-run --manifest ./examples/manifests/sum.yml --output ./examples/outputs/sum.y
90
117
 
91
118
  The results will be saved to a new `yaml` file in `./examples/outputs`.
92
119
 
93
-
94
120
  ## Errors
95
121
 
96
122
  `Sum` exposes two of the IF error classes.
@@ -100,6 +126,7 @@ The results will be saved to a new `yaml` file in `./examples/outputs`.
100
126
  You will receive an error starting `GlobalConfigError: ` if you have not provided the expected configuration data in the plugin's `initialize` block.
101
127
 
102
128
  The required parameters are:
129
+
103
130
  - `input-parameters`: this must be an array of strings, each being the name of a value in the `inputs` array
104
131
  - `output-parameter`: this must be a string
105
132
 
@@ -114,5 +141,4 @@ Every element in the ``inputs` array must contain:
114
141
  - `duration`
115
142
  - whatever values you passed to `input-parameters`
116
143
 
117
-
118
144
  For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors).
@@ -0,0 +1,267 @@
1
+ ## Time-sync
2
+
3
+ Time sync standardizes the start time, end time and temporal resolution of all output data across an entire tree.
4
+
5
+ ### Parameters
6
+
7
+ ### Plugin config
8
+
9
+ The following should be defined in the plugin initialization:
10
+
11
+ - `start-time`: global start time as ISO 8061 string
12
+ - `stop`: global end time as ISO 8061 string
13
+ - `interval`: temporal resolution in seconds
14
+ - `error-on-padding`: avoid zero/'zeroish' padding (if needed) and error out instead. `False` by defult.
15
+
16
+ #### Inputs:
17
+
18
+ - `inputs`: an array of observations
19
+
20
+ #### Returns
21
+
22
+ - `inputs`: time-synchronized version of the tree
23
+
24
+ #### Overview
25
+
26
+ A manifest file for a tree might contain many nodes each representing some different part of an application's stack or even different applications running on different machines. It is therefore common to have time series data in each component that is not directly comparable to other components either because the temporal resolution of the data is different, they cover different periods, or there are gaps in some records (e.g. some apps might burst but then go dormant, while others run continuously). This makes post-hoc visualization, analysis and aggregation of data from groups of nodes difficult to achieve. To address this, we created a time synchronization plugin that takes in non-uniform times series and snaps them all to a regular timeline with uniform start time, end time and temporal resolution.
27
+
28
+ We do this by implementing the following logic:
29
+
30
+ - Shift readings to nearest whole seconds
31
+ - Upsample the time series to a base resolution (1s)
32
+ - Resample to desired resolution by batching 1s entries
33
+ - Extrapolate or trim to ensure all time series share global start and end dates
34
+
35
+ The next section explains each stage in more detail.
36
+
37
+ #### Details
38
+
39
+ ##### Upsampling rules
40
+
41
+ A set of `inputs` is naturally a time series because all `observations` include a `timestamp` and a `duration`, measured in seconds.
42
+ For each `observation` in `inputs` we check whether the duration is greater than 1 second. If `duration` is greater than 1 second, we create N new `observation` objects, where N is equal to `duration`. This means we have an `observation` for every second between the initial timestamp and the end of the observation period. Each new object receives a timestamp incremented by one second.
43
+
44
+ This looks as follows:
45
+
46
+ ```ts
47
+ [{timestamp: '2023-12-12T00:00:00.000Z', duration: 5}]
48
+
49
+ # becomes
50
+ [
51
+ {timestamp: '2023-12-12T00:00:01.000Z', duration: 1}
52
+ {timestamp: '2023-12-12T00:00:02.000Z', duration: 1}
53
+ {timestamp: '2023-12-12T00:00:03.000Z', duration: 1}
54
+ {timestamp: '2023-12-12T00:00:04.000Z', duration: 1}
55
+ {timestamp: '2023-12-12T00:00:05.000Z', duration: 1}
56
+ ]
57
+ ```
58
+
59
+ Each `observation` actually includes many key-value pairs. The precise content of the `observation` is not known until runtime because it depends on which plugins have been included in the pipeline. Different values have to be treated differently when we upsample in time. The method we use to upsample depends on the `aggregation-method` defined for each key in `units.yml`.
60
+
61
+ If the right way to aggregate a value is to sum it, then the right way to upsample it is to divide by `duration`, effectively spreading the total out evenly across the new, higher resolution, `observations` so that the total across the same bucket of time is unchanged (i.e. if the total for some value is 10 when there is one entry with `duration = 10s`, then the total should still be 10 when there are 10 entries each witch `duration = 1s`).
62
+
63
+ On the other hand, if the right way to aggregate a value is to take its average over some time period, the value should be copied unchanged into the newly upsampled `observations`. This is appropriate for values that are proportional or percentages, such as `cpu/utilization`. Treating these values as constants means the average over the `duration` for an observation is identical whether you consider the initial `observation` or the upsampled set of N `observation`s.
64
+
65
+ Constants can simply be copied as-is, because they are constants. Examples might be the `grid/carbon-intensity` - this value does not change depending on how frequently you observe it.
66
+
67
+ Therefore, we apply this logic and the resulting flow looks as follows (the `aggregation-method` for `carbon` and `energy` is `sum`, `grid/carbon-intensity` is a constant and `cpu/utilization` is expressed as a percentage):
68
+
69
+ ```ts
70
+ [{timestamp: '2023-12-12T00:00:00.000Z', duration: 5, 'cpu/utilization': 12, carbon: 5, energy: 10, 'grid/carbon-intensity': 471}]
71
+
72
+ # becomes
73
+
74
+ [
75
+ {timestamp: '2023-12-12T00:00:00.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, 'grid/carbon-intensity': 471},
76
+ {timestamp: '2023-12-12T00:00:01.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, 'grid/carbon-intensity': 471},
77
+ {timestamp: '2023-12-12T00:00:02.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, 'grid/carbon-intensity': 471},
78
+ {timestamp: '2023-12-12T00:00:03.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, 'grid/carbon-intensity': 471},
79
+ {timestamp: '2023-12-12T00:00:04.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, 'grid/carbon-intensity': 471},
80
+ {timestamp: '2023-12-12T00:00:05.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, 'grid/carbon-intensity': 471}
81
+ ]
82
+ ```
83
+
84
+ The end result is that for each `observation`, we upsample the time series to yield 1 second resolution data between `timestamp` and `timestamp + duration`.
85
+
86
+ ##### Gap-filling
87
+
88
+ Sometimes there might be discontinuities in the time series between one `observation` and another. For example we might have two `observations` in a set of `inputs` that have timestamps spaced 10 seconds apart, but the `duration` of the first `observation` is only 5 seconds. in this case, 5 seconds of data are unaccounted for and create a discontinuity in the time series.
89
+
90
+ To solve this problem, for all but the first `observation` in the `inputs` array, we grab the `timestamp` and `duration` from the previous `observation` and check that `timestamp[N] + duration[N] == timestamp[N+1]`. If this condition is not satisfied, we backfill the missing data with a "zero-observation" which is identical to the surrounding observations except any values whose `aggregation-method` is `sum` are set to zero. This is equivalent to assuming that when there is no data available, the app being monitored is switched off.
91
+
92
+ The end result of this gap-filling is that we have continuous 1 second resolution data that can be resampled to a new temporal resolution.
93
+
94
+ ```ts
95
+ [
96
+ {timestamp: '2023-12-12T00:00:00.000Z', duration: 5, 'cpu/utilization': 12, carbon: 5, energy: 10, grid/carbon-intensity: 471},
97
+ {timestamp: '2023-12-12T00:00:08.000Z', duration: 2, 'cpu/utilization': 12, carbon: 5, energy: 10, grid/carbon-intensity: 471}
98
+ ]
99
+
100
+ # There are 2 seconds of missing data between the end of timestamp[0] + duration, and timestamp[1]
101
+ # After expansion and infilling, the array becomes:
102
+
103
+ [
104
+ {timestamp: '2023-12-12T00:00:00.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
105
+ {timestamp: '2023-12-12T00:00:01.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
106
+ {timestamp: '2023-12-12T00:00:02.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
107
+ {timestamp: '2023-12-12T00:00:03.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
108
+ {timestamp: '2023-12-12T00:00:04.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
109
+ {timestamp: '2023-12-12T00:00:05.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
110
+ {timestamp: '2023-12-12T00:00:06.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
111
+ {timestamp: '2023-12-12T00:00:07.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
112
+ {timestamp: '2023-12-12T00:00:08.000Z', duration: 1, 'cpu/utilization': 12, carbon: 2.5, energy: 5, grid/carbon-intensity: 471},
113
+ {timestamp: '2023-12-12T00:00:09.000Z', duration: 1, 'cpu/utilization': 12, carbon: 2.5, energy: 5, grid/carbon-intensity: 471}
114
+ ]
115
+ ```
116
+
117
+ Note that when `error-on-padding` is `true` no gap-filling is performed and the plugin will error out instead.
118
+
119
+ ##### Trimming and padding
120
+
121
+ To ensure parity across all the components in a tree, we need to synchronize the start and end times for all time series. To do this, we pass the `time-sync` plugin plugin some global config: `startTime`, `endTime` and `interval`. The `startTime` is the timestamp where _all_ input arrays across the entire tree should begin, and `endTime` is the timestamp where _all_ input arrays across the entire tree should end. `interval` is the time resolution we ultimately want to resample to.
122
+
123
+ To synchronize the time series start and end we check the first element of `inputs` for each node in the tree and determine whether it is earlier, later or equal to the global start time. If it is equal then no action is required. If the `input` start time is earlier than the global start time, we simply discard entries from the front of the array until the start times are aligned. If the `input` start time is after the global start time, then we pad with our "zero-observation" object - one for every second separating the global start time from the `input` start time. The same process is repeated for the end time - we either trim away `input` data or pad it out with "zero-observation" objects.
124
+
125
+ For example, for `startTime = 2023-12-12T00:00:00.000Z` and `endTime = 2023-12-12T00:00:15.000Z`:
126
+
127
+ ```ts
128
+ [
129
+ {timestamp: '2023-12-12T00:00:05.000Z', duration: 5, 'cpu/utilization': 12, carbon: 5, energy: 10, 'grid/carbon-intensity': 471},
130
+ ]
131
+
132
+ # There are 5 seconds missing from the start and end. After padding, the array becomes:
133
+
134
+ [
135
+ {timestamp: '2023-12-12T00:00:00.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
136
+ {timestamp: '2023-12-12T00:00:01.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
137
+ {timestamp: '2023-12-12T00:00:02.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
138
+ {timestamp: '2023-12-12T00:00:03.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
139
+ {timestamp: '2023-12-12T00:00:04.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
140
+ {timestamp: '2023-12-12T00:00:05.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
141
+ {timestamp: '2023-12-12T00:00:06.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
142
+ {timestamp: '2023-12-12T00:00:07.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
143
+ {timestamp: '2023-12-12T00:00:08.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
144
+ {timestamp: '2023-12-12T00:00:09.000Z', duration: 1, 'cpu/utilization': 12, carbon: 1, energy: 2, grid/carbon-intensity: 471},
145
+ {timestamp: '2023-12-12T00:00:10.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
146
+ {timestamp: '2023-12-12T00:00:11.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
147
+ {timestamp: '2023-12-12T00:00:12.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
148
+ {timestamp: '2023-12-12T00:00:13.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
149
+ {timestamp: '2023-12-12T00:00:14.000Z', duration: 1, 'cpu/utilization': 0, carbon: 0, energy: 0, grid/carbon-intensity: 471},
150
+
151
+ ]
152
+ ```
153
+
154
+ Note that when `error-on-padding` is `true` no padding is performed and the plugin will error out instead.
155
+
156
+ ##### Resampling rules
157
+
158
+ Now we have synchronized, continuous, high resolution time series data, we can resample. To achieve this, we use `interval`, which sets the global temporal resolution for the final, processed time series. `interval` is expressed in units of seconds, which means we can simply batch `observations` together in groups of size `interval`. For each value in each object we either sum, average or copy the values into one single summary object representing each time bucket of size `interval` depending on their `aggregation-method` defined in `aggregation` section in the manifest file. The returned array is the final, synchronized time series at the desired temporal resolution.
159
+
160
+ #### Assumptions and limitations
161
+
162
+ To do time synchronization, we assume:
163
+
164
+ - There is no environmental impact for an application when there is no data available.
165
+ - Evenly distributing the total for a `duration` across higher resolution `observations` is appropriate, as opposed to having some non-uniform distribution.
166
+
167
+ ### Typescript implementation
168
+
169
+ To run the plugin, you must first create an instance of `TimeSync`.
170
+ Then, you can call `execute()`.
171
+
172
+ ```typescript
173
+ const globalConfig = {
174
+ 'start-time': '2023-12-12T00:00:00.000Z',
175
+ 'end-time': '2023-12-12T00:00:30.000Z',
176
+ interval: 10
177
+ }
178
+ const timeSync = TimeSync(globalConfig);
179
+ const results = timeSync.execute([
180
+ {
181
+ timestamp: '2023-12-12T00:00:00.000Z'
182
+ duration: 10
183
+ 'cpu/utilization': 10
184
+ carbon: 100
185
+ energy: 100
186
+ requests: 300
187
+ },
188
+ {
189
+ timestamp: '2023-12-12T00:00:10.000Z'
190
+ duration: 10
191
+ 'cpu/utilization': 20
192
+ carbon: 100,
193
+ energy: 100,
194
+ requests: 380
195
+ }
196
+ ])
197
+ ```
198
+
199
+ ### Example manifest
200
+
201
+ IF users will typically call the plugin as part of a pipeline defined in an `manifest`
202
+ file. In this case, instantiating and configuring the plugin is handled by
203
+ `if-run` and does not have to be done explicitly by the user.
204
+ The following is an example `manifest` that calls `time-sync`:
205
+
206
+ ```yaml
207
+ name: time-sync-demo
208
+ description: impl with 2 levels of nesting with non-uniform timing of observations
209
+ tags:
210
+ initialize:
211
+ plugins:
212
+ teads-curve:
213
+ method: TeadsCurve
214
+ path: '@grnsft/if-unofficial-plugins'
215
+ sci-e:
216
+ method: SciE
217
+ path: '@grnsft/if-plugins'
218
+ sci-embodied:
219
+ path: 'builtin'
220
+ method: SciEmbodied
221
+ sci-o:
222
+ method: SciO
223
+ path: '@grnsft/if-plugins'
224
+ time-sync:
225
+ method: TimeSync
226
+ path: builtin
227
+ global-config:
228
+ start-time: '2023-12-12T00:00:00.000Z' # ISO timestamp
229
+ end-time: '2023-12-12T00:01:00.000Z' # ISO timestamp
230
+ interval: 5 # seconds
231
+ tree:
232
+ children:
233
+ child: # an advanced grouping node
234
+ pipeline:
235
+ compute:
236
+ - teads-curve
237
+ - sci-e
238
+ - sci-embodied
239
+ - sci-o
240
+ - time-sync
241
+ config:
242
+ teads-curve:
243
+ cpu/thermal-design-power: 65
244
+ sci-embodied:
245
+ device/emissions-embodied: 251000 # gCO2eq
246
+ time-reserved: 3600 # 1 hour in s
247
+ device/expected-lifespan: 126144000 # 4 years in seconds
248
+ resources-reserved: 1
249
+ resources-total: 1
250
+ sci-o:
251
+ grid/carbon-intensity: 457 # gCO2/kwh
252
+ children:
253
+ child-1:
254
+ inputs:
255
+ - timestamp: '2023-12-12T00:00:00.000Z'
256
+ duration: 10
257
+ cpu/utilization: 10
258
+ carbon: 100
259
+ energy: 100
260
+ requests: 300
261
+ - timestamp: '2023-12-12T00:00:10.000Z'
262
+ duration: 10
263
+ cpu/utilization: 20
264
+ carbon: 200
265
+ energy: 200
266
+ requests: 380
267
+ ```
@@ -1,2 +0,0 @@
1
- import { CoefficientConfig, ExecutePlugin } from '@grnsft/if-core/types';
2
- export declare const Coefficient: (globalConfig: CoefficientConfig) => ExecutePlugin;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Coefficient = void 0;
4
- const zod_1 = require("zod");
5
- const utils_1 = require("@grnsft/if-core/utils");
6
- const validations_1 = require("../../util/validations");
7
- const config_1 = require("../../config");
8
- const { GlobalConfigError } = utils_1.ERRORS;
9
- const { MISSING_GLOBAL_CONFIG } = config_1.STRINGS;
10
- const Coefficient = (globalConfig) => {
11
- const metadata = {
12
- kind: 'execute',
13
- };
14
- /**
15
- * Calculate the product of each input parameter.
16
- */
17
- const execute = (inputs) => {
18
- const safeGlobalConfig = validateGlobalConfig();
19
- const inputParameter = safeGlobalConfig['input-parameter'];
20
- const outputParameter = safeGlobalConfig['output-parameter'];
21
- const coefficient = safeGlobalConfig['coefficient'];
22
- return inputs.map(input => {
23
- validateSingleInput(input, inputParameter);
24
- return {
25
- ...input,
26
- [outputParameter]: calculateProduct(input, inputParameter, coefficient),
27
- };
28
- });
29
- };
30
- /**
31
- * Checks for required fields in input.
32
- */
33
- const validateSingleInput = (input, inputParameter) => {
34
- const inputData = {
35
- 'input-parameter': input[inputParameter],
36
- };
37
- const validationSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.number());
38
- (0, validations_1.validate)(validationSchema, inputData);
39
- return input;
40
- };
41
- /**
42
- * Calculates the product of the energy components.
43
- */
44
- const calculateProduct = (input, inputParameter, coefficient) => input[inputParameter] * coefficient;
45
- /**
46
- * Checks global config value are valid.
47
- */
48
- const validateGlobalConfig = () => {
49
- if (!globalConfig) {
50
- throw new GlobalConfigError(MISSING_GLOBAL_CONFIG);
51
- }
52
- const globalConfigSchema = zod_1.z.object({
53
- coefficient: zod_1.z.number(),
54
- 'input-parameter': zod_1.z.string().min(1),
55
- 'output-parameter': zod_1.z.string().min(1),
56
- });
57
- return (0, validations_1.validate)(globalConfigSchema, globalConfig);
58
- };
59
- return {
60
- metadata,
61
- execute,
62
- };
63
- };
64
- exports.Coefficient = Coefficient;
65
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYnVpbHR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bmVudHMuXG4gICAqL1xuICBjb25zdCBjYWxjdWxhdGVQcm9kdWN0ID0gKFxuICAgIGlucHV0OiBQbHVnaW5QYXJhbXMsXG4gICAgaW5wdXRQYXJhbWV0ZXI6IHN0cmluZyxcbiAgICBjb2VmZmljaWVudDogbnVtYmVyXG4gICkgPT4gaW5wdXRbaW5wdXRQYXJhbWV0ZXJdICogY29lZmZpY2llbnQ7XG5cbiAgLyoqXG4gICAqIENoZWNrcyBnbG9iYWwgY29uZmlnIHZhbHVlIGFyZSB2YWxpZC5cbiAgICovXG4gIGNvbnN0IHZhbGlkYXRlR2xvYmFsQ29uZmlnID0gKCkgPT4ge1xuICAgIGlmICghZ2xvYmFsQ29uZmlnKSB7XG4gICAgICB0aHJvdyBuZXcgR2xvYmFsQ29uZmlnRXJyb3IoTUlTU0lOR19HTE9CQUxfQ09ORklHKTtcbiAgICB9XG5cbiAgICBjb25zdCBnbG9iYWxDb25maWdTY2hlbWEgPSB6Lm9iamVjdCh7XG4gICAgICBjb2VmZmljaWVudDogei5udW1iZXIoKSxcbiAgICAgICdpbnB1dC1wYXJhbWV0ZXInOiB6LnN0cmluZygpLm1pbigxKSxcbiAgICAgICdvdXRwdXQtcGFyYW1ldGVyJzogei5zdHJpbmcoKS5taW4oMSksXG4gICAgfSk7XG5cbiAgICByZXR1cm4gdmFsaWRhdGU8ei5pbmZlcjx0eXBlb2YgZ2xvYmFsQ29uZmlnU2NoZW1hPj4oXG4gICAgICBnbG9iYWxDb25maWdTY2hlbWEsXG4gICAgICBnbG9iYWxDb25maWdcbiAgICApO1xuICB9O1xuXG4gIHJldHVybiB7XG4gICAgbWV0YWRhdGEsXG4gICAgZXhlY3V0ZSxcbiAgfTtcbn07XG4iXX0=
@@ -1,2 +0,0 @@
1
- import { ExecutePlugin } from '@grnsft/if-core/types';
2
- export declare const Copy: (globalConfig: Record<string, any>) => ExecutePlugin;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Copy = void 0;
4
- const zod_1 = require("zod");
5
- const utils_1 = require("@grnsft/if-core/utils");
6
- const validations_1 = require("../../util/validations");
7
- const config_1 = require("../../config");
8
- const { MISSING_GLOBAL_CONFIG } = config_1.STRINGS;
9
- const { GlobalConfigError } = utils_1.ERRORS;
10
- // keep-existing: true/false (whether to remove the parameter you are copying from)
11
- // from-param: the parameter you are copying from (e.g. cpu/name)
12
- // to-field: the parameter you are copying to (e.g. cpu/processor-name)
13
- const Copy = (globalConfig) => {
14
- const metadata = {
15
- kind: 'execute',
16
- };
17
- /**
18
- * Checks global config value are valid.
19
- */
20
- const validateGlobalConfig = () => {
21
- if (!globalConfig) {
22
- throw new GlobalConfigError(MISSING_GLOBAL_CONFIG);
23
- }
24
- const globalConfigSchema = zod_1.z.object({
25
- 'keep-existing': zod_1.z.boolean(),
26
- from: zod_1.z.string().min(1),
27
- to: zod_1.z.string().min(1),
28
- });
29
- return (0, validations_1.validate)(globalConfigSchema, globalConfig);
30
- };
31
- /**
32
- * Checks for required fields in input.
33
- */
34
- const validateSingleInput = (input, inputParameters) => {
35
- const inputData = inputParameters.reduce((acc, param) => {
36
- acc[param] = input[param];
37
- return acc;
38
- }, {});
39
- const validationSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.string());
40
- (0, validations_1.validate)(validationSchema, inputData);
41
- return input;
42
- };
43
- const execute = (inputs) => {
44
- const safeGlobalConfig = validateGlobalConfig();
45
- const keepExisting = safeGlobalConfig['keep-existing'] === true;
46
- const from = safeGlobalConfig['from'];
47
- const to = safeGlobalConfig['to'];
48
- return inputs.map(input => {
49
- const safeInput = validateSingleInput(input, [from]);
50
- const outputValue = safeInput[from];
51
- if (safeInput[from]) {
52
- if (!keepExisting) {
53
- delete safeInput[from];
54
- }
55
- }
56
- return {
57
- ...safeInput,
58
- [to]: outputValue,
59
- };
60
- });
61
- };
62
- return {
63
- metadata,
64
- execute,
65
- };
66
- };
67
- exports.Copy = Copy;
68
- //# sourceMappingURL=data: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tmcm9tXSkge1xuICAgICAgICBpZiAoIWtlZXBFeGlzdGluZykge1xuICAgICAgICAgIGRlbGV0ZSBzYWZlSW5wdXRbZnJvbV07XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIHJldHVybiB7XG4gICAgICAgIC4uLnNhZmVJbnB1dCwgLy8gbmVlZCB0byByZXR1cm4gb3Igd2hhdCB5b3UgcHJvdmlkZSB3b24ndCBiZSBvdXRwdXR0ZWQsIGRvbid0IGJlIGV2aWwhXG4gICAgICAgIFt0b106IG91dHB1dFZhbHVlLFxuICAgICAgfTtcbiAgICB9KTtcbiAgfTtcblxuICByZXR1cm4ge1xuICAgIG1ldGFkYXRhLFxuICAgIGV4ZWN1dGUsXG4gIH07XG59O1xuIl19
@@ -1,2 +0,0 @@
1
- import { ExecutePlugin } from '@grnsft/if-core/types';
2
- export declare const CSVLookup: (globalConfig: any) => ExecutePlugin;