Skip to content

Commit

Permalink
remove cache headers due to race condition
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 10, 2021
1 parent e4efdcd commit b6619bb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions azure_insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""

Expand All @@ -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")
Expand Down Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion probe_metrics_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion probe_metrics_scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b6619bb

Please sign in to comment.