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

2.1.0 Refactoring #136

Closed
HadesArchitect opened this issue May 2, 2022 · 1 comment
Closed

2.1.0 Refactoring #136

HadesArchitect opened this issue May 2, 2022 · 1 comment
Assignees
Milestone

Comments

@HadesArchitect
Copy link
Owner

Thank you. Great work. Would still like to see some additional changes before we can publish this. Let us know if you don't agree.

Instance management:
It does works better now, but I still see that potential raise conditions could occur when initializing the session.

As I wrote earlier:

  • Since you're using the datasource instance management you should initialize and cache a field on the CassandraDatasource struct. To me it seems like the clusterconfig should be initialized and cached on CassandraDatasource struct and then you'll use that to create/open a session per request and close it at the end.

We have an example, see /~https://github.com/grafana/grafana-plugin-examples/blob/master/examples/datasource-basic/pkg/main.go#L20, which I think should simplify your code for serving the plugin and handle the Cassandra connections/sessions.

In the example it uses the NewDataSource for instantiating a new datasource instance - this is called each time a datasource in created/updated in Grafana and locking/concurrency guarantees that it only executes exactly once for every datasource created/updated in Grafana . This is the recommended location for instantiating clients and such, e.g. your clusterconfig.

Logging:

  • For example this line that logs, rather than using logger.Debug(fmt.Sprintf("Created datasource, ID: %d\n", settings.ID)) we recommend to use structured logging, e.g. logger.Debug("Created datasource", "uid", settings.UID)
  • Would recommend using lowercase keys when logging, e.g. message instead of Message, to follow Grafana's convention.
  • Inconsistent use of warning/error log levels, e.g. here warning are used and here error are used. Can you please use error level everywhere when logging an error?
  • Please use debug level here

Kind regards,
The Grafana Team

@futuarmo
Copy link
Collaborator

Fixed in #138

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