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

Refactor Multi Node Analyzers #1646

Merged
merged 10 commits into from
Oct 21, 2024

Conversation

diamonwiggins
Copy link
Member

@diamonwiggins diamonwiggins commented Oct 13, 2024

Description, Motivation and Context

Refactoring analyzers to be easier to write. All analyzers implement a function to check a condition and then return true/false. All analyzers also evaluate outcomes in a similar way.

The recently added code to check if there are contents from remote collection present and then proceed to use them and if not fallback to local contents is also code that can be shared amongst all analyzers.

The goal is that these changes makes it easier to update all remaining analyzers to be able to process remote collected contents, and also just easier to maintain and update host analyzers going forward.

TODO:

  • Make sure logging is consistent with rest of codebase
  • Update/Fix Tests

Checklist

  • New and existing tests pass locally with introduced changes.
  • Tests for the changes have been added (for bug fixes / features)
  • The commit message(s) are informative and highlight any breaking changes
  • Any documentation required has been added/updated. For changes to https://troubleshoot.sh/ create a PR here

Does this PR introduce a breaking change?

  • Yes
  • No

@diamonwiggins diamonwiggins marked this pull request as ready for review October 15, 2024 23:46
@diamonwiggins diamonwiggins requested a review from a team as a code owner October 15, 2024 23:46
@diamonwiggins diamonwiggins changed the title WIP: Refactor Multi Node Analyzers Refactor Multi Node Analyzers Oct 15, 2024
Copy link
Member

@nvanthao nvanthao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes looks good, I just have few comments and questions.

Understand that all other analyzers will have to use function retrieveCollectedContents to retrieve the files before analyzing.

We will have to ensure that other host collectors follow directory convention of base dir system/<nodeName>/<file.json>

E.g. diskUsage doesn't follow this at the moment.

host-collectors
├── diskUsage
│   └── gerard-kurl-0
│       └── diskUsage.json
└── system
    ├── gerard-kurl-0
    │   ├── block_devices.json
    │   ├── cpu.json
    │   ├── hostos_info.json
    │   └── memory.json
    └── node_list.json

Also, does this PR mean other analyzers will just have to implement method CheckCondition for the analyzing part?

@diamonwiggins
Copy link
Member Author

Understand that all other analyzers will have to use function retrieveCollectedContents to retrieve the files before analyzing.

We will have to ensure that other host collectors follow directory convention of base dir system/<nodeName>/<file.json>

E.g. diskUsage doesn't follow this at the moment.

host-collectors
├── diskUsage
│   └── gerard-kurl-0
│       └── diskUsage.json
└── system
    ├── gerard-kurl-0
    │   ├── block_devices.json
    │   ├── cpu.json
    │   ├── hostos_info.json
    │   └── memory.json
    └── node_list.json

retreiveCollectedContents takes the base path and the file name as arguments, so in this case the base path would just be host-collectors/diskUsage. The only pattern everything must follow with this implementation is base-path/node/filename which is the pattern that remote host collection uses as well

Also, does this PR mean other analyzers will just have to implement method CheckCondition for the analyzing part?

Yup, every analyzer will just need to move their compare functions into a CheckCondition method, update Analyze with the simplified format, and add tests.

@nvanthao nvanthao force-pushed the diamonwiggins/refactor-multi-node-analyzers branch from d217ad1 to c05d677 Compare October 17, 2024 04:04
Copy link
Member

@banjoh banjoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the direction this PR has taken. This will DRY quite many of the host analysers. I've left some minor code comment changes

A change we can consider doing is moving node-list.json a directory higher to remove the duplicate file that gets created. It's not a major issue since it will contain the same contents.

if err != nil {
return nil, errors.Wrap(err, "failed to evaluate outcomes")
}
results = append(results, analyzeResult...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

analyzeResult can be nil. Check if nil

Comment on lines 11 to 20
type CollectedContent struct {
NodeName string
Data CollectorData
}

type CollectorData interface{}

type NodeNames struct {
Nodes []string `json:"nodes"`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these structs private. They are not used outside of analyze package

Copy link
Member

@banjoh banjoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will now have an analysis result for each node. I think we need to indicate which node a results is for. A prefix perhaps?

@banjoh
Copy link
Member

banjoh commented Oct 18, 2024

We will now have an analysis result for each node. I think we need to indicate which node a results is for. A prefix perhaps?

Ignore this comment. I just saw code doing this

@nvanthao nvanthao force-pushed the diamonwiggins/refactor-multi-node-analyzers branch from 0d34ff9 to 72d375c Compare October 21, 2024 03:12
@nvanthao nvanthao requested a review from banjoh October 21, 2024 03:23
@nvanthao
Copy link
Member

Hi @banjoh, could you help me review the updates? 🙇

Signed-off-by: Evans Mungai <evans@replicated.com>
@banjoh
Copy link
Member

banjoh commented Oct 21, 2024

The function to build collectors and filter excluded ones was making wrapping tracing spans a problem. We need one otel.Trace(...).Start() per collector. With that function, we would either not capture excluded collectors, or end up having duplicate traces since we call Start() twice for collectors that get executed.

Copy link
Member

@banjoh banjoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xavpaice xavpaice merged commit b88bc8d into main Oct 21, 2024
27 checks passed
@xavpaice xavpaice deleted the diamonwiggins/refactor-multi-node-analyzers branch October 21, 2024 21:45
@nvanthao nvanthao mentioned this pull request Oct 30, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants