-
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
[Fleet] using point in time for agent status query to avoid discrepancy #135816
Changes from all commits
5cafce9
2c140f7
facbc8c
415c683
071b3b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -16,7 +16,15 @@ import type { AgentStatus } from '../../types'; | |||||||
import { AgentStatusKueryHelper } from '../../../common/services'; | ||||||||
import { FleetUnauthorizedError } from '../../errors'; | ||||||||
|
||||||||
import { getAgentById, getAgentsByKuery, removeSOAttributes } from './crud'; | ||||||||
import { appContextService } from '../app_context'; | ||||||||
|
||||||||
import { | ||||||||
closePointInTime, | ||||||||
getAgentById, | ||||||||
getAgentsByKuery, | ||||||||
openPointInTime, | ||||||||
removeSOAttributes, | ||||||||
} from './crud'; | ||||||||
|
||||||||
const DATA_STREAM_INDEX_PATTERN = 'logs-*-*,metrics-*-*,traces-*-*,synthetics-*-*'; | ||||||||
const MAX_AGENT_DATA_PREVIEW_SIZE = 20; | ||||||||
|
@@ -55,6 +63,18 @@ export async function getAgentStatusForAgentPolicy( | |||||||
agentPolicyId?: string, | ||||||||
filterKuery?: string | ||||||||
) { | ||||||||
let pitId: string | undefined; | ||||||||
try { | ||||||||
pitId = await openPointInTime(esClient); | ||||||||
} catch (error) { | ||||||||
if (error.statusCode === 404) { | ||||||||
appContextService | ||||||||
.getLogger() | ||||||||
.debug('Index .fleet-agents does not exist yet, skipping point in time.'); | ||||||||
} else { | ||||||||
throw error; | ||||||||
} | ||||||||
} | ||||||||
const [all, allActive, online, error, offline, updating] = await pMap( | ||||||||
[ | ||||||||
undefined, // All agents, including inactive | ||||||||
|
@@ -69,11 +89,11 @@ export async function getAgentStatusForAgentPolicy( | |||||||
showInactive: index === 0, | ||||||||
perPage: 0, | ||||||||
page: 1, | ||||||||
pitId, | ||||||||
kuery: joinKuerys( | ||||||||
...[ | ||||||||
kuery, | ||||||||
filterKuery, | ||||||||
`${AGENTS_PREFIX}.attributes.active:true`, | ||||||||
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. adding active filter here is incorrect, as kibana/x-pack/plugins/fleet/server/services/agents/crud.ts Lines 125 to 127 in bce1836
|
||||||||
agentPolicyId ? `${AGENTS_PREFIX}.policy_id:"${agentPolicyId}"` : undefined, | ||||||||
] | ||||||||
), | ||||||||
|
@@ -83,7 +103,11 @@ export async function getAgentStatusForAgentPolicy( | |||||||
} | ||||||||
); | ||||||||
|
||||||||
return { | ||||||||
if (pitId) { | ||||||||
await closePointInTime(esClient, pitId); | ||||||||
} | ||||||||
|
||||||||
const result = { | ||||||||
total: allActive.total, | ||||||||
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. I noticed that
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. Inactive agents are the ones that have been unenrolled, so they're generally excluded from the status as they're not relevant most of the time. We should probably have two fields, one for the real total and one for the total active, but I think we should only do this in a non-breaking way. Maybe 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. I agree, this would be cleaner. 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. I agree it is confusing. Total seems to be total active, which you don't assume from the name total, my vote would be to fix this. 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. Raised an issue to deprecate total status: #135980 |
||||||||
inactive: all.total - allActive.total, | ||||||||
online: online.total, | ||||||||
|
@@ -94,6 +118,7 @@ export async function getAgentStatusForAgentPolicy( | |||||||
/* @deprecated Agent events do not exists anymore */ | ||||||||
events: 0, | ||||||||
}; | ||||||||
return result; | ||||||||
} | ||||||||
export async function getIncomingDataByAgentsId( | ||||||||
esClient: ElasticsearchClient, | ||||||||
|
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.
small change to disable
Add / remove tags
action on inactive agents, like the other actions are disabled