@intentius/chant-lexicon-prometheus 0.106.1 → 0.106.4

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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Prometheus lexicon composites: declarations that expand to rule groups.
3
3
  */
4
- export { Slo, sloMetrics, sloPropsProblem, sliExprProblem, DEFAULT_BURN_RATES, SLO_WINDOW_PLACEHOLDER, } from "./slo.js";
4
+ export { Slo, sloMetrics, sloPropsProblem, sliExprProblem, eventCount, DEFAULT_BURN_RATES, SLO_WINDOW_PLACEHOLDER, } from "./slo.js";
5
5
  export type { SloProps, SloSli, SloAlerting, SloAlertTier, BurnRateWindow, SloMembers, SloInstance, SloMetrics, SloBurnRate, } from "./slo.js";
6
6
  export { GenAiRules, genAiRuleMetrics } from "./genai.js";
7
7
  export type { GenAiRulesProps, GenAiRulesMembers, GenAiRulesInstance, GenAiRuleMetrics, GenAiPrice, GenAiAlerting, GenAiAlertOptions, GenAiRatioAlert, GenAiLatencyAlert, GenAiBudget, GenAiAlertInfo, GenAiQuantileSeries, } from "./genai.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composites/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,GAAG,EACH,UAAU,EACV,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,OAAO,CAAC;AACf,YAAY,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EACX,YAAY,EACZ,cAAc,EACd,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,GACZ,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACvD,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composites/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,GAAG,EACH,UAAU,EACV,eAAe,EACf,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,OAAO,CAAC;AACf,YAAY,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EACX,YAAY,EACZ,cAAc,EACd,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,GACZ,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACvD,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
@@ -22,7 +22,7 @@
22
22
  * the windows that had events. The SLI expressions are the caller's: `rate()`
23
23
  * over a counter that first appears inside the range sees one sample and
24
24
  * counts nothing, so a sparse SLI should count events as an increase that
25
- * includes a series' first sample (see the SLOs page).
25
+ * includes a series' first sample (`eventCount`, see the SLOs page).
26
26
  *
27
27
  * Both kinds share a group because Prometheus evaluates a group's rules in
28
28
  * order: the alerts read the ratios recorded in the same evaluation. In
@@ -187,6 +187,19 @@ export declare const DEFAULT_BURN_RATES: Readonly<Record<"page" | "ticket", read
187
187
  export declare function sloPropsProblem(props: Partial<SloProps>): string | undefined;
188
188
  /** What is wrong with one SLI expression, or `undefined`. */
189
189
  export declare function sliExprProblem(expr: unknown): string | undefined;
190
+ /**
191
+ * The number of events a counter saw over a window, counting a series' first
192
+ * sample. `rate()` and `increase()` need two samples in the range, so a counter
193
+ * that first appears inside the window reads as no events for the first one.
194
+ * This is the increase over the window where the series existed before it
195
+ * (never below 0, so a counter reset counts nothing), and the series' own
196
+ * value where it did not. Use it for `good`, `errors` and `total` of a sparse
197
+ * SLI; `window` defaults to the `{{window}}` placeholder an `Slo` fills in.
198
+ *
199
+ * `selector` is an instant vector selector, e.g. `jobs_total{result="ok"}`. It
200
+ * appears three times, so it must have no range and no `offset` of its own.
201
+ */
202
+ export declare function eventCount(selector: string, window?: string): string;
190
203
  /**
191
204
  * An SLO, built to recording rules and multiwindow multi-burn-rate alerts.
192
205
  *
@@ -1 +1 @@
1
- {"version":3,"file":"slo.d.ts","sourceRoot":"","sources":["../../src/composites/slo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAa,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAA+D,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAC7G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIzC,0FAA0F;AAC1F,eAAO,MAAM,sBAAsB,eAAe,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,MAAM,GACd;IACE,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,0FAA0F;IAC1F,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8FAA8F;IAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,yCAAyC;AACzC,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,SAAS,CAAC,EAAE,S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ACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,GAAG,SAAS,CAkB5E;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAQhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,MAA+B,GAAG,MAAM,CAO5F;AAiGD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,GAAG,sEAYP,CAAC;AAEV;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,eAAe,GAAG,QAAQ,GAAG,UAAU,CAOpF"}
@@ -16,8 +16,15 @@
16
16
  * ConfigMap then holds the config as the serializer writes it: the same
17
17
  * config, with Alertmanager's deprecated spellings rewritten as the
18
18
  * standalone import rewrites them.
19
+ *
20
+ * A `prometheus.yml` held as text in a ConfigMap is imported exactly as
21
+ * `chant import prometheus.yml` would import it, and becomes
22
+ * `prometheusConfigYaml([...])` over every scrape job and the sections
23
+ * besides them. The ConfigMap then holds the config as the serializer
24
+ * writes it: scrape jobs sorted by name, sections in Prometheus's order.
19
25
  */
