Skip to content

Commit

Permalink
Clarify error message when unauthorized Kibana connection (#3753) (#3764
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jalvz authored May 11, 2020
1 parent 1fd82fb commit 84b88c0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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

0 comments on commit 84b88c0

Please sign in to comment.