Skip to content

Commit

Permalink
Mark err as downstream if its from the secure socks proxy (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwysiu authored Nov 7, 2024
1 parent 0cf8fda commit ff8e414
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backend/proxy/secure_socks_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana-plugin-sdk-go/experimental/status"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"golang.org/x/net/proxy"
Expand Down Expand Up @@ -334,6 +335,9 @@ func (d *instrumentedSocksDialer) DialContext(ctx context.Context, n, addr strin
log.DefaultLogger.Error("received err from dialer", "network", n, "addr", addr, "err", err)
code = "dial_error"
}
if err != nil {
err = status.DownstreamError(err)
}

secureSocksRequestsDuration.WithLabelValues(code, d.datasourceName, d.datasourceType).Observe(time.Since(start).Seconds())
return c, err
Expand Down
2 changes: 1 addition & 1 deletion backend/proxy/secure_socks_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func TestInstrumentedSocksDialer(t *testing.T) {
c, err := cd.DialContext(context.Background(), "n", "addr")
assert.Nil(t, c)
assert.NotNil(t, err)
assert.Equal(t, "custom error", err.Error())
assert.Equal(t, "downstream error: custom error", err.Error())
})
}

Expand Down

0 comments on commit ff8e414

Please sign in to comment.