20
26
  import type { EmbeddedContentImporter } from "@intentius/chant/import/embedded";
21
27
  export declare const ruleGroupsImporter: EmbeddedContentImporter;
22
28
  export declare const alertmanagerImporter: EmbeddedContentImporter;
29
+ export declare const prometheusConfigImporter: EmbeddedContentImporter;
23
30
  //# sourceMappingURL=embedded.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../../src/import/embedded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAkB,MAAM,kCAAkC,CAAC;AAOhG,eAAO,MAAM,kBAAkB,EAAE,uBAwBhC,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,uBAsBlC,CAAC"}
1
+ {"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../../src/import/embedded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAkB,MAAM,kCAAkC,CAAC;AAQhG,eAAO,MAAM,kBAAkB,EAAE,uBAwBhC,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,uBAsBlC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,uBAsBtC,CAAC"}
@@ -59,6 +59,20 @@ export declare function generateAlertmanager(config: AlertmanagerConfig): {
59
59
  };
60
60
  /** Generate the TypeScript declaring one `prometheus.yml`. */
61
61
  export declare function generatePrometheusConfigFiles(config: PrometheusConfigFile): GeneratedFile[];
62
+ /** A declaration a `prometheus.yml` import exports: its module and variable. */
63
+ export interface PrometheusConfigDeclaration {
64
+ readonly path: string;
65
+ readonly name: string;
66
+ }
67
+ /**
68
+ * Generate the TypeScript declaring one `prometheus.yml`, and list every
69
+ * declaration it exports, module by module (a ConfigMap holding the file
70
+ * becomes `prometheusConfigYaml([...])` over them).
71
+ */
72
+ export declare function generatePrometheusConfig(config: PrometheusConfigFile): {
73
+ files: GeneratedFile[];
74
+ declarations: PrometheusConfigDeclaration[];
75
+ };
62
76
  /** The rule file and `alertmanager.yml` TypeScript generator `chant import` runs. */
