Skip to content

Commit

Permalink
[Fleet] Fix namespaces property of created agent policies (#189199)
Browse files Browse the repository at this point in the history
## Summary

I found a small bug while working on
#185040: when agent policies are
created, there should be a root-level `namespaces` property, which is
currently missing.

`GET .fleet-policies/_mapping` contains a `namespaces` property with
`keyword` type that was added in
https://github.com/elastic/elasticsearch.

Note: I was looking into removing the existing `data.namespaces`
property, however I don't see any issues with it. It is coming from
[here](https://github.com/nchaulet/kibana/blob/f77e4d243fca87a87eeae1409f27876cc7ea0836/x-pack/plugins/fleet/server/services/agent_policy.ts#L1140),
i.e. the `data` property is generated from the full agent policy which
already has a `namespaces` property.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
jillguyonnet authored Jul 26, 2024
1 parent e1f2011 commit 9bc5741
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ export interface FleetServerPolicy {
* The coordinator index of the policy
*/
coordinator_idx: number;
/**
* The namespaces of the policy
*/
namespaces?: string[];
/**
* The opaque payload.
*/
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/fleet/server/services/agent_policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,7 @@ describe('Agent policy', () => {
mockedGetFullAgentPolicy.mockResolvedValue({
id: 'policy123',
revision: 1,
namespaces: ['mySpace'],
inputs: [
{
id: 'input-123',
Expand Down Expand Up @@ -1282,10 +1283,16 @@ describe('Agent policy', () => {
}),
expect.objectContaining({
'@timestamp': expect.anything(),
data: { id: 'policy123', inputs: [{ id: 'input-123' }], revision: 1 },
data: {
id: 'policy123',
inputs: [{ id: 'input-123' }],
revision: 1,
namespaces: ['mySpace'],
},
default_fleet_server: false,
policy_id: 'policy123',
revision_idx: 1,
namespaces: ['mySpace'],
}),
],
refresh: 'wait_for',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ class AgentPolicyService {
'@timestamp': new Date().toISOString(),
revision_idx: fullPolicy.revision,
coordinator_idx: 0,
namespaces: fullPolicy.namespaces,
data: fullPolicy as unknown as FleetServerPolicy['data'],
policy_id: fullPolicy.id,
default_fleet_server: policy.is_default_fleet_server === true,
Expand Down

0 comments on commit 9bc5741

Please sign in to comment.