@intentius/chant-lexicon-prometheus 0.97.0 → 0.99.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.
- package/README.md +6 -1
- package/dist/alertmanager.d.ts +4 -2
- package/dist/alertmanager.d.ts.map +1 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/codegen/docs.d.ts.map +1 -1
- package/dist/import/embedded.d.ts +14 -0
- package/dist/import/embedded.d.ts.map +1 -0
- package/dist/import/generator.d.ts +50 -0
- package/dist/import/generator.d.ts.map +1 -0
- package/dist/import/parser.d.ts +52 -0
- package/dist/import/parser.d.ts.map +1 -0
- package/dist/import/slo.d.ts +15 -0
- package/dist/import/slo.d.ts.map +1 -0
- package/dist/integrations.d.ts +531 -0
- package/dist/integrations.d.ts.map +1 -0
- package/dist/integrity.json +7 -7
- package/dist/lint/rules/literal-credential.d.ts.map +1 -1
- package/dist/lint/rules/prom-ast.d.ts +8 -0
- package/dist/lint/rules/prom-ast.d.ts.map +1 -1
- package/dist/lint/rules/promql-literal.d.ts.map +1 -1
- package/dist/manifest.json +1 -1
- package/dist/model.d.ts +77 -121
- package/dist/model.d.ts.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/rules/literal-credential.ts +52 -15
- package/dist/rules/prom-ast.ts +36 -0
- package/dist/rules/promql-literal.ts +15 -1
- package/dist/skills/chant-prometheus-alertmanager.md +4 -0
- package/dist/skills/chant-prometheus.md +11 -0
- package/package.json +2 -2
- package/src/alertmanager.ts +4 -1
- package/src/build.ts +2 -0
- package/src/codegen/docs.ts +5 -1
- package/src/import/cli.test.ts +98 -0
- package/src/import/embedded.test.ts +56 -0
- package/src/import/embedded.ts +44 -0
- package/src/import/generated-types.e2e.test.ts +77 -0
- package/src/import/generator.test.ts +138 -0
- package/src/import/generator.ts +578 -0
- package/src/import/parser.test.ts +133 -0
- package/src/import/parser.ts +365 -0
- package/src/import/roundtrip.test.ts +358 -0
- package/src/import/slo.ts +175 -0
- package/src/import/testdata/alertmanager-full.yml +89 -0
- package/src/import/testdata/alertmanager-integrations.yml +215 -0
- package/src/import/testdata/fixtures.ts +122 -0
- package/src/import/testdata/rules-full.yml +42 -0
- package/src/import/testdata/upstream/alertmanager-conf-good.yml +120 -0
- package/src/import/testdata/upstream/alertmanager-mattermost-default-webhook-url-file.yml +16 -0
- package/src/import/testdata/upstream/alertmanager-opsgenie-default-apikey-file.yml +27 -0
- package/src/import/testdata/upstream/alertmanager-rocketchat-default-token-file.yml +25 -0
- package/src/import/testdata/upstream/alertmanager-route-labels.yml +65 -0
- package/src/import/testdata/upstream/alertmanager-simple.yml +130 -0
- package/src/import/testdata/upstream/alertmanager-sns-topic-arn.yml +17 -0
- package/src/import/testdata/upstream/alertmanager-telegram-default-bot-token-file.yml +16 -0
- package/src/import/testdata/upstream/alertmanager-victorops-default-apikey-file.yml +23 -0
- package/src/import/testdata/upstream/alertmanager-wechat-default-api-secret-file.yml +18 -0
- package/src/import/testdata/upstream/prometheus-alerting-rules.yml +15 -0
- package/src/import/testdata/upstream/prometheus-alerting-templates.yml +23 -0
- package/src/import/testdata/upstream/prometheus-recording-rules.yml +7 -0
- package/src/integrations.ts +538 -0
- package/src/lint/rules/literal-credential.ts +52 -15
- package/src/lint/rules/prom-ast.ts +36 -0
- package/src/lint/rules/promql-literal.ts +15 -1
- package/src/lint/rules/rules.test.ts +58 -0
- package/src/model.ts +157 -109
- package/src/plugin.ts +15 -0
- package/src/skills/chant-prometheus-alertmanager.md +4 -0
- package/src/skills/chant-prometheus.md +11 -0
package/README.md
CHANGED
|
@@ -27,10 +27,14 @@ export { api, oncall, fallback, root };
|
|
|
27
27
|
|---|---|
|
|
28
28
|
| `RuleGroup` | rule file |
|
|
29
29
|
| `Slo` (composite) | rule file: SLI recording rules, error budget and multiwindow burn-rate alerts |
|
|
30
|
-
| `Route`, `Receiver` (
|
|
30
|
+
| `Route`, `Receiver` (every Alertmanager integration), `InhibitRule`, `TimeInterval`, `AlertmanagerSettings` | `alertmanager.yml` |
|
|
31
31
|
|
|
32
32
|
Types follow Prometheus `v3.15.0` and Alertmanager `v0.34.1` (`PROMETHEUS_PIN`).
|
|
33
33
|
|
|
34
|
+
## Importing existing files
|
|
35
|
+
|
|
36
|
+
`chant import rules.yml --output src` and `chant import alertmanager.yml --output src` turn an existing rule file or Alertmanager config into this lexicon's TypeScript (`--lexicon prometheus` skips detection). Rules stay plain objects in a `Rule[]` const beside each `RuleGroup`; a group an `Slo()` built comes back as the `Slo` call. Routes reference receivers and time intervals by variable. `*_file` credential paths and Go templates are kept as written, and a literal credential is imported as found for PROM001 to report. `chant build` on the result gives back the same files: the round-trip tests in `src/import/roundtrip.test.ts` hold every example's output, `Slo()` output, and samples from the Prometheus docs and Alertmanager's example configs to that, and run `promtool` and `amtool` over the rebuilt files when installed.
|
|
37
|
+
|
|
34
38
|
## Checks
|
|
35
39
|
|
|
36
40
|
PROM001 to PROM003 run on source (literal credentials, PromQL syntax in literals, `Slo` objective, window and SLI literals). PROM101 to PROM107 run over the built rule file: unique group names, duplicate rules, durations, PromQL syntax, rule shape, severity labels and summaries. PROM201 to PROM209 run over `alertmanager.yml`: receivers and time intervals that exist, every alert severity routed (PROM202, one build root at a time), root route shape, matcher syntax, unused receivers, durations and integrations without a destination.
|
|
@@ -54,5 +58,6 @@ PromQL is parsed with `@prometheus-io/lezer-promql`, the Prometheus project's ow
|
|
|
54
58
|
- `src/promql.ts`, `src/matchers.ts`, `src/duration.ts`: parsing
|
|
55
59
|
- `src/validate-config.ts`, `src/lint/`: checks
|
|
56
60
|
- `src/tools.ts`: promtool and amtool
|
|
61
|
+
- `src/import/`: `chant import` for rule files and `alertmanager.yml` (parser, generator, `Slo` recognition, round-trip tests and fixtures)
|
|
57
62
|
- `src/rule-eval.ts`: a small rule evaluator the SLO tests run over synthetic series
|
|
58
63
|
- `examples/`: getting-started, alerting, rules-from-data, slo, k3d-stack
|
package/dist/alertmanager.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* objects.
|
|
13
13
|
*/
|
|
14
14
|
import type { Declarable } from "@intentius/chant/declarable";
|
|
15
|
-
import type { AlertmanagerGlobalConfig, InhibitRuleConfig, ReceiverConfig, RouteConfig, TimeIntervalConfig } from "./model.js";
|
|
15
|
+
import type { AlertmanagerGlobalConfig, AlertmanagerTracingConfig, InhibitRuleConfig, ReceiverConfig, RouteConfig, TimeIntervalConfig } from "./model.js";
|
|
16
16
|
export declare const RECEIVER_TYPE = "Prometheus::Alertmanager::Receiver";
|
|
17
17
|
export declare const ROUTE_TYPE = "Prometheus::Alertmanager::Route";
|
|
18
18
|
export declare const INHIBIT_RULE_TYPE = "Prometheus::Alertmanager::InhibitRule";
|
|
@@ -64,11 +64,13 @@ export interface AlertmanagerSettingsProps {
|
|
|
64
64
|
global?: AlertmanagerGlobalConfig;
|
|
65
65
|
/** Paths of notification template files. */
|
|
66
66
|
templates?: string[];
|
|
67
|
+
/** Where Alertmanager sends its own traces. */
|
|
68
|
+
tracing?: AlertmanagerTracingConfig;
|
|
67
69
|
}
|
|
68
70
|
export interface AlertmanagerSettingsEntity extends Declarable {
|
|
69
71
|
readonly props: AlertmanagerSettingsProps;
|
|
70
72
|
}
|
|
71
|
-
/** The `global:` block and `
|
|
73
|
+
/** The `global:` block, `templates:` list and `tracing:` block. Optional; declare at most one. */
|
|
72
74
|
export declare const AlertmanagerSettings: Ctor<AlertmanagerSettingsProps, AlertmanagerSettingsEntity>;
|
|
73
75
|
export declare const isReceiver: (value: unknown) => value is ReceiverEntity;
|
|
74
76
|
export declare const isRoute: (value: unknown) => value is RouteEntity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alertmanager.d.ts","sourceRoot":"","sources":["../src/alertmanager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAi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U,CAAC,GAAG,MAAM,CAEjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/codegen/docs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/codegen/docs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgFH,wBAAsB,YAAY,CAAC,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuB9E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule groups embedded in another lexicon's resource, for `chant import`
|
|
3
|
+
* (#2962): a k8s `PrometheusRule`'s `spec.groups`, or a rule file held as
|
|
4
|
+
* text in a ConfigMap.
|
|
5
|
+
*
|
|
6
|
+
* The groups are imported exactly as `chant import rules.yml` would import
|
|
7
|
+
* them, into a directory of its own. `spec.groups` becomes the list of the
|
|
8
|
+
* declared groups (an `Slo`'s by its `rules` member), which the k8s
|
|
9
|
+
* serializer renders as the same groups; a rule file becomes
|
|
10
|
+
* `ruleFileYaml([...])`, the text the prometheus serializer writes.
|
|
11
|
+
*/
|
|
12
|
+
import type { EmbeddedContentImporter } from "@intentius/chant/import/embedded";
|
|
13
|
+
export declare const ruleGroupsImporter: EmbeddedContentImporter;
|
|
14
|
+
//# sourceMappingURL=embedded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../../src/import/embedded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAkB,MAAM,kCAAkC,CAAC;AAOhG,eAAO,MAAM,kBAAkB,EAAE,uBAwBhC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `TemplateIR` -> TypeScript, for `chant import`.
|
|
3
|
+
*
|
|
4
|
+
* Writes the files the way the lexicon's examples are written: nested
|
|
5
|
+
* settings lifted into named consts typed by the model (COR001), at most
|
|
6
|
+
* eight declarables per module (COR009), and an `export { ... }` list at the
|
|
7
|
+
* end of each module (COR004 flags an exported declaration nothing in its
|
|
8
|
+
* file uses).
|
|
9
|
+
*
|
|
10
|
+
* A rule file becomes `rules.ts`: per group, its rules as a `Rule[]` const
|
|
11
|
+
* of plain objects, the same shape `ruleGroupConfig` emits, and a
|
|
12
|
+
* `RuleGroup`. A group an `Slo()` built is written as that `Slo` call in
|
|
13
|
+
* `slos.ts` instead (see ./slo.ts).
|
|
14
|
+
*
|
|
15
|
+
* An `alertmanager.yml` becomes `receivers.ts`, `time-intervals.ts`,
|
|
16
|
+
* `routes.ts` (the root `Route`, its children as `RouteProps` objects),
|
|
17
|
+
* `inhibit-rules.ts` and `settings.ts`. Routes name their receivers and time
|
|
18
|
+
* intervals by the declared variable, imported from the module that
|
|
19
|
+
* declares it; a name nothing declares stays a string, and PROM201 / PROM204
|
|
20
|
+
* report it.
|
|
21
|
+
*/
|
|
22
|
+
import type { GeneratedFile, TypeScriptGenerator } from "@intentius/chant/import/generator";
|
|
23
|
+
import type { TemplateIR } from "@intentius/chant/import/parser";
|
|
24
|
+
import type { AlertmanagerConfig, RuleFileConfig } from "../model.js";
|
|
25
|
+
/** A value as a TypeScript expression, starting at column `col`, indented by `indent` spaces. */
|
|
26
|
+
export declare function tsLiteral(v: unknown, indent: number, col?: number): string;
|
|
27
|
+
/** Generate the TypeScript declaring one rule file. */
|
|
28
|
+
export declare function generateRuleFileFiles(file: RuleFileConfig): GeneratedFile[];
|
|
29
|
+
/** A rule group's declaration: the module and variable, and `rules` when it is an `Slo`'s group. */
|
|
30
|
+
export interface GroupDeclaration {
|
|
31
|
+
readonly path: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly member?: "rules";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generate the TypeScript declaring one rule file, and say where each of its
|
|
37
|
+
* groups is declared, in the file's order (#2962: a PrometheusRule's
|
|
38
|
+
* `spec.groups` refers to them).
|
|
39
|
+
*/
|
|
40
|
+
export declare function generateRuleFile(file: RuleFileConfig): {
|
|
41
|
+
files: GeneratedFile[];
|
|
42
|
+
groups: GroupDeclaration[];
|
|
43
|
+
};
|
|
44
|
+
/** Generate the TypeScript declaring one `alertmanager.yml`. */
|
|
45
|
+
export declare function generateAlertmanagerFiles(config: AlertmanagerConfig): GeneratedFile[];
|
|
46
|
+
/** The rule file and `alertmanager.yml` TypeScript generator `chant import` runs. */
|
|
47
|
+
export declare class PrometheusGenerator implements TypeScriptGenerator {
|
|
48
|
+
generate(ir: TemplateIR): GeneratedFile[];
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +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,EAIlB,cAAc,EAGf,MAAM,UAAU,CAAC;AAmFlB,iGAAiG;AACjG,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAmB1E;AAyID,uDAAuD;AACvD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,cAAc,GAAG,aAAa,EAAE,CAE3E;AAED,oGAAoG;AACpG,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG;IAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAAC,MAAM,EAAE,gBAAgB,EAAE,CAAA;CAAE,CA4D7G;AAgCD,gEAAgE;AAChE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,kBAAkB,GAAG,aAAa,EAAE,CAmLrF;AAED,qFAAqF;AACrF,qBAAa,mBAAoB,YAAW,mBAAmB;IAC7D,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,aAAa,EAAE;CAY1C"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule file or `alertmanager.yml` -> `TemplateIR`, for `chant import`.
|
|
3
|
+
*
|
|
4
|
+
* Either file is one document whose parts name each other (a route names a
|
|
5
|
+
* receiver and time intervals), so the IR carries the whole file as one
|
|
6
|
+
* resource and the generator lays out the modules itself, turning those
|
|
7
|
+
* names into imports of declared entities. Core splits an IR with more than
|
|
8
|
+
* three resources into one generate() call per category and keeps only the
|
|
9
|
+
* first file of each, which would lose the imports between a route and the
|
|
10
|
+
* receivers it names.
|
|
11
|
+
*
|
|
12
|
+
* Values are carried as written: `*_file` credential paths, Go templates in
|
|
13
|
+
* annotations and notifier fields, and literal credentials, which PROM001
|
|
14
|
+
* then reports in the generated source. What the lexicon has no place for is
|
|
15
|
+
* named in `warnings`. Two deprecated Alertmanager spellings are rewritten to
|
|
16
|
+
* the ones Alertmanager treats the same way: `match` / `match_re` (and the
|
|
17
|
+
* inhibit rules' `source_match*` / `target_match*`) become matcher strings,
|
|
18
|
+
* and the top-level `mute_time_intervals` list joins `time_intervals`.
|
|
19
|
+
*/
|
|
20
|
+
import type { TemplateIR, TemplateParser } from "@intentius/chant/import/parser";
|
|
21
|
+
import { type AlertmanagerConfig, type RuleFileConfig } from "../model.js";
|
|
22
|
+
/** The IR resource type for a whole rule file. */
|
|
23
|
+
export declare const RULE_FILE_RESOURCE_TYPE = "Prometheus::RuleFile";
|
|
24
|
+
/** The IR resource type for a whole `alertmanager.yml`. */
|
|
25
|
+
export declare const ALERTMANAGER_RESOURCE_TYPE = "Prometheus::Alertmanager::Config";
|
|
26
|
+
/** `properties` of the `Prometheus::RuleFile` resource. */
|
|
27
|
+
export interface RuleFileResourceProperties {
|
|
28
|
+
file: RuleFileConfig;
|
|
29
|
+
}
|
|
30
|
+
/** `properties` of the `Prometheus::Alertmanager::Config` resource. */
|
|
31
|
+
export interface AlertmanagerResourceProperties {
|
|
32
|
+
config: AlertmanagerConfig;
|
|
33
|
+
}
|
|
34
|
+
/** What the parser read. */
|
|
35
|
+
export type ParsedPrometheusFile = {
|
|
36
|
+
kind: "rules";
|
|
37
|
+
file: RuleFileConfig;
|
|
38
|
+
warnings: string[];
|
|
39
|
+
} | {
|
|
40
|
+
kind: "alertmanager";
|
|
41
|
+
config: AlertmanagerConfig;
|
|
42
|
+
warnings: string[];
|
|
43
|
+
};
|
|
44
|
+
/** A matcher string Alertmanager parses back to `name op value`. */
|
|
45
|
+
export declare function matcherString(name: string, op: "=" | "=~", value: string): string;
|
|
46
|
+
/** Parse a rule file or `alertmanager.yml`, telling them apart by shape. */
|
|
47
|
+
export declare function parsePrometheusYaml(content: string): ParsedPrometheusFile;
|
|
48
|
+
/** The rule file and `alertmanager.yml` parser `chant import` runs. */
|
|
49
|
+
export declare class PrometheusParser implements TemplateParser {
|
|
50
|
+
parse(content: string): TemplateIR;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/import/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAKL,KAAK,kBAAkB,EAKvB,KAAK,cAAc,EAGpB,MAAM,UAAU,CAAC;AAGlB,kDAAkD;AAClD,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AAC9D,2DAA2D;AAC3D,eAAO,MAAM,0BAA0B,qCAAqC,CAAC;AAE7E,2DAA2D;AAC3D,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,uEAAuE;AACvE,MAAM,WAAW,8BAA8B;IAC7C,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,4BAA4B;AAC5B,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAgH7E,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGjF;AA4JD,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAezE;AAED,uEAAuE;AACvE,qBAAa,gBAAiB,YAAW,cAAc;IACrD,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU;CAgBnC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recognise a rule group that `Slo()` built, so the importer can write the
|
|
3
|
+
* `Slo` declaration instead of its forty-odd lines of rules.
|
|
4
|
+
*
|
|
5
|
+
* The group's name, recorded series, objective and burn-rate alerts give
|
|
6
|
+
* back candidate props; the candidate is accepted only when `Slo()` builds
|
|
7
|
+
* it to the same group, rule for rule. Anything else (a hand-edited
|
|
8
|
+
* threshold, an extra rule, a different description) fails that check and
|
|
9
|
+
* the group is imported as a plain `RuleGroup`.
|
|
10
|
+
*/
|
|
11
|
+
import { type SloProps } from "../composites/slo.js";
|
|
12
|
+
import { type RuleGroupConfig } from "../model.js";
|
|
13
|
+
/** The `Slo` props that build exactly `group`, or `undefined` when no `Slo()` call does. */
|
|
14
|
+
export declare function recognizeSlo(group: RuleGroupConfig): SloProps | undefined;
|
|
15
|
+
//# sourceMappingURL=slo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slo.d.ts","sourceRoot":"","sources":["../../src/import/slo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAsE,KAAK,QAAQ,EAAuB,MAAM,mBAAmB,CAAC;AAG3I,OAAO,EAAuF,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AA8DrI,4FAA4F;AAC5F,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,QAAQ,GAAG,SAAS,CAiGzE"}
|