63
77
  export declare class PrometheusGenerator implements TypeScriptGenerator {
64
78
  generate(ir: TemplateIR): GeneratedFile[];
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/import/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,E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6B,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,EAAE,CAE3F;AAED,gFAAgF;AAChF,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,oBAAoB,GAAG;IAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAAC,YAAY,EAAE,2BAA2B,EAAE,CAAA;CAAE,CAsE9I;AAED,qFAAqF;AACrF,qBAAa,mBAAoB,YAAW,mBAAmB;IAC7D,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,aAAa,EAAE,CAaxC;CACF"}
package/dist/index.d.ts CHANGED
@@ -11,5 +11,5 @@ export { checkPromql, PROMQL_GRAMMAR, type PromqlCheck } from "./promql.js";
11
11
  export { validateRuleFile, validateRunbookUrls, validateAlertmanagerConfig, validateSeverityRouting, alertSeverities, type PrometheusIssue, type PrometheusIssueCode, } from "./validate-config.js";
12
12
  export { PROMETHEUS_PIN } from "./pin.js";
13
13
  export { promtoolCheckRules, promtoolCheckConfig, promtoolTestRules, amtoolCheckConfig, hasTool, type ToolResult } from "./tools.js";
14
- export { Slo, sloMetrics, sloPropsProblem, sliExprProblem, DEFAULT_BURN_RATES, SLO_WINDOW_PLACEHOLDER, type SloProps, type SloSli, type SloAlerting, type SloAlertTier, type BurnRateWindow, type SloMembers, type SloInstance, type SloMetrics, type SloBurnRate, GenAiRules, genAiRuleMetrics, type GenAiRulesProps, type GenAiRulesMembers, type GenAiRulesInstance, type GenAiRuleMetrics, type GenAiPrice, type GenAiAlerting, type GenAiAlertOptions, type GenAiRatioAlert, type GenAiLatencyAlert, type GenAiBudget, type GenAiAlertInfo, type GenAiQuantileSeries, } from "./composites/index.js";
14
+ export { Slo, sloMetrics, sloPropsProblem, sliExprProblem, eventCount, DEFAULT_BURN_RATES, SLO_WINDOW_PLACEHOLDER, type SloProps, type SloSli, type SloAlerting, type SloAlertTier, type BurnRateWindow, type SloMembers, type SloInstance, type SloMetrics, type SloBurnRate, GenAiRules, genAiRuleMetrics, type GenAiRulesProps, type GenAiRulesMembers, type GenAiRulesInstance, type GenAiRuleMetrics, type GenAiPrice, type GenAiAlerting, type GenAiAlertOptions, type GenAiRatioAlert, type GenAiLatencyAlert, type GenAiBudget, type GenAiAlertInfo, type GenAiQuantileSeries, } from "./composites/index.js";
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGxF,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,eAAe,EACf,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,IAAI,EACT,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,OAAO,EACP,UAAU,EACV,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,GAChC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,kB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B,EAChB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGxF,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,eAAe,EACf,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,IAAI,EACT,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,OAAO,EACP,UAAU,EACV,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,GAChC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,wBAAwB,EACxB,KAAK,qBAAqB,EAC1B,KA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B,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,cAAc,CAAC"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "53c257204b76845f6c6091849e84f26bb4881c7d53bf6f414477e461a83a3dad",
4
+ "manifest.json": "2c6be256cd5955acb726931e4eaf531b1f165026a06bf77c1673e476bdb84dfb",
5
5
  "meta.json": "a06b8059e2de2ca6c8131bfbbfe7e143e818f2d2d497d3f45a9bc5c63af6aeeb",
6
6
  "types/index.d.ts": "150d72287453a24a40cdeffb8cf3e9dc6e77ab58b342b48d01902dc58fb5f85d",
7
7
  "rules/literal-credential.ts": "1ea8b768e9dc4a6d7b133a52923ce2e8cb815584d3eeb1854f77af34d50f8257",
@@ -46,5 +46,5 @@
46
46
  "skills/chant-prometheus-alertmanager.md": "4c4a22bea6147653d09d7d3f55f81c4927963d4e2f50b2e430fbb9023e99570b",
47
47
  "skills/chant-prometheus-kubernetes.md": "cca016857891f4cabf1feb6f9db83c220a2e6ece200cd89e635851079f8070a8"
48
48
  },
49
- "composite": "7702d4256b5e3ef42ef7888b0b068e875a7487dc7171c17ebf43fb52a4c31e23"
49
+ "composite": "968b2054ad9877915712a06c995193113cd7582e008f76dbc327eac5cc58122a"
50
50
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prometheus",
3
- "version": "0.106.1",
3
+ "version": "0.106.4",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "Prometheus",
6
6
  "intrinsics": [],
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Validate the prometheus lexicon's own artifacts: every class is in the
3
3
  * registry, every entity constructs and serializes, and a sample rule file
