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

[7.x] Clarify error message when unauthorized Kibana connection (#3753) #3764

Merged
merged 1 commit into from
May 11, 2020
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
6 changes: 3 additions & 3 deletions agentcfg/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import (

// Error Messages used to signal fetching errors
const (
ErrMsgSendToKibanaFailed = "sending request to kibana failed"
ErrMsgReadKibanaResponse = "unable to read Kibana response body"

ErrMsgSendToKibanaFailed = "sending request to kibana failed"
ErrMsgReadKibanaResponse = "unable to read Kibana response body"
ErrUnauthorized = "Unauthorized"
TransactionSamplingRateKey = "transaction_sample_rate"
)

Expand Down
7 changes: 7 additions & 0 deletions beater/api/config/agent/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ func extractInternalError(c *request.Context, err error, withAuth bool) {
body = authErrMsg(msg, agentcfg.ErrMsgReadKibanaResponse, withAuth)
keyword = agentcfg.ErrMsgReadKibanaResponse

case strings.Contains(msg, agentcfg.ErrUnauthorized):
fullMsg := "APM Server is not authorized to query Kibana. " +
"Please configure apm-server.kibana.username and apm-server.kibana.password, " +
"and ensure the user has the necessary privileges."
body = authErrMsg(fullMsg, agentcfg.ErrUnauthorized, withAuth)
keyword = agentcfg.ErrUnauthorized

default:
body = authErrMsg(msg, msgServiceUnavailable, withAuth)
keyword = msgServiceUnavailable
Expand Down
12 changes: 12 additions & 0 deletions beater/api/config/agent/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ var (
respBody: map[string]string{"error": msgMethodUnsupported},
respBodyToken: map[string]string{"error": fmt.Sprintf("%s: PUT", msgMethodUnsupported)},
},

"Unauthorized": {
kbClient: tests.MockKibana(http.StatusUnauthorized, m{"error": "Unauthorized"}, mockVersion, true),
method: http.MethodGet,
queryParams: map[string]string{"service.name": "opbeans-node"},
respStatus: http.StatusServiceUnavailable,
respCacheControlHeader: "max-age=300, must-revalidate",
respBody: map[string]string{"error": agentcfg.ErrUnauthorized},
respBodyToken: map[string]string{"error": "APM Server is not authorized to query Kibana. " +
"Please configure apm-server.kibana.username and apm-server.kibana.password, " +
"and ensure the user has the necessary privileges."},
},
}
)

Expand Down