@intentius/chant-lexicon-grafana 0.106.3 → 0.107.1
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/dist/composites/red-dashboard.d.ts +5 -3
- package/dist/composites/red-dashboard.d.ts.map +1 -1
- package/dist/composites/shared.d.ts +2 -1
- package/dist/composites/shared.d.ts.map +1 -1
- package/dist/integrity.json +2 -2
- package/dist/manifest.json +1 -1
- package/package.json +2 -2
- package/src/composites/red-dashboard.ts +19 -60
- package/src/composites/shared.ts +19 -8
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* its internal spans don't inflate its rate or dilute its error ratio.
|
|
13
13
|
*/
|
|
14
14
|
import { type CompositeInstance } from "@intentius/chant/composite";
|
|
15
|
-
import { type PrometheusNaming, type SpanMetricsNames } from "@intentius/chant-lexicon-otel/metric-names";
|
|
15
|
+
import { type PrometheusNaming, type SpanMetricsKind, type SpanMetricsNames } from "@intentius/chant-lexicon-otel/metric-names";
|
|
16
16
|
import type { OTelComponent } from "@intentius/chant-lexicon-otel/define";
|
|
17
17
|
import type { SpanMetricsConnectorConfig } from "@intentius/chant-lexicon-otel/components/connectors";
|
|
18
18
|
import type { PrometheusExporterConfig } from "@intentius/chant-lexicon-otel/components/exporters";
|
|
@@ -37,7 +37,7 @@ export interface RedDashboardProps extends DashboardOptions {
|
|
|
37
37
|
spanKinds?: SpanKind[];
|
|
38
38
|
}
|
|
39
39
|
/** The `span_kind` label values the spanmetrics connector writes. */
|
|
40
|
-
export type SpanKind =
|
|
40
|
+
export type SpanKind = SpanMetricsKind;
|
|
41
41
|
/** The kinds `RedDashboard` counts unless told otherwise: the spans that serve a request or consume a message. */
|
|
42
42
|
export declare const RED_DEFAULT_SPAN_KINDS: readonly SpanKind[];
|
|
43
43
|
export type RedDashboardMembers = {
|
|
@@ -48,7 +48,9 @@ export type RedDashboardInstance = CompositeInstance<RedDashboardMembers> & RedD
|
|
|
48
48
|
/**
|
|
49
49
|
* The PromQL the RED dashboard runs, from the connector's names. Exposed for
|
|
50
50
|
* tests and for panels of your own. `spanKinds` defaults to server and
|
|
51
|
-
* consumer spans; `[]` counts every kind.
|
|
51
|
+
* consumer spans; `[]` counts every kind. The expressions come from the otel
|
|
52
|
+
* lexicon's `spanMetricsRedQueries()`, which the prometheus lexicon's
|
|
53
|
+
* `RedAlerts` reads too.
|
|
52
54
|
*/
|
|
53
55
|
export declare function redQueries(names: SpanMetricsNames, quantiles?: number[], serviceFilter?: string, spanKinds?: readonly SpanKind[]): {
|
|
54
56
|
rate: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"red-dashboard.d.ts","sourceRoot":"","sources":["../../src/composites/red-dashboard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAa,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,
|
|
1
|
+
{"version":3,"file":"red-dashboard.d.ts","sourceRoot":"","sources":["../../src/composites/red-dashboard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAa,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAIL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qDAAqD,CAAC;AACtG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAK/D,OAAO,EAAmF,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAElI,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD;;;OAGG;IACH,WAAW,EAAE,aAAa,CAAC,WAAW,EAAE,aAAa,EAAE,0BAA0B,CAAC,GAAG,gBAAgB,CAAC;IACtG,mHAAmH;IACnH,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,wBAAwB,CAAC,GAAG,gBAAgB,CAAC;IAChG,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;CACxB;AAED,qEAAqE;AACrE,MAAM,MAAM,QAAQ,GAAG,eAAe,CAAC;AAEvC,kHAAkH;AAClH,eAAO,MAAM,sBAAsB,EAAE,SAAS,QAAQ,EAA8B,CAAC;AAErF,MAAM,MAAM,mBAAmB,GAAG;IAAE,SAAS,EAAE,eAAe,CAAA;CAAE,CAAC;AAEjE,uEAAuE;AACvE,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;AAYhG;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,gBAAgB,EACvB,SAAS,GAAE,MAAM,EAAsB,EACvC,aAAa,SAAa,EAC1B,SAAS,CAAC,EAAE,SAAS,QAAQ,EAAE;IAI7B,IAAI;IACJ,UAAU;IACV,QAAQ;;;;IACR,QAAQ;EAEX;AAUD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,wFAuEP,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* What the dashboard composites share: the dashboard-level props they all
|
|
3
3
|
* take, a PromQL selector builder, and the field configs they reuse.
|
|
4
4
|
*/
|
|
5
|
+
import { type PromMatcher } from "@intentius/chant-lexicon-otel/metric-names";
|
|
5
6
|
import type { DatasourceInput } from "../query.js";
|
|
6
7
|
import type { DashboardLinkInput } from "../dashboard.js";
|
|
7
8
|
import type { FolderEntity } from "../folder.js";
|
|
@@ -27,7 +28,7 @@ export interface DashboardOptions {
|
|
|
27
28
|
links?: DashboardLinkInput[];
|
|
28
29
|
}
|
|
29
30
|
/** A label matcher: `[label, op, value]`. */
|
|
30
|
-
export type Matcher =
|
|
31
|
+
export type Matcher = PromMatcher;
|
|
31
32
|
/** `metric{a="x", b=~"y"}`; just `metric` with no matchers. */
|
|
32
33
|
export declare function selector(metric: string, matchers: Matcher[]): string;
|
|
33
34
|
/** `sum by (labels) (rate(sel[range]))`, or `sum (...)` with no labels. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/composites/shared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,+FAA+F;AAC/F,MAAM,WAAW,gBAAgB;IAC/B,yIAAyI;IACzI,UAAU,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC/B,0BAA0B;IAC1B,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAED,6CAA6C;AAC7C,MAAM,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/composites/shared.ts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e4b9ab0cf3b70434a198042a9a6c55c",
|
|
5
5
|
"meta.json": "330a1598c3b35ae62267e886a3416a494b0ebe9f1d2e2379253787d0a0bcb32e",
|
|
6
6
|
"types/index.d.ts": "ad385264290f2486f7a54be205684de8415a25b74eee5b809ca625ae19fb08da",
|
|
7
7
|
"rules/grafana-ast.ts": "51f4fac423f7a5c6d6f577074e95b4a70d4ab0a05883a86e04970a50c63d92e8",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"skills/chant-grafana-alerting.md": "d9648dc14c848851bdccbe069dac54ad06115066f9466c90c4137d07dde6d4ad",
|
|
32
32
|
"skills/chant-grafana-operations.md": "4e665f80292ab32bde6d77940cc3f3923678c58e6db0b80613489050d2cb665b"
|
|
33
33
|
},
|
|
34
|
-
"composite": "
|
|
34
|
+
"composite": "3cd566cebfaf02692a4bbac19eb97a0e7f346f885e8367193c28b237958e6a8f"
|
|
35
35
|
}
|
package/dist/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-grafana",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.107.1",
|
|
4
4
|
"description": "Grafana lexicon for chant — typed dashboards, panels, queries and datasources, serialized to dashboard JSON and Grafana provisioning files",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://intentius.io/chant",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"zod": "^4.3.6"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@intentius/chant": "^0.
|
|
86
|
+
"@intentius/chant": "^0.107.1",
|
|
87
87
|
"typescript": "^5.9.3",
|
|
88
88
|
"zod": "^4.3.6"
|
|
89
89
|
}
|
|
@@ -13,7 +13,14 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { Composite, type CompositeInstance } from "@intentius/chant/composite";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
RED_DEFAULT_SPAN_KINDS as SHARED_DEFAULT_SPAN_KINDS,
|
|
18
|
+
spanMetricsNames,
|
|
19
|
+
spanMetricsRedQueries,
|
|
20
|
+
type PrometheusNaming,
|
|
21
|
+
type SpanMetricsKind,
|
|
22
|
+
type SpanMetricsNames,
|
|
23
|
+
} from "@intentius/chant-lexicon-otel/metric-names";
|
|
17
24
|
import type { OTelComponent } from "@intentius/chant-lexicon-otel/define";
|
|
18
25
|
import type { SpanMetricsConnectorConfig } from "@intentius/chant-lexicon-otel/components/connectors";
|
|
19
26
|
import type { PrometheusExporterConfig } from "@intentius/chant-lexicon-otel/components/exporters";
|
|
@@ -22,19 +29,7 @@ import { Row, TimeSeriesPanel } from "../panels";
|
|
|
22
29
|
import { PromQuery } from "../query";
|
|
23
30
|
import { QueryVariable } from "../variables";
|
|
24
31
|
import { slugUid } from "../util";
|
|
25
|
-
import {
|
|
26
|
-
dashboardProps,
|
|
27
|
-
durationUnit,
|
|
28
|
-
errorRatio,
|
|
29
|
-
legend,
|
|
30
|
-
quantile,
|
|
31
|
-
quantileName,
|
|
32
|
-
requireDatasource,
|
|
33
|
-
selector,
|
|
34
|
-
sumRate,
|
|
35
|
-
type DashboardOptions,
|
|
36
|
-
type Matcher,
|
|
37
|
-
} from "./shared";
|
|
32
|
+
import { dashboardProps, durationUnit, legend, quantileName, requireDatasource, selector, type DashboardOptions } from "./shared";
|
|
38
33
|
|
|
39
34
|
export interface RedDashboardProps extends DashboardOptions {
|
|
40
35
|
/**
|
|
@@ -56,25 +51,10 @@ export interface RedDashboardProps extends DashboardOptions {
|
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
/** The `span_kind` label values the spanmetrics connector writes. */
|
|
59
|
-
export type SpanKind =
|
|
60
|
-
| "SPAN_KIND_UNSPECIFIED"
|
|
61
|
-
| "SPAN_KIND_INTERNAL"
|
|
62
|
-
| "SPAN_KIND_SERVER"
|
|
63
|
-
| "SPAN_KIND_CLIENT"
|
|
64
|
-
| "SPAN_KIND_PRODUCER"
|
|
65
|
-
| "SPAN_KIND_CONSUMER";
|
|
66
|
-
|
|
67
|
-
const SPAN_KINDS: readonly SpanKind[] = [
|
|
68
|
-
"SPAN_KIND_UNSPECIFIED",
|
|
69
|
-
"SPAN_KIND_INTERNAL",
|
|
70
|
-
"SPAN_KIND_SERVER",
|
|
71
|
-
"SPAN_KIND_CLIENT",
|
|
72
|
-
"SPAN_KIND_PRODUCER",
|
|
73
|
-
"SPAN_KIND_CONSUMER",
|
|
74
|
-
];
|
|
54
|
+
export type SpanKind = SpanMetricsKind;
|
|
75
55
|
|
|
76
56
|
/** The kinds `RedDashboard` counts unless told otherwise: the spans that serve a request or consume a message. */
|
|
77
|
-
export const RED_DEFAULT_SPAN_KINDS: readonly SpanKind[] =
|
|
57
|
+
export const RED_DEFAULT_SPAN_KINDS: readonly SpanKind[] = SHARED_DEFAULT_SPAN_KINDS;
|
|
78
58
|
|
|
79
59
|
export type RedDashboardMembers = { dashboard: DashboardEntity };
|
|
80
60
|
|
|
@@ -91,25 +71,12 @@ function isNames(x: unknown): x is SpanMetricsNames {
|
|
|
91
71
|
return typeof x === "object" && x !== null && "calls" in x && "labels" in x && "errorStatus" in x;
|
|
92
72
|
}
|
|
93
73
|
|
|
94
|
-
/**
|
|
95
|
-
* The span-kind matcher for `kinds`, or none: none for `[]`, and none for
|
|
96
|
-
* the default kinds when the connector excludes `span.kind`.
|
|
97
|
-
*/
|
|
98
|
-
function spanKindMatchers(names: SpanMetricsNames, kinds: readonly SpanKind[] | undefined): Matcher[] {
|
|
99
|
-
const label = names.labels.spanKind;
|
|
100
|
-
if (kinds === undefined) return label ? [[label, "=~", RED_DEFAULT_SPAN_KINDS.join("|")]] : [];
|
|
101
|
-
for (const k of kinds) {
|
|
102
|
-
if (!SPAN_KINDS.includes(k)) throw new Error(`RedDashboard: unknown span kind ${JSON.stringify(k)}; use one of ${SPAN_KINDS.join(", ")}`);
|
|
103
|
-
}
|
|
104
|
-
if (kinds.length === 0) return [];
|
|
105
|
-
if (!label) throw new Error("RedDashboard: the connector excludes span.kind, so the metrics can't be filtered by spanKinds");
|
|
106
|
-
return [[label, "=~", [...new Set(kinds)].join("|")]];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
74
|
/**
|
|
110
75
|
* The PromQL the RED dashboard runs, from the connector's names. Exposed for
|
|
111
76
|
* tests and for panels of your own. `spanKinds` defaults to server and
|
|
112
|
-
* consumer spans; `[]` counts every kind.
|
|
77
|
+
* consumer spans; `[]` counts every kind. The expressions come from the otel
|
|
78
|
+
* lexicon's `spanMetricsRedQueries()`, which the prometheus lexicon's
|
|
79
|
+
* `RedAlerts` reads too.
|
|
113
80
|
*/
|
|
114
81
|
export function redQueries(
|
|
115
82
|
names: SpanMetricsNames,
|
|
@@ -117,20 +84,12 @@ export function redQueries(
|
|
|
117
84
|
serviceFilter = "$service",
|
|
118
85
|
spanKinds?: readonly SpanKind[],
|
|
119
86
|
) {
|
|
120
|
-
const
|
|
121
|
-
const status = names.labels.statusCode;
|
|
122
|
-
if (!svc) throw new Error("RedDashboard: the connector excludes service.name, so there is no service to break the metrics down by");
|
|
123
|
-
if (!status) throw new Error("RedDashboard: the connector excludes status.code, so errors can't be told from successes");
|
|
124
|
-
const kind = spanKindMatchers(names, spanKinds);
|
|
125
|
-
const scope: Matcher[] = [[svc, "=~", serviceFilter], ...kind];
|
|
126
|
-
const calls = selector(names.calls.prometheus, scope);
|
|
127
|
-
const errors = selector(names.calls.prometheus, [...scope, [status, "=", names.errorStatus]]);
|
|
128
|
-
const buckets = names.duration ? selector(`${names.duration.prometheus}_bucket`, scope) : undefined;
|
|
87
|
+
const q = spanMetricsRedQueries(names, { range: "$__rate_interval", quantiles, serviceMatch: serviceFilter, spanKinds, owner: "RedDashboard" });
|
|
129
88
|
return {
|
|
130
|
-
rate:
|
|
131
|
-
errorRatio: errorRatio
|
|
132
|
-
duration:
|
|
133
|
-
services: `label_values(${selector(names.calls.prometheus,
|
|
89
|
+
rate: q.rate,
|
|
90
|
+
errorRatio: q.errorRatio,
|
|
91
|
+
duration: q.duration,
|
|
92
|
+
services: `label_values(${selector(names.calls.prometheus, q.kindMatchers)}, ${q.service})`,
|
|
134
93
|
};
|
|
135
94
|
}
|
|
136
95
|
|
package/src/composites/shared.ts
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
* take, a PromQL selector builder, and the field configs they reuse.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
promErrorRatio,
|
|
8
|
+
promNumber,
|
|
9
|
+
promQuantile,
|
|
10
|
+
promSelector,
|
|
11
|
+
promSumRate,
|
|
12
|
+
type PromMatcher,
|
|
13
|
+
} from "@intentius/chant-lexicon-otel/metric-names";
|
|
6
14
|
import type { DatasourceInput } from "../query";
|
|
7
15
|
import type { DashboardLinkInput } from "../dashboard";
|
|
8
16
|
import type { FolderEntity } from "../folder";
|
|
@@ -27,17 +35,21 @@ export interface DashboardOptions {
|
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
/** A label matcher: `[label, op, value]`. */
|
|
30
|
-
export type Matcher =
|
|
38
|
+
export type Matcher = PromMatcher;
|
|
39
|
+
|
|
40
|
+
// The PromQL builders live in the otel lexicon's metric-names, next to the
|
|
41
|
+
// names they read, so the prometheus lexicon's RedAlerts builds the same
|
|
42
|
+
// expressions without importing grafana. Here they default the range to
|
|
43
|
+
// Grafana's `$__rate_interval`.
|
|
31
44
|
|
|
32
45
|
/** `metric{a="x", b=~"y"}`; just `metric` with no matchers. */
|
|
33
46
|
export function selector(metric: string, matchers: Matcher[]): string {
|
|
34
|
-
|
|
35
|
-
return `${metric}{${matchers.map(([l, op, v]) => `${l}${op}${JSON.stringify(v)}`).join(", ")}}`;
|
|
47
|
+
return promSelector(metric, matchers);
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
/** `sum by (labels) (rate(sel[range]))`, or `sum (...)` with no labels. */
|
|
39
51
|
export function sumRate(sel: string, by: string[], range = "$__rate_interval"): string {
|
|
40
|
-
return
|
|
52
|
+
return promSumRate(sel, by, range);
|
|
41
53
|
}
|
|
42
54
|
|
|
43
55
|
/**
|
|
@@ -47,18 +59,17 @@ export function sumRate(sel: string, by: string[], range = "$__rate_interval"):
|
|
|
47
59
|
* "No data" for a service that has had no errors.
|
|
48
60
|
*/
|
|
49
61
|
export function errorRatio(errorSel: string, allSel: string, by: string[]): string {
|
|
50
|
-
|
|
51
|
-
return `(\n${sumRate(errorSel, by)}\nor\n${all} * 0\n)\n/\n${all}`;
|
|
62
|
+
return promErrorRatio(errorSel, allSel, by, "$__rate_interval");
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
/** `histogram_quantile(q, sum by (le, labels) (rate(bucket[range])))`. */
|
|
55
66
|
export function quantile(q: number, bucketSel: string, by: string[]): string {
|
|
56
|
-
return
|
|
67
|
+
return promQuantile(q, bucketSel, by, "$__rate_interval");
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
/** A number as PromQL and Grafana thresholds write it, without float noise. */
|
|
60
71
|
export function num(n: number): string {
|
|
61
|
-
return
|
|
72
|
+
return promNumber(n);
|
|
62
73
|
}
|
|
63
74
|
|
|
64
75
|
/** `p95` for 0.95, `p99.9` for 0.999. */
|