Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't use dashboard cache if url is different #841

Merged
merged 5 commits into from Nov 21, 2022

Conversation

weisdd
Copy link
Collaborator

@weisdd weisdd commented Oct 24, 2022

Description

Currently, dashboard cache is still being used even if URL changes. The PR addresses that.

Other changes:

  • fix: lift restriction on having both url and grafanacom defined. Since there's a fallback mechanism in place that handles such case, there's not much sense in having the restriction;
  • chore: for code simplification, moved from *metav1.Duration to metav1.Duration where the former was not really needed (GrafanaDashboardStatus, GrafanaSpec);
  • fix: for unknown reasons, NewDashboardPipeline would fallback to 24h instead of 0(=infinity) if dashboard.Spec.ContentCacheDuration is not defined. Removed that;
  • chore: moved cache extraction from obtainJson() to loadDashboardFromURL(). - I think that location makes more sense.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • This change requires a documentation update
  • I have added tests that prove my fix is effective or that my feature works
  • I have added a test case that will be used to verify my changes
  • Verified independently on a cluster by reviewer

Verification steps

PR

I think tests should already offer a comprehensive picture.

Extra notes

Ideally, we should have an automated e2e-test for testing the caching mechanism. For now, something like this would work:

  1. Save a dashboard to a local disk;
  2. Start caddy:
caddy file-server --listen :2015 --access-log
  1. Reference the dashboard with your IP:
apiVersion: integreatly.org/v1alpha1
kind: GrafanaDashboard
metadata:
  name: grafana-dashboard-from-url
  labels:
    app.kubernetes.io/instance: grafana-operator
spec:
  url: http://192.168.64.1:2015/victoriametrics-cluster_rev2.json

Depending on the settings, you should start seeing records in the access log.

Options:

  • contentCacheDuration: 20s in GrafanaDashboard spec;
  • dashboardContentCacheDuration: 1m in Grafana spec;
  • And no updates at all if URL is the same and the timer is not set anywhere.

weisdd and others added 5 commits October 23, 2022 23:02
…a dashboard spec

There's a fallback logic in (r *DashboardPipelineImpl) obtainJson() that allows a user to have multiple sources for configuration with falling back to the next one in case of an error. For unknown reasons, having both url and grafanacom in spec was not allowed. This restriction should be lifted.
…ixes

- for code simplification, moved from &metav1.Duration to metav1.Duration where the former was not really needed (GrafanaDashboardStatus, GrafanaSpec);
- fix: for unknown reasons, NewDashboardPipeline would fallback to 24h instead of 0(=infinity) if dashboard.Spec.ContentCacheDuration is not defined. Removed that;
- moved cache extraction from obtainJson() to loadDashboardFromURL(). - I think that location makes more sense;
- fix: don’t use dashboard cache if url is different.
@NissesSenap
Copy link
Collaborator

I think this looks good but I would love a second par of eyes from ether @pb82 or @HubertStefanski

Copy link
Collaborator

@pb82 pb82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a different URL will result in an empty result from the cache leading to a re-fetch of the content.

@NissesSenap NissesSenap merged commit 50db234 into grafana:master Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants