Skip to content

Commit

Permalink
Add datasource label to secure_socks_requests_duration
Browse files Browse the repository at this point in the history
  • Loading branch information
PoorlyDefinedBehaviour committed Jan 19, 2024
1 parent 7250ba5 commit 5ebee79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
11 changes: 7 additions & 4 deletions backend/proxy/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import "time"

// Options defines per datasource options for creating the proxy dialer.
type Options struct {
Enabled bool
Auth *AuthOptions
Timeouts *TimeoutOptions
ClientCfg *ClientCfg
Enabled bool
// The type of the datasource the proxy will be used to communicate with.
// It should be the value assigned to the type property in a datasource provisioning file (e.g mysql, prometheus)
DatasourceType string
Auth *AuthOptions
Timeouts *TimeoutOptions
ClientCfg *ClientCfg
}

// AuthOptions socks5 username and password options.
Expand Down
16 changes: 10 additions & 6 deletions backend/proxy/secure_socks_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var (
Namespace: "grafana",
Name: "secure_socks_requests_duration",
Help: "Duration of requests to the secure socks proxy",
}, []string{"code"})
}, []string{"code", "datasource"})
)

// Client is the main Proxy Client interface.
Expand Down Expand Up @@ -152,7 +152,7 @@ func (p *cfgProxyWrapper) NewSecureSocksProxyContextDialer() (proxy.Dialer, erro
return nil, err
}

return newInstrumentedSocksDialer(dialSocksProxy), nil
return newInstrumentedSocksDialer(dialSocksProxy, p.opts.DatasourceType), nil
}

func (p *cfgProxyWrapper) getTLSDialer() (*tls.Dialer, error) {
Expand Down Expand Up @@ -280,13 +280,17 @@ func SecureSocksProxyEnabledOnDS(jsonData map[string]interface{}) bool {
// instrumentedSocksDialer is a wrapper around the proxy.Dialer and proxy.DialContext
// that records relevant socks secure socks proxy.
type instrumentedSocksDialer struct {
dialer proxy.Dialer
// The type of the datasourceType the proxy will be used to communicate with.
// It should be the value assigned to the type property in a datasourceType provisioning file (e.g mysql, prometheus)
datasourceType string
dialer proxy.Dialer
}

// newInstrumentedSocksDialer creates a new instrumented dialer
func newInstrumentedSocksDialer(dialer proxy.Dialer) proxy.Dialer {
func newInstrumentedSocksDialer(dialer proxy.Dialer, datasource string) proxy.Dialer {
return &instrumentedSocksDialer{
dialer: dialer,
dialer: dialer,
datasourceType: datasource,
}
}

Expand Down Expand Up @@ -348,6 +352,6 @@ func (d *instrumentedSocksDialer) DialContext(ctx context.Context, n, addr strin
code = "dial_error"
}

secureSocksRequestsDuration.WithLabelValues(code).Observe(time.Since(start).Seconds())
secureSocksRequestsDuration.WithLabelValues(code, d.datasourceType).Observe(time.Since(start).Seconds())
return c, err
}

0 comments on commit 5ebee79

Please sign in to comment.