forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix agent config indicator when applied through fleet integration (el…
…astic#131820) * Fix agent config indicator when applied through fleet integration * Add synthrace scenario Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
dcb9fc4
commit fe6190f
Showing
17 changed files
with
363 additions
and
36 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
24 changes: 24 additions & 0 deletions
24
packages/elastic-apm-synthtrace/src/lib/agent_config/agent_config.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,24 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { AgentConfigFields } from './agent_config_fields'; | ||
import { Metricset } from '../apm/metricset'; | ||
|
||
export class AgentConfig extends Metricset<AgentConfigFields> { | ||
constructor() { | ||
super({ | ||
'metricset.name': 'agent_config', | ||
agent_config_applied: 1, | ||
}); | ||
} | ||
|
||
etag(etag: string) { | ||
this.fields['labels.etag'] = etag; | ||
return this; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/elastic-apm-synthtrace/src/lib/agent_config/agent_config_fields.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,25 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ApmFields } from '../apm/apm_fields'; | ||
|
||
export type AgentConfigFields = Pick< | ||
ApmFields, | ||
| '@timestamp' | ||
| 'processor.event' | ||
| 'processor.name' | ||
| 'metricset.name' | ||
| 'observer' | ||
| 'ecs.version' | ||
| 'event.ingested' | ||
> & | ||
Partial<{ | ||
'labels.etag': string; | ||
agent_config_applied: number; | ||
'event.agent_id_status': string; | ||
}>; |
9 changes: 9 additions & 0 deletions
9
packages/elastic-apm-synthtrace/src/lib/agent_config/index.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,9 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { observer } from './observer'; |
21 changes: 21 additions & 0 deletions
21
packages/elastic-apm-synthtrace/src/lib/agent_config/observer.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,21 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { AgentConfigFields } from './agent_config_fields'; | ||
import { AgentConfig } from './agent_config'; | ||
import { Entity } from '../entity'; | ||
|
||
export class Observer extends Entity<AgentConfigFields> { | ||
agentConfig() { | ||
return new AgentConfig(); | ||
} | ||
} | ||
|
||
export function observer() { | ||
return new Observer({}); | ||
} |
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
36 changes: 36 additions & 0 deletions
36
packages/elastic-apm-synthtrace/src/scripts/examples/04_agent_config.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,36 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { observer, timerange } from '../..'; | ||
import { Scenario } from '../scenario'; | ||
import { getLogger } from '../utils/get_common_services'; | ||
import { RunOptions } from '../utils/parse_run_cli_flags'; | ||
import { AgentConfigFields } from '../../lib/agent_config/agent_config_fields'; | ||
|
||
const scenario: Scenario<AgentConfigFields> = async (runOptions: RunOptions) => { | ||
const logger = getLogger(runOptions); | ||
|
||
return { | ||
generate: ({ from, to }) => { | ||
const agentConfig = observer().agentConfig(); | ||
|
||
const range = timerange(from, to); | ||
return range | ||
.interval('30s') | ||
.rate(1) | ||
.generator((timestamp) => { | ||
const events = logger.perf('generating_agent_config_events', () => { | ||
return agentConfig.etag('test-etag').timestamp(timestamp); | ||
}); | ||
return events; | ||
}); | ||
}, | ||
}; | ||
}; | ||
|
||
export default scenario; |
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
60 changes: 60 additions & 0 deletions
60
...m/server/routes/settings/agent_configuration/get_config_applied_to_agent_through_fleet.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,60 @@ | ||
/* | ||
* 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 { termQuery, rangeQuery } from '@kbn/observability-plugin/server'; | ||
import datemath from '@kbn/datemath'; | ||
import { METRICSET_NAME } from '../../../../common/elasticsearch_fieldnames'; | ||
import { Setup } from '../../../lib/helpers/setup_request'; | ||
|
||
export async function getConfigsAppliedToAgentsThroughFleet({ | ||
setup, | ||
}: { | ||
setup: Setup; | ||
}) { | ||
const { internalClient, indices } = setup; | ||
|
||
const params = { | ||
index: indices.metric, | ||
size: 0, | ||
body: { | ||
query: { | ||
bool: { | ||
filter: [ | ||
...termQuery(METRICSET_NAME, 'agent_config'), | ||
...rangeQuery( | ||
datemath.parse('now-15m')!.valueOf(), | ||
datemath.parse('now')!.valueOf() | ||
), | ||
], | ||
}, | ||
}, | ||
aggs: { | ||
config_by_etag: { | ||
terms: { | ||
field: 'labels.etag', | ||
size: 200, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const response = await internalClient.search( | ||
'get_config_applied_to_agent_through_fleet', | ||
params | ||
); | ||
|
||
return ( | ||
response.aggregations?.config_by_etag.buckets.reduce( | ||
(configsAppliedToAgentsThroughFleet, bucket) => { | ||
configsAppliedToAgentsThroughFleet[bucket.key as string] = true; | ||
return configsAppliedToAgentsThroughFleet; | ||
}, | ||
{} as Record<string, true> | ||
) ?? {} | ||
); | ||
} |
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.