Skip to content

Commit 2fbf4c5

Browse files
authored
chore: backend config response size metric (#4309)
1 parent ac2e155 commit 2fbf4c5

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

backend-config/backend_config_test.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,18 @@ func TestBadResponse(t *testing.T) {
113113

114114
configs := map[string]workspaceConfig{
115115
"namespace": &namespaceConfig{
116-
configBackendURL: parsedURL,
117-
namespace: "some-namespace",
118-
client: http.DefaultClient,
119-
logger: logger.NOP,
120-
httpCallsStat: stats.NOP.NewStat("backend_config_http_calls", stats.CountType),
116+
configBackendURL: parsedURL,
117+
namespace: "some-namespace",
118+
client: http.DefaultClient,
119+
logger: logger.NOP,
120+
httpCallsStat: stats.NOP.NewStat("backend_config_http_calls", stats.CountType),
121+
httpResponseSizeStat: stats.NOP.NewStat("backend_config_http_response_size", stats.HistogramType),
121122
},
122123
"single-workspace": &singleWorkspaceConfig{
123-
configBackendURL: parsedURL,
124-
logger: logger.NOP,
125-
httpCallsStat: stats.NOP.NewStat("backend_config_http_calls", stats.CountType),
124+
configBackendURL: parsedURL,
125+
logger: logger.NOP,
126+
httpCallsStat: stats.NOP.NewStat("backend_config_http_calls", stats.CountType),
127+
httpResponseSizeStat: stats.NOP.NewStat("backend_config_http_response_size", stats.HistogramType),
126128
},
127129
}
128130
disableCache()

backend-config/namespace_config.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ type namespaceConfig struct {
4444
lastUpdatedAt time.Time
4545
workspacesConfig map[string]ConfigT
4646

47-
httpCallsStat stats.Counter
47+
httpCallsStat stats.Counter
48+
httpResponseSizeStat stats.Histogram
4849
}
4950

5051
func (nc *namespaceConfig) SetUp() (err error) {
@@ -77,6 +78,7 @@ func (nc *namespaceConfig) SetUp() (err error) {
7778
}
7879
nc.workspacesConfig = make(map[string]ConfigT)
7980
nc.httpCallsStat = stats.Default.NewStat("backend_config_http_calls", stats.CountType)
81+
nc.httpResponseSizeStat = stats.Default.NewStat("backend_config_http_response_size", stats.HistogramType)
8082

8183
if nc.logger == nil {
8284
nc.logger = logger.NewLogger().Child("backend-config").Withn(obskit.Namespace(nc.namespace))
@@ -210,6 +212,8 @@ func (nc *namespaceConfig) makeHTTPRequest(req *http.Request) ([]byte, error) {
210212
return nil, err
211213
}
212214

215+
nc.httpResponseSizeStat.Observe(float64(len(respBody)))
216+
213217
if resp.StatusCode >= 300 {
214218
return nil, getNotOKError(respBody, resp.StatusCode)
215219
}

backend-config/single_workspace.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ type singleWorkspaceConfig struct {
3131
workspaceIDOnce sync.Once
3232
workspaceID string
3333

34-
logger logger.Logger
35-
httpCallsStat stats.Counter
34+
logger logger.Logger
35+
httpCallsStat stats.Counter
36+
httpResponseSizeStat stats.Histogram
3637
}
3738

3839
func (wc *singleWorkspaceConfig) SetUp() error {
3940
wc.httpCallsStat = stats.Default.NewStat("backend_config_http_calls", stats.CountType)
41+
wc.httpResponseSizeStat = stats.Default.NewStat("backend_config_http_response_size", stats.HistogramType)
4042

4143
if wc.logger == nil {
4244
wc.logger = logger.NewLogger().Child("backend-config").Withn(obskit.WorkspaceID(wc.workspaceID))
@@ -182,6 +184,8 @@ func (wc *singleWorkspaceConfig) makeHTTPRequest(ctx context.Context, url string
182184
return nil, err
183185
}
184186

187+
wc.httpResponseSizeStat.Observe(float64(len(respBody)))
188+
185189
if resp.StatusCode >= 300 {
186190
return nil, getNotOKError(respBody, resp.StatusCode)
187191
}

0 commit comments

Comments
 (0)