Skip to content

Commit

Permalink
Get Grafana version from context
Browse files Browse the repository at this point in the history
  • Loading branch information
adamyeats committed Nov 23, 2023
1 parent 0e427dc commit e3e5d65
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/plugin/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"net"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -56,8 +55,10 @@ func getTLSConfig(settings Settings) (*tls.Config, error) {
return tlsConfig, nil
}

func getClientInfoProducts() (products []struct{ Name, Version string }) {
if version := os.Getenv("GF_VERSION"); version != "" {
func getClientInfoProducts(ctx context.Context) (products []struct{ Name, Version string }) {
version := backend.UserAgentFromContext(ctx).GrafanaVersion()

Check failure on line 59 in pkg/plugin/driver.go

View workflow job for this annotation

GitHub Actions / run (22.3)

undefined: backend.UserAgentFromContext

Check failure on line 59 in pkg/plugin/driver.go

View workflow job for this annotation

GitHub Actions / Build and archive plugin build artifacts

undefined: backend.UserAgentFromContext

Check failure on line 59 in pkg/plugin/driver.go

View workflow job for this annotation

GitHub Actions / run

undefined: backend.UserAgentFromContext

Check failure on line 59 in pkg/plugin/driver.go

View workflow job for this annotation

GitHub Actions / run (22.8)

undefined: backend.UserAgentFromContext

Check failure on line 59 in pkg/plugin/driver.go

View workflow job for this annotation

GitHub Actions / run (22.9)

undefined: backend.UserAgentFromContext

Check failure on line 59 in pkg/plugin/driver.go

View workflow job for this annotation

GitHub Actions / run (22.10)

undefined: backend.UserAgentFromContext

Check failure on line 59 in pkg/plugin/driver.go

View workflow job for this annotation

GitHub Actions / run (latest)

undefined: backend.UserAgentFromContext

if version != "" {
products = append(products, struct{ Name, Version string }{
Name: "grafana",
Version: version,
Expand Down Expand Up @@ -140,9 +141,13 @@ func (h *Clickhouse) Connect(config backend.DataSourceInstanceSettings, message
}
}

timeout := time.Duration(t)
ctx, cancel := context.WithTimeout(context.Background(), timeout*time.Second)
defer cancel()

opts := &clickhouse.Options{
ClientInfo: clickhouse.ClientInfo{
Products: getClientInfoProducts(),
Products: getClientInfoProducts(ctx),
},
TLS: tlsConfig,
Addr: []string{fmt.Sprintf("%s:%d", settings.Server, settings.Port)},
Expand Down Expand Up @@ -179,10 +184,6 @@ func (h *Clickhouse) Connect(config backend.DataSourceInstanceSettings, message

db := clickhouse.OpenDB(opts)

timeout := time.Duration(t)
ctx, cancel := context.WithTimeout(context.Background(), timeout*time.Second)
defer cancel()

chErr := make(chan error, 1)
go func() {
err = db.PingContext(ctx)
Expand Down

0 comments on commit e3e5d65

Please sign in to comment.