Skip to content

[7.x] [ACM] Return 200 instead of 404 for missing config. (#2458) #2462

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

Merged
merged 1 commit into from
Jul 16, 2019
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
11 changes: 6 additions & 5 deletions beater/agent_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ func agentConfigHandler(kbClient kibana.Client, config *agentConfig, secretToken
}

cfg, upstreamEtag, internalErr := fetcher.Fetch(query, nil)
etag := fmt.Sprintf("\"%s\"", upstreamEtag)
if internalErr != nil {
sendErr(http.StatusServiceUnavailable, internalErrMsg(internalErr.Error()), internalErr.Error())
return
}

etag := fmt.Sprintf("\"%s\"", upstreamEtag)
switch {
case internalErr != nil:
sendErr(http.StatusServiceUnavailable, internalErrMsg(internalErr.Error()), internalErr.Error())
case len(cfg) == 0:
logMsg := fmt.Sprintf("%s for %s", errMsgConfigNotFound, query.ID())
sendErr(http.StatusNotFound, errMsgConfigNotFound, logMsg)
sendResp(nil, http.StatusOK, cacheControl)
case upstreamEtag == "":
sendResp(cfg, http.StatusOK, cacheControl)
case etag == r.Header.Get(headers.IfNoneMatch):
Expand Down
18 changes: 8 additions & 10 deletions beater/agent_config_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ var (
respBodyToken: successBody,
},

"NoConfigFound": {
kbClient: tests.MockKibana(http.StatusNotFound, m{}, mockVersion, true),
method: http.MethodGet,
queryParams: map[string]string{"service.name": "opbeans-python"},
respStatus: http.StatusOK,
respCacheControlHeader: "max-age=4, must-revalidate",
},

"SendToKibanaFailed": {
kbClient: tests.MockKibana(http.StatusBadGateway, m{}, mockVersion, true),
method: http.MethodGet,
Expand Down Expand Up @@ -144,16 +152,6 @@ var (
" configured Kibana version {version:7.2.0 Major:7 Minor:2 Bugfix:0 Meta:}"),
},

"StatusNotFoundError": {
kbClient: tests.MockKibana(http.StatusNotFound, m{}, mockVersion, true),
method: http.MethodGet,
queryParams: map[string]string{"service.name": "opbeans-python"},
respStatus: http.StatusNotFound,
respCacheControlHeader: "max-age=300, must-revalidate",
respBody: errWrap(errMsgConfigNotFound),
respBodyToken: errWrap(fmt.Sprintf("%s for opbeans-python", errMsgConfigNotFound)),
},

"NoService": {
kbClient: tests.MockKibana(http.StatusOK, m{}, mockVersion, true),
method: http.MethodGet,
Expand Down
20 changes: 10 additions & 10 deletions tests/system/test_integration_acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def test_config_requests(self):
params={"service.name": service_name + "_cache_bust"},
headers={"Content-Type": "application/x-ndjson"},
)
assert r2.status_code == 404, r2.status_code
assert r2.status_code == 200, r2.status_code
expect_log.append({
"level": "error",
"message": "error handling request",
"error": "no configuration available for {}_cache_bust".format(service_name),
"response_code": 404,
"level": "info",
"message": "handled request",
"response_code": 200,
})
self.assertFalse(r2.content)

create_config_rsp = self.create_service_config({"sample_rate": "0.05"}, service_name)
assert create_config_rsp.status_code == 200, create_config_rsp.status_code
Expand Down Expand Up @@ -109,13 +109,13 @@ def test_config_requests(self):
"service.environment": bad_service_env,
},
headers={"Content-Type": "application/x-ndjson"})
assert r4.status_code == 404, r4.status_code
assert r4.status_code == 200, r4.status_code
expect_log.append({
"level": "error",
"message": "error handling request",
"error": "no configuration available for {}_{}".format(service_name, bad_service_env),
"response_code": 404,
"level": "info",
"message": "handled request",
"response_code": 200,
})
self.assertFalse(r4.content)

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