From 84b88c0afc28cb6453723f4830435b60a57d9334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Mon, 11 May 2020 11:29:29 +0200 Subject: [PATCH] Clarify error message when unauthorized Kibana connection (#3753) (#3764) --- agentcfg/fetch.go | 6 +++--- beater/api/config/agent/handler.go | 7 +++++++ beater/api/config/agent/handler_test.go | 12 ++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/agentcfg/fetch.go b/agentcfg/fetch.go index 2fe75826ce7..62451faf114 100644 --- a/agentcfg/fetch.go +++ b/agentcfg/fetch.go @@ -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" ) diff --git a/beater/api/config/agent/handler.go b/beater/api/config/agent/handler.go index a9eff1c80f5..8d49407aefa 100644 --- a/beater/api/config/agent/handler.go +++ b/beater/api/config/agent/handler.go @@ -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 diff --git a/beater/api/config/agent/handler_test.go b/beater/api/config/agent/handler_test.go index fca7e6ed8a8..cbfe03613f1 100644 --- a/beater/api/config/agent/handler_test.go +++ b/beater/api/config/agent/handler_test.go @@ -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."}, + }, } )