-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Stack Monitoring] Collect metrics errors in health api (#148750)
Closes #140358 ## Summary This PR adds integration package errors to the `_health` endpoint. The response should look similar to the metricbeat one we already have. The difference will be that the package will use `data_stream.dataset` instead of `metricset.name` ## Testing 1. Setup an integration - Follow this [guide](https://github.com/klacabane/observability-dev/blob/0e924730cc5d9ae16f67420eb6fa3b2337b98dc9/docs/infra-obs-ui/stack-monitoring_integration-packages.md) to install the package. ~~⚠️ Note that you need to have `metricset.name` mapping to see the errors added in this [PR](elastic/integrations#4973 - No need anymore as we use `data_stream.dataset` for packages 2. Installing the package: - In this case, we want to enable metrics and set the Agent policy to Elastic-Agent (elastic-package). To see an error I used the wrong host URL (inside `Change Defaults`) when I was configuring the elasticsearch integration: <img width="1313" alt="image" src="https://user-images.githubusercontent.com/14139027/212313537-f1f6f5b1-6e4d-40f2-8f78-9f0e5f48c434.png"> 3. To see the package errors run `curl --user elastic:changeme http://localhost:5602/ftw/api/monitoring/v1/_health` or open http://localhost:5602/ftw/api/monitoring/v1/_health in a browser where you are logged in in your kibana. (The port of the kibana is 5602 as mentioned in the [guide](https://github.com/klacabane/observability-dev/blob/0e924730cc5d9ae16f67420eb6fa3b2337b98dc9/docs/infra-obs-ui/stack-monitoring_integration-packages.md#connecting-a-local-kibana) this will be your local kibana running - I recommend to add the package to the elastic package kibana running on 5601 and to run your local kibana after the setup is complete) Example response: ``` { "metricbeatErrors": { ... }, "packageErrors": { "products": { "elasticsearch": { "elasticsearch.stack_monitoring.node": [ { "message": "error making http request: Get \"http://localhost:9200/_nodes/_local\": dial tcp 127.0.0.1:9200: connect: connection refused", "lastSeen": "2023-01-12T17:27:01.862Z" } ], "elasticsearch.stack_monitoring.node_stats": [ { "message": "error making http request: Get \"http://localhost:9200/_nodes/_local/stats\": dial tcp [::1]:9200: connect: cannot assign requested address", "lastSeen": "2023-01-12T17:26:31.883Z" } ], ..... }, "execution": { "timedOut": false, "errors": [] } } } } ```
- Loading branch information
1 parent
4bdf1d4
commit 066ee1c
Showing
17 changed files
with
1,975 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
x-pack/plugins/monitoring/server/routes/api/v1/_health/errors_helpers/build_errors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { buildErrors } from './build_errors'; | ||
import assert from 'assert'; | ||
|
||
describe(__filename, () => { | ||
describe('buildErrors', () => { | ||
test('Metricbeat: it should build an object containing dedup error messages per event.dataset', () => { | ||
const metricbeatErrors = [ | ||
{ | ||
key: 'beat', | ||
errors_by_dataset: { | ||
buckets: [ | ||
{ | ||
key: 'state', | ||
latest_docs: { | ||
hits: { | ||
hits: [ | ||
{ | ||
_source: { | ||
'@timestamp': '2022-07-26T08:43:32.625Z', | ||
error: { | ||
message: | ||
'error making http request: Get "http://host.docker.internal:5067/state": dial tcp 192.168.65.2:5067: connect: connection refused', | ||
}, | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
'@timestamp': '2022-07-26T08:42:32.625Z', | ||
error: { | ||
message: | ||
'error making http request: Get "http://host.docker.internal:5067/state": dial tcp 192.168.65.2:5067: connect: connection refused', | ||
}, | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
'@timestamp': '2022-07-26T08:41:32.625Z', | ||
error: { | ||
message: 'Generic random error', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
const monitoredClusters = buildErrors(metricbeatErrors); | ||
assert.deepEqual(monitoredClusters, { | ||
beat: { | ||
state: [ | ||
{ | ||
lastSeen: '2022-07-26T08:43:32.625Z', | ||
message: | ||
'error making http request: Get "http://host.docker.internal:5067/state": dial tcp 192.168.65.2:5067: connect: connection refused', | ||
}, | ||
{ | ||
lastSeen: '2022-07-26T08:41:32.625Z', | ||
message: 'Generic random error', | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
test('Packages: it should build an object containing dedup error messages per event.dataset', () => { | ||
const packageErrors = [ | ||
{ | ||
key: 'elasticsearch', | ||
errors_by_dataset: { | ||
buckets: [ | ||
{ | ||
key: 'state', | ||
latest_docs: { | ||
hits: { | ||
hits: [ | ||
{ | ||
_source: { | ||
'@timestamp': '2023-01-10T14:39:37.114Z', | ||
error: { | ||
message: | ||
'error making http request: Get "https://localhost:9200/_nodes/_local": dial tcp [::1]:9200: connect: cannot assign requested address', | ||
}, | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
'@timestamp': '2023-01-10T14:39:27.114Z', | ||
error: { | ||
message: | ||
'error making http request: Get "https://localhost:9200/_nodes/_local": dial tcp [::1]:9200: connect: cannot assign requested address', | ||
}, | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
'@timestamp': '2022-07-26T08:41:32.625Z', | ||
error: { | ||
message: 'Generic random error', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
const monitoredClusters = buildErrors(packageErrors); | ||
assert.deepEqual(monitoredClusters, { | ||
elasticsearch: { | ||
state: [ | ||
{ | ||
lastSeen: '2023-01-10T14:39:37.114Z', | ||
message: | ||
'error making http request: Get "https://localhost:9200/_nodes/_local": dial tcp [::1]:9200: connect: cannot assign requested address', | ||
}, | ||
{ | ||
lastSeen: '2022-07-26T08:41:32.625Z', | ||
message: 'Generic random error', | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.