1
- const COUNTER_NAME = "function_calls_count" ;
2
- const HISTOGRAM_BUCKET_NAME = "function_calls_duration_bucket" ;
3
-
4
- const ADD_BUILD_INFO_LABELS =
5
- "* on (instance, job) group_left(version, commit) last_over_time(build_info[1s])" ;
1
+ const COUNTER_NAME = "function_calls(_count)?(_total)?" ;
6
2
7
3
export function getRequestRate (
8
4
functionName : string ,
@@ -19,36 +15,21 @@ export function getCalledByRequestRate(functionName: string) {
19
15
${ getSumQuery ( COUNTER_NAME , { caller : functionName } ) } `;
20
16
}
21
17
22
- export function getErrorRatio ( functionName : string ) {
23
- return `# Percentage of calls to the \`${ functionName } \` function that return errors, averaged over 5 minute windows
24
-
25
- ${ getSumQuery ( COUNTER_NAME , { function : functionName , result : "error" } ) } /
26
- ${ getSumQuery ( COUNTER_NAME , { function : functionName } ) } `;
27
- }
28
-
29
18
export function getCalledByErrorRatio ( functionName : string ) {
30
19
return `# Percentage of calls to functions called by \`${ functionName } \` that return errors, averaged over 5 minute windows
31
20
32
21
${ getSumQuery ( COUNTER_NAME , { caller : functionName , result : "error" } ) } /
33
22
${ getSumQuery ( COUNTER_NAME , { caller : functionName } ) } `;
34
23
}
35
24
36
- export function getLatency ( functionName : string ) {
37
- const latency = `sum by (le, function, module, commit, version) (rate(${ HISTOGRAM_BUCKET_NAME } {function="${ functionName } "}[5m]) ${ ADD_BUILD_INFO_LABELS } )` ;
38
-
39
- return `# 95th and 99th percentile latencies for the \`${ functionName } \` function
40
-
41
- label_replace(histogram_quantile(0.99, ${ latency } ), "percentile_latency", "99", "", "") or
42
- label_replace(histogram_quantile(0.95, ${ latency } ), "percentile_latency", "95", "", "")` ;
43
- }
44
-
45
25
export function getSumQuery (
46
26
metricName : string ,
47
27
labels : Record < string , string > = { } ,
48
28
) {
49
29
return `sum by (function, module) (
50
30
rate(
51
- ${ metricName } {
31
+ {
32
+ __name__=~"${ metricName } ",
52
33
${ Object . entries ( labels )
53
34
. map (
54
35
( [ key , value ] ) => ` ${ key } ="${ value } "
@@ -65,7 +46,7 @@ export function generateRequestRateQuery(
65
46
return `sum by (function, module, version, commit) (
66
47
rate(
67
48
{
68
- __name__=~"function_calls_count(?: _total)?",
49
+ __name__=~"function_calls(_count)?( _total)?",
69
50
function=~"${ functionName } ",
70
51
module=~"${ moduleName || ".*" } "
71
52
}[5m]
@@ -86,7 +67,7 @@ export function generateErrorRatioQuery(
86
67
sum by(function, module, version, commit) (
87
68
rate(
88
69
{
89
- __name__=~"function_calls_count(?: _total)?",
70
+ __name__=~"function_calls(_count)?( _total)?",
90
71
result="error",
91
72
function=~"${ functionName } ",
92
73
module=~"${ moduleName || ".*" } "
@@ -102,7 +83,7 @@ export function generateErrorRatioQuery(
102
83
sum by(function, module, version, commit) (
103
84
rate(
104
85
{
105
- __name__=~"function_calls_count(?: _total)?",
86
+ __name__=~"function_calls(_count)?( _total)?",
106
87
function=~"${ functionName } ",
107
88
module=~"${ moduleName || ".*" } "
108
89
}[5m]
@@ -125,14 +106,15 @@ export function generateLatencyQuery(
125
106
0.99,
126
107
sum by (le, function, module, commit, version) (
127
108
rate(
128
- function_calls_duration_bucket{
109
+ {
110
+ __name__=~"function_calls_duration(_seconds)?_bucket",
129
111
function=~"${ functionName } ",
130
112
module=~"${ moduleName || ".*" } "
131
113
}[5m]
132
114
)
133
115
# Attach the "version" and "commit" labels from the "build_info" metric
134
116
* on (instance, job) group_left(version, commit) (
135
- last_over_time(build_info[1s])
117
+ last_over_time(build_info[1s]) or on (instance, job) up
136
118
)
137
119
)
138
120
),
@@ -146,14 +128,15 @@ export function generateLatencyQuery(
146
128
0.95,
147
129
sum by (le, function, module, commit, version) (
148
130
rate(
149
- function_calls_duration_bucket{
131
+ {
132
+ __name__=~"function_calls_duration(_seconds)?_bucket",
150
133
function=~"${ functionName } ",
151
134
module=~"${ moduleName || ".*" } "
152
135
}[5m]
153
136
)
154
137
# Attach the "version" and "commit" labels from the "build_info" metric
155
138
* on (instance, job) group_left(version, commit) (
156
- last_over_time(build_info[1s])
139
+ last_over_time(build_info[1s]) or on (instance, job) up
157
140
)
158
141
)
159
142
),
0 commit comments