Skip to content

Commit 459f0c5

Browse files
authored
[ACM] Return 200 instead of 404 for missing config. (#2458) (#2463)
fixes #2457
1 parent 7cd8bdc commit 459f0c5

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

beater/agent_config_handler.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ func agentConfigHandler(kbClient kibana.Client, config *agentConfig, secretToken
7777
}
7878

7979
cfg, upstreamEtag, internalErr := fetcher.Fetch(query, nil)
80-
etag := fmt.Sprintf("\"%s\"", upstreamEtag)
80+
if internalErr != nil {
81+
sendErr(http.StatusServiceUnavailable, internalErrMsg(internalErr.Error()), internalErr.Error())
82+
return
83+
}
8184

85+
etag := fmt.Sprintf("\"%s\"", upstreamEtag)
8286
switch {
83-
case internalErr != nil:
84-
sendErr(http.StatusServiceUnavailable, internalErrMsg(internalErr.Error()), internalErr.Error())
8587
case len(cfg) == 0:
86-
logMsg := fmt.Sprintf("%s for %s", errMsgConfigNotFound, query.ID())
87-
sendErr(http.StatusNotFound, errMsgConfigNotFound, logMsg)
88+
sendResp(nil, http.StatusOK, cacheControl)
8889
case upstreamEtag == "":
8990
sendResp(cfg, http.StatusOK, cacheControl)
9091
case etag == r.Header.Get(headerIfNoneMatch):

beater/agent_config_handler_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ var (
104104
respBodyToken: successBody,
105105
},
106106

107+
"NoConfigFound": {
108+
kbClient: tests.MockKibana(http.StatusNotFound, m{}, mockVersion, true),
109+
method: http.MethodGet,
110+
queryParams: map[string]string{"service.name": "opbeans-python"},
111+
respStatus: http.StatusOK,
112+
respCacheControlHeader: "max-age=4, must-revalidate",
113+
},
114+
107115
"SendToKibanaFailed": {
108116
kbClient: tests.MockKibana(http.StatusBadGateway, m{}, mockVersion, true),
109117
method: http.MethodGet,
@@ -143,16 +151,6 @@ var (
143151
" configured Kibana version {version:7.2.0 Major:7 Minor:2 Bugfix:0 Meta:}"),
144152
},
145153

146-
"StatusNotFoundError": {
147-
kbClient: tests.MockKibana(http.StatusNotFound, m{}, mockVersion, true),
148-
method: http.MethodGet,
149-
queryParams: map[string]string{"service.name": "opbeans-python"},
150-
respStatus: http.StatusNotFound,
151-
respCacheControlHeader: "max-age=300, must-revalidate",
152-
respBody: errWrap(errMsgConfigNotFound),
153-
respBodyToken: errWrap(fmt.Sprintf("%s for opbeans-python", errMsgConfigNotFound)),
154-
},
155-
156154
"NoService": {
157155
kbClient: tests.MockKibana(http.StatusOK, m{}, mockVersion, true),
158156
method: http.MethodGet,

tests/system/test_integration_acm.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ def test_config_requests(self):
6262
params={"service.name": service_name + "_cache_bust"},
6363
headers={"Content-Type": "application/x-ndjson"},
6464
)
65-
assert r2.status_code == 404, r2.status_code
65+
assert r2.status_code == 200, r2.status_code
6666
expect_log.append({
67-
"level": "error",
68-
"message": "error handling request",
69-
"error": "no configuration available for {}_cache_bust".format(service_name),
70-
"response_code": 404,
67+
"level": "info",
68+
"message": "handled request",
69+
"response_code": 200,
7170
})
71+
self.assertFalse(r2.content)
7272

7373
create_config_rsp = self.create_service_config({"sample_rate": "0.05"}, service_name)
7474
assert create_config_rsp.status_code == 200, create_config_rsp.status_code
@@ -109,13 +109,13 @@ def test_config_requests(self):
109109
"service.environment": bad_service_env,
110110
},
111111
headers={"Content-Type": "application/x-ndjson"})
112-
assert r4.status_code == 404, r4.status_code
112+
assert r4.status_code == 200, r4.status_code
113113
expect_log.append({
114-
"level": "error",
115-
"message": "error handling request",
116-
"error": "no configuration available for {}_{}".format(service_name, bad_service_env),
117-
"response_code": 404,
114+
"level": "info",
115+
"message": "handled request",
116+
"response_code": 200,
118117
})
118+
self.assertFalse(r4.content)
119119

120120
create_config_with_env_rsp = self.create_service_config({"sample_rate": "0.15"}, service_name, env=service_env)
121121
assert create_config_with_env_rsp.status_code == 200, create_config_with_env_rsp.status_code

0 commit comments

Comments
 (0)