Skip to content
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

AgentJanitor Rework #1217

Merged
merged 17 commits into from
Jul 27, 2023
Merged

AgentJanitor Rework #1217

merged 17 commits into from
Jul 27, 2023

Conversation

tylerwowen
Copy link
Contributor

@tylerwowen tylerwowen commented Jul 13, 2023

Problems

  1. AgentJanitor cleans up based on the agents_and_hosts table, but it's not complete. There are hosts that' never had an agent. So it should look at the hosts table as well.
  2. The order of processing was wrong. Stale hosts should be a subset of unreachable hosts. The current implementation processes unreachable hosts first then stale hosts. This can result in stale hosts being processed twice.

Improvements

Now the AgentJanitor does 3 things:

  1. processStaleHosts();
  2. determineStaleHostCandidates();
  3. cleanUpAgentlessHosts();

The first 2 remain the same, except the order has been swapped. This resolves problem 2. The third task solves problem 1.

cleanUpAgentlessHosts

This method queries the DB via the new API HostDAO:getStaleAgentlessHostIds to get a list of host IDs without associated agents. The list is filtered by last_update so only stale hosts will be process.

SELECT DISTINCT
    hosts.host_id
FROM
    hosts
    LEFT JOIN hosts_and_agents ON hosts.host_id = hosts_and_agents.host_id
WHERE
    hosts.last_update < ?
    AND hosts_and_agents.host_id IS NULL
ORDER BY
    hosts.last_update DESC
LIMIT
    ?

Tests and validations

Deployed to dev1 and manually validated the status by reviewing corresponding logs.

CDP-6636

@tylerwowen tylerwowen marked this pull request as ready for review July 14, 2023 23:07
@tylerwowen tylerwowen requested a review from a team as a code owner July 14, 2023 23:07
@tylerwowen tylerwowen requested a review from yongwen July 27, 2023 00:45
@tylerwowen tylerwowen merged commit b2bd6b8 into master Jul 27, 2023
4 checks passed
@tylerwowen tylerwowen deleted the touyang/agentjanitor branch July 27, 2023 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants