@@ -11,33 +11,27 @@ function (_) {
11
11
}
12
12
13
13
PrometheusMetricFindQuery . prototype . process = function ( ) {
14
- var labelValuesRegex = / ^ l a b e l _ v a l u e s \( (?: ( .+ ) , \s * ) ? ( [ a - z A - Z _ ] [ a - z A - Z 0 - 9 _ ] + ) \) $ / ;
15
- var metricNamesRegex = / ^ m e t r i c s \( ( .+ ) \) $ / ;
16
- var labelsRegex = / ^ l a b e l s \( ( .+ ) \) $ / ;
17
- var queryResultRegex = / ^ q u e r y _ r e s u l t \( ( .+ ) \) $ / ;
18
-
19
- var labelsQuery = this . query . match ( labelsRegex ) ;
20
- if ( labelsQuery ) {
21
- return this . labelsQuery ( labelsQuery [ 1 ] ) ;
22
- }
23
-
24
- var labelValuesQuery = this . query . match ( labelValuesRegex ) ;
25
- if ( labelValuesQuery ) {
26
- if ( labelValuesQuery [ 1 ] ) {
27
- return this . labelValuesQuery ( labelValuesQuery [ 2 ] , labelValuesQuery [ 1 ] ) ;
14
+ var label_values_regex = / ^ l a b e l _ v a l u e s \( (?: ( .+ ) , \s * ) ? ( [ a - z A - Z _ ] [ a - z A - Z 0 - 9 _ ] + ) \) $ / ;
15
+ var metric_names_regex = / ^ m e t r i c s \( ( .+ ) \) $ / ;
16
+ var query_result_regex = / ^ q u e r y _ r e s u l t \( ( .+ ) \) $ / ;
17
+
18
+ var label_values_query = this . query . match ( label_values_regex ) ;
19
+ if ( label_values_query ) {
20
+ if ( label_values_query [ 1 ] ) {
21
+ return this . labelValuesQuery ( label_values_query [ 2 ] , label_values_query [ 1 ] ) ;
28
22
} else {
29
- return this . labelValuesQuery ( labelValuesQuery [ 2 ] , null ) ;
23
+ return this . labelValuesQuery ( label_values_query [ 2 ] , null ) ;
30
24
}
31
25
}
32
26
33
- var metricNamesQuery = this . query . match ( metricNamesRegex ) ;
34
- if ( metricNamesQuery ) {
35
- return this . metricNameQuery ( metricNamesQuery [ 1 ] ) ;
27
+ var metric_names_query = this . query . match ( metric_names_regex ) ;
28
+ if ( metric_names_query ) {
29
+ return this . metricNameQuery ( metric_names_query [ 1 ] ) ;
36
30
}
37
31
38
- var queryResultQuery = this . query . match ( queryResultRegex ) ;
39
- if ( queryResultQuery ) {
40
- return this . queryResultQuery ( queryResultQuery [ 1 ] ) ;
32
+ var query_result_query = this . query . match ( query_result_regex ) ;
33
+ if ( query_result_query ) {
34
+ return this . queryResultQuery ( query_result_query [ 1 ] ) ;
41
35
}
42
36
43
37
// if query contains full metric name, return metric name and label list
@@ -73,71 +67,45 @@ function (_) {
73
67
}
74
68
} ;
75
69
76
- PrometheusMetricFindQuery . prototype . labelsQuery = function ( metric ) {
77
- var url ;
78
-
79
- url = '/api/v1/series?match[]=' + encodeURIComponent ( metric )
80
- + '&start=' + ( this . range . from . valueOf ( ) / 1000 )
81
- + '&end=' + ( this . range . to . valueOf ( ) / 1000 ) ;
82
-
83
- return this . datasource . _request ( 'GET' , url )
84
- . then ( function ( result ) {
85
- var tags = { } ;
86
- _ . each ( result . data . data , function ( metric ) {
87
- _ . each ( metric , function ( value , key ) {
88
- if ( key === "__name__" ) {
89
- return ;
90
- }
91
-
92
- tags [ key ] = key ;
93
- } ) ;
94
- } ) ;
95
-
96
- return _ . map ( tags , function ( value ) {
97
- return { text : value , value : value } ;
98
- } ) ;
99
- } ) ;
100
- } ;
101
-
102
70
PrometheusMetricFindQuery . prototype . metricNameQuery = function ( metricFilterPattern ) {
103
71
var url = '/api/v1/label/__name__/values' ;
104
72
105
73
return this . datasource . _request ( 'GET' , url )
106
- . then ( function ( result ) {
107
- return _ . chain ( result . data . data )
108
- . filter ( function ( metricName ) {
109
- var r = new RegExp ( metricFilterPattern ) ;
110
- return r . test ( metricName ) ;
111
- } )
112
- . map ( function ( matchedMetricName ) {
113
- return {
114
- text : matchedMetricName ,
115
- expandable : true
116
- } ;
117
- } )
118
- . value ( ) ;
119
- } ) ;
74
+ . then ( function ( result ) {
75
+ return _ . chain ( result . data . data )
76
+ . filter ( function ( metricName ) {
77
+ var r = new RegExp ( metricFilterPattern ) ;
78
+ return r . test ( metricName ) ;
79
+ } )
80
+ . map ( function ( matchedMetricName ) {
81
+ return {
82
+ text : matchedMetricName ,
83
+ expandable : true
84
+ } ;
85
+ } )
86
+ . value ( ) ;
87
+ } ) ;
120
88
} ;
121
89
122
90
PrometheusMetricFindQuery . prototype . queryResultQuery = function ( query ) {
123
91
var url = '/api/v1/query?query=' + encodeURIComponent ( query ) + '&time=' + ( this . range . to . valueOf ( ) / 1000 ) ;
124
92
125
93
return this . datasource . _request ( 'GET' , url )
126
- . then ( function ( result ) {
127
- return _ . map ( result . data . data . result , function ( metricData ) {
128
- var text = metricData . metric . __name__ || '' ;
129
- delete metricData . metric . __name__ ;
130
- text += '{' +
131
- _ . map ( metricData . metric , function ( v , k ) { return k + '="' + v + '"' ; } ) . join ( ',' ) +
132
- '}' ;
133
- text += ' ' + metricData . value [ 1 ] + ' ' + metricData . value [ 0 ] * 1000 ;
134
-
135
- return {
136
- text : text ,
137
- expandable : true
138
- } ;
139
- } ) ;
94
+ . then ( function ( result ) {
95
+ return _ . map ( result . data . data . result , function ( metricData ) {
96
+ var text = metricData . metric . __name__ || '' ;
97
+ delete metricData . metric . __name__ ;
98
+ text += '{' +
99
+ _ . map ( metricData . metric , function ( v , k ) { return k + '="' + v + '"' ; } ) . join ( ',' ) +
100
+ '}' ;
101
+ text += ' ' + metricData . value [ 1 ] + ' ' + metricData . value [ 0 ] * 1000 ;
102
+
103
+ return {
104
+ text : text ,
105
+ expandable : true
106
+ } ;
140
107
} ) ;
108
+ } ) ;
141
109
} ;
142
110
143
111
PrometheusMetricFindQuery . prototype . metricNameAndLabelsQuery = function ( query ) {
@@ -147,14 +115,14 @@ function (_) {
147
115
148
116
var self = this ;
149
117
return this . datasource . _request ( 'GET' , url )
150
- . then ( function ( result ) {
151
- return _ . map ( result . data . data , function ( metric ) {
152
- return {
153
- text : self . datasource . getOriginalMetricName ( metric ) ,
154
- expandable : true
155
- } ;
156
- } ) ;
118
+ . then ( function ( result ) {
119
+ return _ . map ( result . data . data , function ( metric ) {
120
+ return {
121
+ text : self . datasource . getOriginalMetricName ( metric ) ,
122
+ expandable : true
123
+ } ;
157
124
} ) ;
125
+ } ) ;
158
126
} ;
159
127
160
128
return PrometheusMetricFindQuery ;
0 commit comments