-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[/api/stats
] Add documentation + small improvement
#79330
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fa2aaf2
[`/api/stats`] Add documentation + small improvement
afharo 6df200e
Add link to the README in the main plugin's README
afharo 2fd5af4
Merge branch 'master' into usage_collection/routes/stats
kibanamachine 58d02b8
Apply suggestions from code review
Bamieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions
20
src/plugins/usage_collection/server/routes/stats/README.md
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,20 @@ | ||
# `/api/stats` | ||
|
||
This API returns the metrics for the Kibana server and usage stats. It allows the [Metricbeat Kibana module](https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-module-kibana.html) to collect the [stats metricset](https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-metricset-kibana-stats.html). | ||
|
||
By default, it returns the simplest level of stats; consisting of the Kibana server's ops metrics, version, status, and basic config like the server name, host, port, and locale. | ||
|
||
However, the information detailed above can be extended, with the combination of the following 3 query parameters: | ||
|
||
| Query Parameter | Default value | Description | | ||
|:----------------|:-------------:|:------------| | ||
|`extended`|`false`|When `true`, it adds `clusterUuid` and `usage`. The latter contains the information reported by all the Usage Collectors registered in the Kibana server. It may throw `503 Stats not ready` if any of the collectors is not fully initialized yet.| | ||
|`legacy`|`false`|By default, when `extended=true`, the key names of the data in `usage` are transformed into API-friendlier `snake_case` format (i.e.: `clusterUuid` is transformed to `cluster_uuid`). When this parameter is `true`, the data is returned as-is.| | ||
|`exclude_usage`|`false`|When `true`, and `extended=true`, it will report `clusterUuid` but no `usage`.| | ||
|
||
## Known use cases | ||
|
||
Metricbeat Kibana' stats metricset ([code](https://github.com/elastic/beats/blob/master/metricbeat/module/kibana/stats/stats.go)) uses this API to collect the metrics (every 10s) and usage (only once every 24h), and then reports them to the Monitoring cluster. They call this API in 2 ways: | ||
|
||
1. Metrics-only collection (every 10 seconds): `GET /api/stats?extended=true&legacy=true&exclude_usage=true` | ||
2. Metrics+usage (every 24 hours): `GET /api/stats?extended=true&legacy=true&exclude_usage=false` |
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,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { registerStatsRoute } from './stats'; |
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 |
---|---|---|
|
@@ -30,8 +30,8 @@ import { | |
MetricsServiceSetup, | ||
ServiceStatus, | ||
ServiceStatusLevels, | ||
} from '../../../../core/server'; | ||
import { CollectorSet } from '../collector'; | ||
} from '../../../../../core/server'; | ||
import { CollectorSet } from '../../collector'; | ||
|
||
const STATS_NOT_READY_MESSAGE = i18n.translate('usageCollection.stats.notReadyMessage', { | ||
defaultMessage: 'Stats are not ready yet. Please try again later.', | ||
|
@@ -101,10 +101,12 @@ export function registerStatsRoute({ | |
if (isExtended) { | ||
const callCluster = context.core.elasticsearch.legacy.client.callAsCurrentUser; | ||
const esClient = context.core.elasticsearch.client.asCurrentUser; | ||
const collectorsReady = await collectorSet.areAllCollectorsReady(); | ||
|
||
if (shouldGetUsage && !collectorsReady) { | ||
return res.customError({ statusCode: 503, body: { message: STATS_NOT_READY_MESSAGE } }); | ||
if (shouldGetUsage) { | ||
const collectorsReady = await collectorSet.areAllCollectorsReady(); | ||
if (!collectorsReady) { | ||
return res.customError({ statusCode: 503, body: { message: STATS_NOT_READY_MESSAGE } }); | ||
} | ||
} | ||
|
||
const usagePromise = shouldGetUsage ? getUsage(callCluster, esClient) : Promise.resolve({}); | ||
|
@@ -152,9 +154,8 @@ export function registerStatsRoute({ | |
} | ||
} | ||
|
||
// Guranteed to resolve immediately due to replay effect on getOpsMetrics$ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, OCD trying to avoid as many |
||
const { collected_at, ...lastMetrics } = await metrics | ||
// Guaranteed to resolve immediately due to replay effect on getOpsMetrics$ | ||
const { collected_at: collectedAt, ...lastMetrics } = await metrics | ||
.getOpsMetrics$() | ||
.pipe(first()) | ||
.toPromise(); | ||
|
@@ -173,7 +174,7 @@ export function registerStatsRoute({ | |
snapshot: SNAPSHOT_REGEX.test(config.kibanaVersion), | ||
status: ServiceStatusToLegacyState[overallStatus.level.toString()], | ||
}, | ||
last_updated: collected_at.toISOString(), | ||
last_updated: collectedAt.toISOString(), | ||
collection_interval_in_millis: metrics.collectionInterval, | ||
}); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs on the kibana stats metricset don't actually give anything useful. Having the link is great though and hopefully we can get a bit more on that page.