[9.0] [Usage collection] Replace agent.type with hard coded value to categorize monitoring type correctly. (#216391) (#216953)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Usage collection] Replace `agent.type` with hard coded value to
categorize monitoring type correctly.
(#216391)](https://github.com/elastic/kibana/pull/216391)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT
[{"author":{"name":"Mashhur","email":"99575341+mashhurs@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-03T07:06:38Z","message":"[Usage
collection] Replace `agent.type` with hard coded value to categorize
monitoring type correctly. (#216391)\n\n## Summary\nCollection type was
set with `agent.type` which conflicts on stack and\nmetricbeat
monitorings (same `metricbeat` value). For the stack\nmonitoring,
elastic-agent internally utilizes filebat or metricbeat.\nThis change
hard codes the `collection_types` corresponding on each\nmonitoring type
to categorize monitoring type correctly.\n\n\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\nReviewers should verify this
PR satisfies this list as well.\n\n- ~~[ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~~\n-
~~[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials~~\n- [x] [Unit
or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- ~~[ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~~\n-
~~[ ] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.~~\n- ~~[ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed~~\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\n- [ ] \n\n\n### Example data\n- when stack
monitoring\n```\n{\n \"clusterUuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n
\"stats\": {\n \"collectionSource\": \"monitoring\",\n \"cacheDetails\":
{\n \"updatedAt\": \"2025-03-31T23:07:32.154Z\",\n \"fetchedAt\":
\"2025-03-31T23:07:33.349Z\"\n },\n \"cluster_name\": \"logstash\",\n
\"timestamp\": \"2025-03-31T23:07:32Z\",\n \"version\": \"9.1.0\",\n
\"cluster_uuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n \"stack_stats\": {\n
\"logstash\": {\n \"versions\": [\n {\n \"version\": \"9.1.0\",\n
\"count\": 1\n }\n ],\n \"count\": 1,\n \"cluster_stats\": {\n
\"pipelines\": {\n \"count\": 1,\n \"batch_size_total\": 125,\n
\"batch_size_max\": 125,\n \"batch_size_min\": 125,\n
\"batch_size_avg\": 125,\n \"workers_total\": 10,\n \"workers_max\":
10,\n \"workers_min\": 10,\n \"workers_avg\": 10,\n \"sources\": {\n
\"file\": true\n }\n },\n \"plugins\": [\n {\n \"name\":
\"logstash-input-heartbeat\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-filter-ruby\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-filter-mutate\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-output-stdout\",\n \"count\": 1\n }\n ],\n
\"monitoringClusterUuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n
\"collection_types\": {\n \"agent\": 1\n },\n \"queues\": {\n
\"memory\": 1\n }\n }\n }\n },\n \"cluster_stats\": {}\n }\n
}\n```\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c4ad8cbe8c13fb490bf2d3d56077098fa85ff736","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","backport:prev-major","v9.1.0"],"title":"[Usage
collection] Replace `agent.type` with hard coded value to categorize
monitoring type
correctly.","number":216391,"url":"https://github.com/elastic/kibana/pull/216391","mergeCommit":{"message":"[Usage
collection] Replace `agent.type` with hard coded value to categorize
monitoring type correctly. (#216391)\n\n## Summary\nCollection type was
set with `agent.type` which conflicts on stack and\nmetricbeat
monitorings (same `metricbeat` value). For the stack\nmonitoring,
elastic-agent internally utilizes filebat or metricbeat.\nThis change
hard codes the `collection_types` corresponding on each\nmonitoring type
to categorize monitoring type correctly.\n\n\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\nReviewers should verify this
PR satisfies this list as well.\n\n- ~~[ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~~\n-
~~[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials~~\n- [x] [Unit
or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- ~~[ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~~\n-
~~[ ] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.~~\n- ~~[ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed~~\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\n- [ ] \n\n\n### Example data\n- when stack
monitoring\n```\n{\n \"clusterUuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n
\"stats\": {\n \"collectionSource\": \"monitoring\",\n \"cacheDetails\":
{\n \"updatedAt\": \"2025-03-31T23:07:32.154Z\",\n \"fetchedAt\":
\"2025-03-31T23:07:33.349Z\"\n },\n \"cluster_name\": \"logstash\",\n
\"timestamp\": \"2025-03-31T23:07:32Z\",\n \"version\": \"9.1.0\",\n
\"cluster_uuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n \"stack_stats\": {\n
\"logstash\": {\n \"versions\": [\n {\n \"version\": \"9.1.0\",\n
\"count\": 1\n }\n ],\n \"count\": 1,\n \"cluster_stats\": {\n
\"pipelines\": {\n \"count\": 1,\n \"batch_size_total\": 125,\n
\"batch_size_max\": 125,\n \"batch_size_min\": 125,\n
\"batch_size_avg\": 125,\n \"workers_total\": 10,\n \"workers_max\":
10,\n \"workers_min\": 10,\n \"workers_avg\": 10,\n \"sources\": {\n
\"file\": true\n }\n },\n \"plugins\": [\n {\n \"name\":
\"logstash-input-heartbeat\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-filter-ruby\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-filter-mutate\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-output-stdout\",\n \"count\": 1\n }\n ],\n
\"monitoringClusterUuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n
\"collection_types\": {\n \"agent\": 1\n },\n \"queues\": {\n
\"memory\": 1\n }\n }\n }\n },\n \"cluster_stats\": {}\n }\n
}\n```\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c4ad8cbe8c13fb490bf2d3d56077098fa85ff736"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216391","number":216391,"mergeCommit":{"message":"[Usage
collection] Replace `agent.type` with hard coded value to categorize
monitoring type correctly. (#216391)\n\n## Summary\nCollection type was
set with `agent.type` which conflicts on stack and\nmetricbeat
monitorings (same `metricbeat` value). For the stack\nmonitoring,
elastic-agent internally utilizes filebat or metricbeat.\nThis change
hard codes the `collection_types` corresponding on each\nmonitoring type
to categorize monitoring type correctly.\n\n\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\nReviewers should verify this
PR satisfies this list as well.\n\n- ~~[ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~~\n-
~~[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials~~\n- [x] [Unit
or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- ~~[ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~~\n-
~~[ ] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.~~\n- ~~[ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed~~\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\n- [ ] \n\n\n### Example data\n- when stack
monitoring\n```\n{\n \"clusterUuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n
\"stats\": {\n \"collectionSource\": \"monitoring\",\n \"cacheDetails\":
{\n \"updatedAt\": \"2025-03-31T23:07:32.154Z\",\n \"fetchedAt\":
\"2025-03-31T23:07:33.349Z\"\n },\n \"cluster_name\": \"logstash\",\n
\"timestamp\": \"2025-03-31T23:07:32Z\",\n \"version\": \"9.1.0\",\n
\"cluster_uuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n \"stack_stats\": {\n
\"logstash\": {\n \"versions\": [\n {\n \"version\": \"9.1.0\",\n
\"count\": 1\n }\n ],\n \"count\": 1,\n \"cluster_stats\": {\n
\"pipelines\": {\n \"count\": 1,\n \"batch_size_total\": 125,\n
\"batch_size_max\": 125,\n \"batch_size_min\": 125,\n
\"batch_size_avg\": 125,\n \"workers_total\": 10,\n \"workers_max\":
10,\n \"workers_min\": 10,\n \"workers_avg\": 10,\n \"sources\": {\n
\"file\": true\n }\n },\n \"plugins\": [\n {\n \"name\":
\"logstash-input-heartbeat\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-filter-ruby\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-filter-mutate\",\n \"count\": 1\n },\n {\n \"name\":
\"logstash-output-stdout\",\n \"count\": 1\n }\n ],\n
\"monitoringClusterUuid\": \"WKhHGcv8Rt6nHwKRmKDdAw\",\n
\"collection_types\": {\n \"agent\": 1\n },\n \"queues\": {\n
\"memory\": 1\n }\n }\n }\n },\n \"cluster_stats\": {}\n }\n
}\n```\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c4ad8cbe8c13fb490bf2d3d56077098fa85ff736"}}]}]
BACKPORT-->

Co-authored-by: Mashhur <99575341+mashhurs@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2025-04-03 11:34:43 +02:00 committed by GitHub
parent 0ab9cd521e
commit e658d0ed24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 9 deletions

View file

@ -204,7 +204,7 @@ describe('LogstashAgentMonitoring', () => {
count: 1,
cluster_stats: {
collection_types: {
filebeat: 1,
agent: 1,
},
monitoringClusterUuid: 'FlV4ckTxQ0a78hmBkzzc9A',
pipelines: {
@ -288,7 +288,7 @@ describe('LogstashAgentMonitoring', () => {
count: 1,
cluster_stats: {
collection_types: {
filebeat: 1,
agent: 1,
},
monitoringClusterUuid: 'FlV4ckTxQ0a78hmBkzzc9A',
pipelines: {
@ -491,7 +491,7 @@ describe('LogstashAgentMonitoring', () => {
'1n1p': {
cluster_stats: {
collection_types: {
filebeat: 1,
agent: 1,
},
monitoringClusterUuid: 'monitoringClusterUuid',
pipelines: {
@ -523,7 +523,7 @@ describe('LogstashAgentMonitoring', () => {
'1nmp': {
cluster_stats: {
collection_types: {
filebeat: 2,
agent: 2,
},
monitoringClusterUuid: 'monitoringClusterUuid',
pipelines: {
@ -547,7 +547,7 @@ describe('LogstashAgentMonitoring', () => {
mnmp: {
cluster_stats: {
collection_types: {
filebeat: 3,
agent: 3,
},
monitoringClusterUuid: 'monitoringClusterUuid',
pipelines: {

View file

@ -120,7 +120,7 @@ export class LogstashAgentMonitoring implements LogstashMonitoring {
}
}
const thisCollectionType = hit._source?.agent?.type || 'agent';
const thisCollectionType = 'agent';
if (!Object.hasOwn(clusterStats, 'collection_types')) {
clusterStats.collection_types = {};
}

View file

@ -53,15 +53,17 @@ describe('LogstashMetricbeatMonitoring', () => {
});
test('should set and get indexPattern correctly', () => {
metricbeatMonitoring.setIndexPattern('legacy');
metricbeatMonitoring.setIndexPattern('metricbeat');
const indexPatternForLegacy = metricbeatMonitoring.getIndexPattern();
expect(indexPatternForLegacy.stats).toBe(INDEX_PATTERN_LOGSTASH_MONITORING);
expect(indexPatternForLegacy.state).toBe(INDEX_PATTERN_LOGSTASH_MONITORING);
expect(metricbeatMonitoring.getMonitoringType()).toBe('metricbeat');
metricbeatMonitoring.setIndexPattern('stack');
const indexPatternForStack = metricbeatMonitoring.getIndexPattern();
expect(indexPatternForStack.stats).toBe(INDEX_PATTERN_LOGSTASH_STACK_MONITORING_STATS);
expect(indexPatternForStack.state).toBe(INDEX_PATTERN_LOGSTASH_STACK_MONITORING_STATE);
expect(metricbeatMonitoring.getMonitoringType()).toBe('stack');
});
describe('Logstash metricbeat monitoring query test', () => {

View file

@ -33,6 +33,8 @@ export class LogstashMetricbeatMonitoring implements LogstashMonitoring {
stats: INDEX_PATTERN_LOGSTASH_STACK_MONITORING_STATS,
};
private monitoringType: string = 'metricbeat';
/*
* Call the function for fetching and summarizing Logstash metrics for Metricbeat monitoring
* @param {Object} callCluster - ES client
@ -67,6 +69,7 @@ export class LogstashMetricbeatMonitoring implements LogstashMonitoring {
* @param monitoringType - the monitoring type where metricbeat monitoring is intended.
*/
setIndexPattern(monitoringType: string) {
this.monitoringType = monitoringType;
if (monitoringType === 'stack') {
this.indexPattern.state = INDEX_PATTERN_LOGSTASH_STACK_MONITORING_STATE;
this.indexPattern.stats = INDEX_PATTERN_LOGSTASH_STACK_MONITORING_STATS;
@ -79,6 +82,11 @@ export class LogstashMetricbeatMonitoring implements LogstashMonitoring {
getIndexPattern(): { [key: string]: string } {
return this.indexPattern;
}
getMonitoringType(): string {
return this.monitoringType;
}
/*
* Update a clusters object with processed Logstash stats for metricbeat monitoring
* @param {Array} results - array of LogstashStats docs from ES
@ -117,7 +125,8 @@ export class LogstashMetricbeatMonitoring implements LogstashMonitoring {
incrementByKey(a, thisVersion);
clusters[clusterUuid].versions = mapToList(a, 'version');
const thisCollectionType = hit._source?.agent?.type || 'metricbeat';
// for stack_monitoring, agent internally uses metricbeat or filebeat
const thisCollectionType = this.getMonitoringType() === 'stack' ? 'agent' : 'metricbeat';
if (!Object.hasOwn(clusterStats, 'collection_types')) {
clusterStats.collection_types = {};
}

View file

@ -103,7 +103,7 @@ export class LogstashSelfMonitoring implements LogstashMonitoring {
clusters[clusterUuid].versions = mapToList(a, 'version');
// Internal Collection has no agent field, so default to 'internal_collection'
const thisCollectionType = hit._source?.agent?.type || 'internal_collection';
const thisCollectionType = 'internal_collection';
if (!Object.hasOwn(clusterStats, 'collection_types')) {
clusterStats.collection_types = {};
}