Skip to content

fix: correct orgId misuse, defer-after-error, and log format in datasource plugin - #33

Open
belowzeroff wants to merge 1 commit into
DataIntellectTech:masterfrom
belowzeroff:fix/logic-bugs-orgid-defer-logformat
Open

fix: correct orgId misuse, defer-after-error, and log format in datasource plugin#33
belowzeroff wants to merge 1 commit into
DataIntellectTech:masterfrom
belowzeroff:fix/logic-bugs-orgid-defer-logformat

Conversation

@belowzeroff

Copy link
Copy Markdown

Summary

Three logic bug fixes:

  1. Incorrect orgId in metricFindQueryorgId was set to this.id (datasource instance ID), which is semantically wrong. Grafana derives the org ID from the session context on the backend side, so this field was both wrong and unnecessary.

  2. defer f.Close() before error check — In getConfig(), if os.Open("../../test/testConfig.csv") fails, f is nil and defer f.Close() causes a nil pointer panic. Moved the defer after the error check.

  3. log.DefaultLogger.Error used printf-style format — Grafana SDK logger uses structured key-value pairs (key, value), not %s format strings. Changed "Error decoding query and field -%s", err.Error() to "Error decoding query and field", "error", err.Error().

Verification

  • go build ./... succeeds
  • go vet ./... shows no new warnings

…ource plugin

- Remove orgId: this.id from metricFindQuery (datasource ID != org ID;
  Grafana backend derives org from session context)
- Move defer f.Close() after error check in getConfig to avoid panic
  on nil *os.File when testConfig.csv is missing
- Fix log.DefaultLogger.Error call: Grafana SDK uses structured
  key-value pairs, not printf-style formatting
@belowzeroff
belowzeroff force-pushed the fix/logic-bugs-orgid-defer-logformat branch from e2014af to 9e3beb8 Compare July 23, 2026 10:54
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.

1 participant