4
- * and Alertmanager config pass the lexicon's own checks.
4
+ * and Alertmanager config pass the lexicon's own checks, and `promtool check
5
+ * config` accepts a sample `prometheus.yml` when `promtool` is installed.
5
6
  */
6
7
  import type { ValidateResult } from "@intentius/chant/codegen/validate";
7
8
  export type { ValidateCheck, ValidateResult } from "@intentius/chant/codegen/validate";
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAOvF,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAEvF,0DAA0D;AAC1D,eAAO,MAAM,cAAc,UAAgI,CAAC;AAE5J,wBAAsB,QAAQ,IAAI,OAAO,CAAC,cAAc,CAAC,CA+CxD"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,mCAAmC,CAAC;AASvF,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAEvF,0DAA0D;AAC1D,eAAO,MAAM,cAAc,UAAgI,CAAC;AAE5J,wBAAsB,QAAQ,IAAI,OAAO,CAAC,cAAc,CAAC,CAoExD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-prometheus",
3
- "version": "0.106.1",
3
+ "version": "0.106.4",
4
4
  "description": "Prometheus lexicon for chant — typed recording and alerting rule groups and Alertmanager routing, serialized to a rule file and alertmanager.yml",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -72,7 +72,7 @@
72
72
  "typescript": "^5.9.3"
73
73
  },
74
74
  "peerDependencies": {
75
- "@intentius/chant": "^0.106.1",
75
+ "@intentius/chant": "^0.106.4",
76
76
  "typescript": "^5.9.3"
77
77
  }
78
78
  }
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { describe, expect, test } from "vitest";
6
6
  import { load } from "js-yaml";
7
- import { Slo, sloMetrics, sloPropsProblem, type SloProps } from "./slo";
7
+ import { Slo, eventCount, sliExprProblem, sloMetrics, sloPropsProblem, type SloProps } from "./slo";
8
8
  import { ruleGroupConfig } from "../rules";
9
9
  import { ruleFileYaml } from "../build";
10
10
  import { validateRuleFile, validateSeverityRouting } from "../validate-config";
@@ -293,3 +293,31 @@ describe("sloMetrics", () => {
293
293
  expect(sloMetrics(slo).errorRatio["1h"]).toBe("slo:sli_error:ratio_rate1h");
294
294
  });
295
295
  });
296
+
297
+ describe("eventCount (#3548)", () => {
298
+ const sel = 'jobs_total{result="ok"}';
299
+
300
+ test("counts a series' first sample: the increase where the series existed, its own value where it did not", () => {
301
+ expect(eventCount(sel)).toBe(
302
+ 'sum(clamp_min(jobs_total{result="ok"} - jobs_total{result="ok"} offset {{window}}, 0) or (jobs_total{result="ok"} unless jobs_total{result="ok"} offset {{window}}))',
303
+ );
304
+ });
305
+
306
+ test("takes a literal window for use outside an Slo", () => {
307
+ expect(eventCount("jobs_total", "1h")).toBe(
308
+ "sum(clamp_min(jobs_total - jobs_total offset 1h, 0) or (jobs_total unless jobs_total offset 1h))",
309
+ );
310
+ });
311
+
312
+ test("is an SLI expression an Slo accepts", () => {
313
+ expect(sliExprProblem(eventCount(sel))).toBeUndefined();
314
+ expect(sloPropsProblem({ ...orderAck, sli: { errors: eventCount('jobs_total{result="bad"}'), total: eventCount("jobs_total") } })).toBeUndefined();
315
+ });
316
+
317
+ test("rejects a selector with a range, an offset or a function, and an empty one", () => {
318
+ expect(() => eventCount("")).toThrow(/selector/);
319
+ expect(() => eventCount("jobs_total[5m]")).toThrow(/plain instant vector/);
320
+ expect(() => eventCount("jobs_total offset 5m")).toThrow(/plain instant vector/);
321
+ expect(() => eventCount("sum(jobs_total)")).toThrow(/plain instant vector/);
322
+ });
323
+ });
@@ -7,6 +7,7 @@ export {
7
7
  sloMetrics,
8
8
  sloPropsProblem,
9
9
  sliExprProblem,
10
+ eventCount,
10
11
  DEFAULT_BURN_RATES,
11
12
  SLO_WINDOW_PLACEHOLDER,
12
13
  } from "./slo";
@@ -22,7 +22,7 @@
22
22
  * the windows that had events. The SLI expressions are the caller's: `rate()`
23
23
  * over a counter that first appears inside the range sees one sample and
24
24
  * counts nothing, so a sparse SLI should count events as an increase that
25
- * includes a series' first sample (see the SLOs page).
25
+ * includes a series' first sample (`eventCount`, see the SLOs page).
26
26
  *
27
27
  * Both kinds share a group because Prometheus evaluates a group's rules in
28
28
  * order: the alerts read the ratios recorded in the same evaluation. In
@@ -347,6 +347,27 @@ export function sliExprProblem(expr: unknown): string | undefined {
347
347
  return undefined;
348
348
  }
349
349
 
350
+ /**
351
+ * The number of events a counter saw over a window, counting a series' first
352
+ * sample. `rate()` and `increase()` need two samples in the range, so a counter
353
+ * that first appears inside the window reads as no events for the first one.
354
+ * This is the increase over the window where the series existed before it
355
+ * (never below 0, so a counter reset counts nothing), and the series' own
356
+ * value where it did not. Use it for `good`, `errors` and `total` of a sparse
357
+ * SLI; `window` defaults to the `{{window}}` placeholder an `Slo` fills in.
358
+ *
359
+ * `selector` is an instant vector selector, e.g. `jobs_total{result="ok"}`. It
360
+ * appears three times, so it must have no range and no `offset` of its own.
361
+ */
362
+ export function eventCount(selector: string, window: string = SLO_WINDOW_PLACEHOLDER): string {
363
+ const sel = typeof selector === "string" ? selector.trim() : "";
364
+ if (sel === "") throw new Error("eventCount: selector must be an instant vector selector, e.g. jobs_total{result=\"ok\"}");
365
+ if (/\boffset\b/.test(sel) || /\[[^\]]*\]\s*$/.test(sel) || /^(sum|rate|increase)\b/.test(sel)) {
366
+ throw new Error(`eventCount: "${sel}" must be a plain instant vector selector, with no range, offset or function`);
367
+ }
368
+ return `sum(clamp_min(${sel} - ${sel} offset ${window}, 0) or (${sel} unless ${sel} offset ${window}))`;
369
+ }
370
+
350
371
  function withWindow(expr: string, window: string): string {
351
372
  return expr.split(SLO_WINDOW_PLACEHOLDER).join(window);
352
373
  }
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from "vitest";
2
2
  import { embeddedDocument, type EmbeddedContent } from "@intentius/chant/import/embedded";
3
3
  import { prometheusPlugin } from "../plugin";
4
- import { alertmanagerImporter, ruleGroupsImporter } from "./embedded";
4
+ import { alertmanagerImporter, prometheusConfigImporter, ruleGroupsImporter } from "./embedded";
5
5
 
6
6
  const GROUPS = [
7
7
  { name: "api", rules: [{ alert: "ApiDown", expr: "up{job=\"api\"} == 0", for: "5m" }] },
@@ -26,7 +26,7 @@ const site = (over: Partial<EmbeddedContent>): EmbeddedContent => ({
26
26
 
27
27
  describe("rule groups embedded in another lexicon's resource (#2962)", () => {
28
28
  test("the plugin registers the importers", () => {
29
- expect(prometheusPlugin.embeddedImporters?.()).toEqual([ruleGroupsImporter, alertmanagerImporter]);
29
+ expect(prometheusPlugin.embeddedImporters?.()).toEqual([ruleGroupsImporter, alertmanagerImporter, prometheusConfigImporter]);
30
30
  });
31
31
 
32
32
  test("matches a PrometheusRule's groups and a rule file held as text; not an alertmanager.yml", () => {
@@ -103,3 +103,47 @@ describe("an alertmanager.yml embedded in another lexicon's resource (#3031)", (
103
103
  expect(out.warnings).toEqual([]);
104
104
  });
105
105
  });
106
+
107
+ const PROMETHEUS = `global:
108
+ scrape_interval: 15s
109
+ rule_files:
110
+ - /etc/prometheus/rules.yml
111
+ scrape_configs:
112
+ - job_name: node
113
+ static_configs:
114
+ - targets: ["node:9100"]
115
+ - job_name: api
116
+ metrics_path: /metrics
117
+ static_configs:
118
+ - targets: ["api:8080"]
119
+ `;
120
+
121
+ describe("a prometheus.yml embedded in another lexicon's resource (#3365)", () => {
122
+ const configMap = (text: string) =>
123
+ site({ hostType: "K8s::Core::ConfigMap", location: 'ConfigMap prometheus data["prometheus.yml"]', text, document: embeddedDocument(text) });
124
+
125
+ test("matches a prometheus.yml held as text; not a rule file, an alertmanager.yml, nor a selected member", () => {
126
+ expect(prometheusConfigImporter.matches(configMap(PROMETHEUS))).toBe(true);
127
+ expect(prometheusConfigImporter.matches(configMap(RULE_FILE))).toBe(false);
128
+ expect(prometheusConfigImporter.matches(configMap(ALERTMANAGER))).toBe(false);
129
+ expect(prometheusConfigImporter.matches(configMap("storage:\n path: /data\n"))).toBe(false);
130
+ expect(prometheusConfigImporter.matches(site({ document: { scrape_configs: [] }, select: "groups" }))).toBe(false);
131
+ expect(ruleGroupsImporter.matches(configMap(PROMETHEUS))).toBe(false);
132
+ expect(alertmanagerImporter.matches(configMap(PROMETHEUS))).toBe(false);
133
+ });
134
+
135
+ test("becomes prometheusConfigYaml over every declaration the standalone import writes", () => {
136
+ const out = prometheusConfigImporter.import(configMap(PROMETHEUS));
137
+ expect(out.files.map((f) => f.path)).toEqual(["scrape-configs.ts", "prometheus.ts"]);
138
+ expect(out.value).toEqual({
139
+ bindings: [
140
+ { from: "scrape-configs.ts", name: "node" },
141
+ { from: "scrape-configs.ts", name: "api" },
142
+ { from: "prometheus.ts", name: "prometheus" },
143
+ ],
144
+ shape: "list",
145
+ through: { from: "@intentius/chant-lexicon-prometheus", name: "prometheusConfigYaml" },
146
+ });
147
+ expect(out.warnings).toEqual([]);
148
+ });
149
+ });
@@ -16,12 +16,19 @@
16
16
  * ConfigMap then holds the config as the serializer writes it: the same
17
17
  * config, with Alertmanager's deprecated spellings rewritten as the
18
18
  * standalone import rewrites them.
19
+ *
20
+ * A `prometheus.yml` held as text in a ConfigMap is imported exactly as
21
+ * `chant import prometheus.yml` would import it, and becomes
22
+ * `prometheusConfigYaml([...])` over every scrape job and the sections
23
+ * besides them. The ConfigMap then holds the config as the serializer
24
+ * writes it: scrape jobs sorted by name, sections in Prometheus's order.
19
25
  */
20
26
 
21
27
  import type { EmbeddedContentImporter, EmbeddedImport } from "@intentius/chant/import/embedded";
22
28
  import { looksLikeAlertmanagerConfig, looksLikeRuleFile } from "../model";
29
+ import { looksLikePrometheusConfig } from "../config-model";
23
30
  import { parsePrometheusYaml } from "./parser";
24
- import { generateAlertmanager, generateRuleFile } from "./generator";
31
+ import { generateAlertmanager, generatePrometheusConfig, generateRuleFile } from "./generator";
25
32
 
26
33
  const PACKAGE = "@intentius/chant-lexicon-prometheus";
27
34
 
@@ -74,3 +81,27 @@ export const alertmanagerImporter: EmbeddedContentImporter = {
74
81
  };
75
82
  },
76
83
  };
84
+
85
+ export const prometheusConfigImporter: EmbeddedContentImporter = {
86
+ what: "a prometheus.yml",
87
+
88
+ matches(content) {
89
+ return content.select === undefined && typeof content.text === "string" && looksLikePrometheusConfig(content.document);
90
+ },
91
+
92
+ import(content): EmbeddedImport {
93
+ const parsed = parsePrometheusYaml(content.text!);
94
+ if (parsed.kind !== "prometheus") throw new Error("this is not a prometheus.yml");
95
+ const { files, declarations } = generatePrometheusConfig(parsed.config);
96
+ if (declarations.length === 0) throw new Error("the import declared nothing");
97
+ return {
98
+ files,
99
+ value: {
100
+ bindings: declarations.map((d) => ({ from: d.path, name: d.name })),
101
+ shape: "list",
102
+ through: { from: PACKAGE, name: "prometheusConfigYaml" },
103
+ },
104
+ warnings: parsed.warnings,
105
+ };
106
+ },
107
+ };
@@ -629,6 +629,21 @@ const SECTION_TYPES: Record<string, string> = {
629
629
 
630
630
  /** Generate the TypeScript declaring one `prometheus.yml`. */
631
631
  export function generatePrometheusConfigFiles(config: PrometheusConfigFile): GeneratedFile[] {
632
+ return generatePrometheusConfig(config).files;
633
+ }
634
+
635
+ /** A declaration a `prometheus.yml` import exports: its module and variable. */
636
+ export interface PrometheusConfigDeclaration {
637
+ readonly path: string;
638
+ readonly name: string;
639
+ }
640
+
641
+ /**
642
+ * Generate the TypeScript declaring one `prometheus.yml`, and list every
643
+ * declaration it exports, module by module (a ConfigMap holding the file
644
+ * becomes `prometheusConfigYaml([...])` over them).
645
+ */
646
+ export function generatePrometheusConfig(config: PrometheusConfigFile): { files: GeneratedFile[]; declarations: PrometheusConfigDeclaration[] } {
632
647
  const names = new Names([...LEXICON_NAMES, ...Object.keys(SECTION_TYPES)]);
633
648
  const modules: Module[] = [];
634
649
 
@@ -694,7 +709,10 @@ export function generatePrometheusConfigFiles(config: PrometheusConfigFile): Gen
694
709
  mod.exports.push(v);
695
710
  }
696
711
 
697
- return modules.map((m) => ({ path: m.path, content: m.render() }));
712
+ return {
713
+ files: modules.map((m) => ({ path: m.path, content: m.render() })),
714
+ declarations: modules.flatMap((m) => m.exports.map((name) => ({ path: m.path, name }))),
715
+ };
698
716
  }
699
717
 
700
718
  /** The rule file and `alertmanager.yml` TypeScript generator `chant import` runs. */