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

Add datasource label to secure_socks_requests_duration #866

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions backend/proxy/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ 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
// DatasourceName is the name of the datasource the proxy will be used to communicate with.
DatasourceName string
// DatasourceType is 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
19 changes: 13 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", "datasource_type"})
)

// 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.DatasourceName, p.opts.DatasourceType), nil
}

func (p *cfgProxyWrapper) getTLSDialer() (*tls.Dialer, error) {
Expand Down Expand Up @@ -280,13 +280,20 @@ 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
// datasourceName is the name of the datasource the proxy will be used to communicate with.
datasourceName string
// datasourceType is 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, datasourceName, datasourceType string) proxy.Dialer {
return &instrumentedSocksDialer{
dialer: dialer,
dialer: dialer,
datasourceName: datasourceName,
datasourceType: datasourceType,
}
}

Expand Down Expand Up @@ -348,6 +355,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.datasourceName, d.datasourceType).Observe(time.Since(start).Seconds())
return c, err
}