-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecordingRules.ts
60 lines (55 loc) · 2.7 KB
/
recordingRules.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { latencyQuery, throughputQuery, writeYaml, recordingPrometheusRule, prometheusRuleFor, ranges, percentiles, yamlStringify, EXTENDED_SCHEMA } from "./recording.ts"
export const apps = [
"abcService",
"defService",
"xyzService",
]
export const latencyQueries = [
latencyQuery({
name: "http",
expr: (percentile, app, window) =>
`histogram_quantile(0.${percentile}, sum(rate(http_server_requests_seconds_bucket{job="${app}", uri!~".*/(test|admin|internal|\\*\\*).*|root"}[${window}])) by (le, job, service, uri, method, status))`,
}),
latencyQuery({
name: "http_by_method",
expr: (percentile, app, window) =>
`histogram_quantile(0.${percentile}, sum(rate(http_server_requests_seconds_bucket{job="${app}", uri!~".*/(test|admin|internal|\\*\\*).*|root"}[${window}])) by (le, job, service, method))`,
}),
latencyQuery({
name: "http_total",
expr: (percentile, app, window) =>
`histogram_quantile(0.${percentile}, sum(rate(http_server_requests_seconds_bucket{job="${app}", uri!~".*/(test|admin|internal|\\*\\*).*|root"}[${window}])) by (le, job, service))`,
}),
latencyQuery({
name: "resilience4j",
expr: (percentile, app, window) =>
`histogram_quantile(0.${percentile}, sum(rate(resilience4j_circuitbreaker_calls_seconds_bucket{job="${app}", }[${window}])) by (le, job, service, name))`,
}),
]
export const throughputQueries = [
throughputQuery({
name: "http",
expr: (_percentile, app, window) =>
`sum(rate(http_server_requests_seconds_count{job="${app}", uri!~".*/(test|admin|internal|\\*\\*).*|root"}[${window}])) by (job, service, uri, method, status)`,
}),
throughputQuery({
name: "logging",
expr: (_percentile, app, window) =>
`sum(rate(logging_all_events_total{job="${app}", appender="general_log_statistics"}[${window}])) by (job, service, level, scope)`,
}),
throughputQuery({
name: "resilience4j",
expr: (_percentile, app, window) =>
`sum(rate(resilience4j_circuitbreaker_calls_seconds_count{job="${app}", }[${window}])) by (job, service, kind, name)`,
}),
]
writeYaml("./latencyRecording.yaml", recordingPrometheusRule("checkout", "latency", latencyQueries, ranges, percentiles, apps))
writeYaml("./throughputRecording.yaml", recordingPrometheusRule("checkout", "throughput", throughputQueries, ranges, percentiles, apps))
const validRule = prometheusRuleFor("latency", latencyQueries, ranges, percentiles, apps)
const preamble = `
# yaml-language-server: $schema=https://json.schemastore.org/prometheus.rules.json
`
const validYaml = yamlStringify(validRule, {schema: EXTENDED_SCHEMA})
const fileName = "./validRule.yaml"
await Deno.writeTextFile(fileName, preamble + validYaml)
console.log(`${fileName} written`)