@@ -44,15 +44,17 @@ type prometheusResponse struct {
44
44
45
45
// Handler interacts with a prometheus API endpoint
46
46
type Handler struct {
47
- ApiURL string
48
- Username string
49
- Password string
50
- Project string
51
- Stage string
52
- Service string
53
- HTTPClient * http.Client
54
- CustomFilters []* keptnv2.SLIFilter
55
- CustomQueries map [string ]string
47
+ ApiURL string
48
+ Username string
49
+ Password string
50
+ Project string
51
+ Stage string
52
+ Service string
53
+ DeploymentType string
54
+ Labels map [string ]string
55
+ HTTPClient * http.Client
56
+ CustomFilters []* keptnv2.SLIFilter
57
+ CustomQueries map [string ]string
56
58
}
57
59
58
60
const alertManagerYml = `global:
@@ -162,14 +164,16 @@ func (p *PrometheusHelper) UpdateAMConfigMap(name string, filename string, names
162
164
}
163
165
164
166
// NewPrometheusHandler returns a new prometheus handler that interacts with the Prometheus REST API
165
- func NewPrometheusHandler (apiURL string , eventData * keptnv2.EventData , customFilters []* keptnv2.SLIFilter ) * Handler {
167
+ func NewPrometheusHandler (apiURL string , eventData * keptnv2.EventData , deploymentType string , labels map [ string ] string , customFilters []* keptnv2.SLIFilter ) * Handler {
166
168
ph := & Handler {
167
- ApiURL : apiURL ,
168
- Project : eventData .Project ,
169
- Stage : eventData .Stage ,
170
- Service : eventData .Service ,
171
- HTTPClient : & http.Client {},
172
- CustomFilters : customFilters ,
169
+ ApiURL : apiURL ,
170
+ Project : eventData .Project ,
171
+ Stage : eventData .Stage ,
172
+ Service : eventData .Service ,
173
+ DeploymentType : deploymentType ,
174
+ Labels : labels ,
175
+ HTTPClient : & http.Client {},
176
+ CustomFilters : customFilters ,
173
177
}
174
178
175
179
return ph
@@ -265,9 +269,14 @@ func (ph *Handler) replaceQueryParameters(query string, start time.Time, end tim
265
269
query = strings .Replace (query , "$PROJECT" , ph .Project , - 1 )
266
270
query = strings .Replace (query , "$STAGE" , ph .Stage , - 1 )
267
271
query = strings .Replace (query , "$SERVICE" , ph .Service , - 1 )
268
- query = strings .Replace (query , "$project" , ph .Project , - 1 )
269
- query = strings .Replace (query , "$stage" , ph .Stage , - 1 )
270
- query = strings .Replace (query , "$service" , ph .Service , - 1 )
272
+ query = strings .Replace (query , "$DEPLOYMENT" , ph .DeploymentType , - 1 )
273
+
274
+ // replace labels
275
+ for key , value := range ph .Labels {
276
+ query = strings .Replace (query , "$LABEL." + key , value , - 1 )
277
+ }
278
+
279
+ // replace duration
271
280
durationString := strconv .FormatInt (getDurationInSeconds (start , end ), 10 ) + "s"
272
281
273
282
query = strings .Replace (query , "$DURATION_SECONDS" , durationString , - 1 )
0 commit comments