Skip to content

Commit

Permalink
Use header X-metrics-cached to incident if cached
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
  • Loading branch information
mblaschke committed May 18, 2020
1 parent 07e8cb9 commit 8a19638
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion probe_metrics_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func probeMetricsListHandler(w http.ResponseWriter, r *http.Request) {
}

if !loadedFromCache {
w.Header().Add("X-metrics-cached", "false")
for _, subscription := range settings.Subscriptions {
wg.Add()
go func(subscription string) {
Expand Down Expand Up @@ -115,10 +116,10 @@ func probeMetricsListHandler(w http.ResponseWriter, r *http.Request) {

// enable caching if enabled
if settings.Cache != nil {
w.Header().Add("X-metrics-cached", (*settings.Cache).String())
metricsList.StoreToCache(cacheKey, *settings.Cache)
}
} else {
w.Header().Add("X-metrics-cached", "true")
prometheusMetricRequests.With(prometheus.Labels{
"subscriptionID": "",
"handler": PROBE_METRICS_LIST_URL,
Expand Down
3 changes: 2 additions & 1 deletion probe_metrics_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func probeMetricsResourceHandler(w http.ResponseWriter, r *http.Request) {
}

if !loadedFromCache {
w.Header().Add("X-metrics-cached", "false")
for _, target := range settings.Target {
result, err := azureInsightMetrics.FetchMetrics(ctx, subscription, target, settings)

Expand Down Expand Up @@ -88,10 +89,10 @@ func probeMetricsResourceHandler(w http.ResponseWriter, r *http.Request) {

// enable caching if enabled
if settings.Cache != nil {
w.Header().Add("X-metrics-cached", (*settings.Cache).String())
metricsList.StoreToCache(cacheKey, *settings.Cache)
}
} else {
w.Header().Add("X-metrics-cached", "true")
prometheusMetricRequests.With(prometheus.Labels{
"subscriptionID": "",
"handler": PROBE_METRICS_RESOURCE_URL,
Expand Down
4 changes: 2 additions & 2 deletions probe_metrics_scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func probeMetricsScrapeHandler(w http.ResponseWriter, r *http.Request) {
}

if !loadedFromCache {
w.Header().Add("X-metrics-cached", "false")
for _, subscription := range settings.Subscriptions {
wg.Add()
go func(subscription string) {
Expand Down Expand Up @@ -131,17 +132,16 @@ func probeMetricsScrapeHandler(w http.ResponseWriter, r *http.Request) {

// enable caching if enabled
if settings.Cache != nil {
w.Header().Add("X-metrics-cached", (*settings.Cache).String())
metricsList.StoreToCache(cacheKey, *settings.Cache)
}
} else {
w.Header().Add("X-metrics-cached", "true")
prometheusMetricRequests.With(prometheus.Labels{
"subscriptionID": "",
"handler": PROBE_METRICS_SCRAPE_URL,
"filter": settings.Filter,
"result": "cached",
}).Inc()

}

metricsList.GaugeSet(metricGauge)
Expand Down

0 comments on commit 8a19638

Please sign in to comment.