From b6619bbac1d93918aa4e3ba9b2a4efa37bdec8d8 Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Mon, 10 May 2021 20:18:38 +0200 Subject: [PATCH] remove cache headers due to race condition Signed-off-by: Markus Blaschke --- azure_insights.go | 4 +--- probe_metrics_list.go | 2 +- probe_metrics_scrape.go | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/azure_insights.go b/azure_insights.go index cdfe10f..3748475 100644 --- a/azure_insights.go +++ b/azure_insights.go @@ -99,7 +99,7 @@ func (m *AzureInsightMetrics) azureResponseInsepector(subscriptionId string) aut } } -func (m *AzureInsightMetrics) ListResources(ctx context.Context, logger *log.Entry, subscriptionId, filter string, w http.ResponseWriter) ([]AzureResource, error) { +func (m *AzureInsightMetrics) ListResources(ctx context.Context, logger *log.Entry, subscriptionId, filter string) ([]AzureResource, error) { var cacheDuration *time.Duration cacheKey := "" @@ -118,7 +118,6 @@ func (m *AzureInsightMetrics) ListResources(ctx context.Context, logger *log.Ent if cacheData, ok := v.([]byte); ok { if err := json.Unmarshal(cacheData, &resourceList); err == nil { logger.Debug("fetched servicediscovery from cache") - w.Header().Add("X-servicediscovery-cached", "true") return resourceList, nil } else { logger.Debug("unable to parse cached servicediscovery") @@ -152,7 +151,6 @@ func (m *AzureInsightMetrics) ListResources(ctx context.Context, logger *log.Ent if cacheDuration != nil { logger.Debug("saving servicedisccovery to cache") if cacheData, err := json.Marshal(resourceList); err == nil { - w.Header().Add("X-servicediscovery-cached-until", time.Now().Add(*cacheDuration).Format(time.RFC3339)) azureCache.Set(cacheKey, cacheData, *cacheDuration) logger.Debugf("saved servicediscovery to cache for %s", cacheDuration.String()) } diff --git a/probe_metrics_list.go b/probe_metrics_list.go index 8a828ec..2cfdc74 100644 --- a/probe_metrics_list.go +++ b/probe_metrics_list.go @@ -62,7 +62,7 @@ func probeMetricsListHandler(w http.ResponseWriter, r *http.Request) { wgResource := sizedwaitgroup.New(opts.Prober.ConcurrencySubscriptionResource) // fetch list of resources - list, err := azureInsightMetrics.ListResources(ctx, contextLogger, subscription, settings.Filter, w) + list, err := azureInsightMetrics.ListResources(ctx, contextLogger, subscription, settings.Filter) if err != nil { contextLogger.Errorln(err) http.Error(w, err.Error(), http.StatusBadRequest) diff --git a/probe_metrics_scrape.go b/probe_metrics_scrape.go index 6983892..5716ed3 100644 --- a/probe_metrics_scrape.go +++ b/probe_metrics_scrape.go @@ -75,7 +75,7 @@ func probeMetricsScrapeHandler(w http.ResponseWriter, r *http.Request) { defer wg.Done() wgResource := sizedwaitgroup.New(opts.Prober.ConcurrencySubscriptionResource) - list, err := azureInsightMetrics.ListResources(ctx, contextLogger, subscription, settings.Filter, w) + list, err := azureInsightMetrics.ListResources(ctx, contextLogger, subscription, settings.Filter) if err != nil { contextLogger.Errorln(err) http.Error(w, err.Error(), http.StatusBadRequest)