Skip to content

Commit

Permalink
checks apm fleet integration when pushing button
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 1, 2021
1 parent 0f0f458 commit 2f81e72
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ const statusCheckConfigShape = PropTypes.shape({
title: PropTypes.string,
text: PropTypes.string,
btnLabel: PropTypes.string,
customStatusCheck: PropTypes.string,
});

InstructionSetUi.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,31 @@ class TutorialUi extends React.Component {
checkInstructionSetStatus = async (instructionSetIndex) => {
const instructionSet = this.getInstructionSets()[instructionSetIndex];
const esHitsCheckConfig = _.get(instructionSet, `statusCheck.esHitsCheck`);
const customStatusCheck = _.get(instructionSet, `statusCheck.customStatusCheck`);

if (esHitsCheckConfig) {
const statusCheckState = await this.fetchEsHitsStatus(esHitsCheckConfig);
const [esHitsStatusCheck, apmFleetStatusCheck] = await Promise.all([
...(esHitsCheckConfig ? [this.fetchEsHitsStatus(esHitsCheckConfig)] : []),
...(customStatusCheck === 'apm-fleet-check' ? [this.fetchApmFleetStatus()] : []),
]);

this.setState((prevState) => ({
statusCheckStates: {
...prevState.statusCheckStates,
[instructionSetIndex]: statusCheckState,
},
}));
}
const nextStatusCheckState =
esHitsStatusCheck === StatusCheckStates.HAS_DATA ||
apmFleetStatusCheck === StatusCheckStates.HAS_DATA
? StatusCheckStates.HAS_DATA
: StatusCheckStates.NO_DATA;

this.setState((prevState) => ({
statusCheckStates: {
...prevState.statusCheckStates,
[instructionSetIndex]: nextStatusCheckState,
},
}));
};

fetchApmFleetStatus = async () => {
const { http } = getServices();
const response = await http.get('/api/apm/fleet/has_data');
return response?.hasData === true ? StatusCheckStates.HAS_DATA : StatusCheckStates.NO_DATA;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const statusCheckSchema = schema.object({
index: schema.oneOf([schema.string(), schema.arrayOf(schema.string())]),
query: schema.recordOf(schema.string(), schema.any()),
}),
customStatusCheck: schema.maybe(schema.string()),
});

const instructionSchema = schema.object({
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/server/tutorial/envs/on_prem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export function onPremInstructions({
'No APM Server detected. Please make sure it is running and you have updated to 7.0 or higher.',
}
),
customStatusCheck: 'apm-fleet-check',
esHitsCheck: {
index: onboardingIndices,
query: {
Expand Down

0 comments on commit 2f81e72

Please sign in to comment.