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

Fix get health #1032

Merged
merged 9 commits into from
Dec 20, 2022
Merged

Fix get health #1032

merged 9 commits into from
Dec 20, 2022

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Dec 2, 2022

Improve the old getHealth (now getCheckHealthByAgent) to consider all the possible scenarios: agentCheckError, expect_same, fact gathering error, etc

I have added more factory improvements in order to make the check results mocks creation easy.
PD: I have fixed some other functions like getHosts by this will be removed once we get the other PR using the targets to create the results table

@dottorblaster dottorblaster force-pushed the fix-get-health branch 2 times, most recently from 5138f14 to dd40854 Compare December 19, 2022 09:06
Copy link
Contributor

@rtorrero rtorrero left a comment

Choose a reason for hiding this comment

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

LGTM @arbulu89 , just a bit of (opinionated) nitpicking on naming

);

export const getChecks = (checkResults) =>
checkResults.map(({ check_id }) => check_id);

export const getHealth = (checkResults, checkID, agentID) => {
export const getCheckHealthByAgent = (checkResults, checkID, agentID) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make more sense to call this getCheckResultHealthByAgent ?

}

// expectation evaluation error , malformed expression most probably
const evaluationErrors = agentCheckResult?.expectation_evaluations.filter(
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally like adding a Count suffix to variables that are just counting something, in this case e.g.: evaluationErrorCount as it makes operations with the variable more obvious (e.g. the + below is immediately understood as a sum and not a concatenation). Wdyt?

};

const addExpectation = (checkResult, name, expec, result) => {
const { type } = expec;
Copy link
Contributor

Choose a reason for hiding this comment

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

expect maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be expectation to me, you're right

return addExpectation(checkResult, name, expec, false);
};

export const addExpectationWithError = (checkResult) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe addErroredExpectation sound better and matches the same wording as the other functions?

Copy link
Contributor Author

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

@dottorblaster It looks good.
Have a look only in one of the factory functions that I think you updated accidentaly.
Besides that, a small change in the test to make it more logical.
Green light, otherwise.
I cannot approve though, as I opened the PR XD

);

export const executionFactFactory = Factory.define(() => ({
check_id: faker.datatype.uuid(),
name: faker.animal.cat(),
value: faker.datatype.number(),
result: resultEnum(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change looks wrong. This is an execution fact, which is composed by check_id, name and value, as it was before

import { renderWithRouter } from '@lib/test-utils';
import {
addCriticalExpectation,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any reason not to put the executions under the factories import. All of them are exported in the index file.
@lib/test-utils/factories

@@ -87,7 +108,8 @@ describe('ExecutionResults', () => {
const {
clusterID,
hostnames,
checkID,
checkID1,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we return maybe checks? As we do with the hostnames

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair point

} from '@lib/test-utils/factories/executions';
import { catalogFactory, hostnameFactory } from '@lib/test-utils/factories';

import ExecutionResults from './ExecutionResults';

const prepareStateData = (checkExecutionStatus) => {
const hostnames = hostnameFactory.buildList(2);
const hostnames = hostnameFactory.buildList(4);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why a 4 here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Leftover from an experiment LOL

@dottorblaster dottorblaster merged commit 9adf53d into main Dec 20, 2022
@dottorblaster dottorblaster deleted the fix-get-health branch December 20, 2022 09:09
});

const lastExecution = {
executionLoading: false,
executionData: {
status: checkExecutionStatus,
targets,
check_results: [checkResult],
check_results: [checkResult1, checkResult2],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dottorblaster You fortot to change this executionData: executionResult

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants