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

Per-datasource cache and auth storage #812

Closed
alexanderzobnin opened this issue Oct 7, 2019 · 5 comments
Closed

Per-datasource cache and auth storage #812

alexanderzobnin opened this issue Oct 7, 2019 · 5 comments

Comments

@alexanderzobnin
Copy link
Collaborator

Initial work is done, but as mentioned in #808 (comment), we should store cache and auth for each particular data source, not for the package at all. So we need an object that stores information related to data source, like:

type ZabbixDatasource struct {
	plugin.NetRPCUnsupportedPlugin
	logger    hclog.Logger
	instances map[int64]ZabbixInstance
}

type ZabbixInstance struct {
	dsInfo *datasource.DatasourceInfo
	cache  *Cache
	auth   string
}

This is just an example, so maybe there's better solution.

@alecxvs
Copy link
Contributor

alecxvs commented Oct 8, 2019

I had some brief conversation with @dneth about this last week and trying to cache datasource info introduces some interesting problems. Knowing when datasources are updated so we can invalidate the cache is tricky. At least from the UI, if we always Save & Test, we can rely on the front end to send some kind of test request and invalidate the cache/instance when that happens. But I don't know if we can guarantee that always is the case.

I think ideally Grafana would give us more state, because the way the rpc plugins are arranged, it almost forces the plugins to be stateless. But that's a lot harder to change.

(That's all assuming we even store DatasourceInfo. Auth tokens are the only state we really need to cache.)

@alexanderzobnin
Copy link
Collaborator Author

Good catch! Yes, this is tricky right now. I think we can start with "Save and Test" approach: build special test query type which will handle test requests from the frontend and invalidate cache.

@alecxvs
Copy link
Contributor

alecxvs commented Oct 10, 2019

I was going to create an issue for creating a Test query type, but after thinking about it, I'm not sure we need it. Though I'm entirely speculating since I don't know the frontend code very well...

The frontend currently submits some query to test the connection. We only need to change that to run the same query on the backend. As for expiring the auth token... We probably don't need to explicitly expire it. The cache should expire after a period of time. If the login information changes, as part of the per-datasource caching, perhaps we can hash the credentials and use that to access the cache.

@alecxvs
Copy link
Contributor

alecxvs commented Oct 11, 2019

I'm working on this

@alecxvs
Copy link
Contributor

alecxvs commented Oct 18, 2019

I looked at the connection test and it doesn't simply execute a query, so I was mistaken there. Anyways, connection test implementation is included with the changes in my PR ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants