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

[RAC] [APM] removes hardcoded alerts as data index from apm integration test #109715

Merged
merged 4 commits into from
Aug 25, 2021

Conversation

dhurley14
Copy link
Contributor

@dhurley14 dhurley14 commented Aug 23, 2021

Summary

removes hardcoded alerts as data index from apm integration test and adds integration tests for getting alerts index from rule registry route.

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@dhurley14 dhurley14 changed the title cleanup code [RAC] [APM] removes hardcoded alerts as data index from apm integration test Aug 23, 2021
@dhurley14 dhurley14 self-assigned this Aug 23, 2021
@dhurley14 dhurley14 marked this pull request as ready for review August 23, 2021 20:48
@dhurley14 dhurley14 requested a review from a team as a code owner August 23, 2021 20:48
@dhurley14 dhurley14 added the release_note:skip Skip the PR/issue when compiling release notes label Aug 23, 2021
@@ -17,7 +17,7 @@ import { registry } from './registry';
interface Config {
name: APMFtrConfigName;
license: 'basic' | 'trial';
kibanaConfig?: Record<string, string>;
kibanaConfig?: Record<string, string | string[]>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the above while I was debugging the integration tests using the following as part of the FTR kibana config and needed to pass in an array of values instead of just a string. I can remove this but figured it might be useful going forward for anybody who is debugging tests in the future.

--logging.verbose=true,
--logging.events.log=${JSON.stringify([ 'alerts', 'ruleRegistry', 'apm', 'securitySolution', 'info', 'warning', 'error', 'fatal', ])},
--logging.events.request=${JSON.stringify(['info', 'warning', 'error', 'fatal'])},
--logging.events.error='*',
--logging.events.ops=__no-ops__,

Comment on lines +84 to +86
? Object.entries(kibanaConfig).map(([key, value]) =>
Array.isArray(value) ? `--${key}=${JSON.stringify(value)}` : `--${key}=${value}`
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

related to my above comment

@dhurley14 dhurley14 added the auto-backport Deprecated - use backport:version if exact versions are needed label Aug 24, 2021
index: targetIndices[0],
});
// eslint-disable-next-line no-empty
} catch (exc) {}
Copy link
Member

Choose a reason for hiding this comment

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

can you leave a comment here why it's okay for this to fail?

Copy link
Contributor Author

@dhurley14 dhurley14 Aug 24, 2021

Choose a reason for hiding this comment

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

For sure I can add a comment to the code. Essentially it boils down to this:

When calling refresh on an index pattern .alerts-observability.apm.alerts* (as was originally the hard-coded string in this test) The response from Elasticsearch is a 200, even if no indices which match that index pattern have been created.

When calling refresh on a concrete index alias .alerts-observability.apm.alerts-default for instance, we receive a 404 error index_not_found_exception when no indices have been created which match that alias (obviously).

Since we are receiving a concrete index alias from the observability api instead of a kibana index pattern and we understand / expect that this index does not exist at certain points of the test, we can try-catch at certain points without caring if the call fails. There are points in the code where we do want to ensure we get the appropriate error message back (such as this expect you commented on)

Example..
# This request yields a 200 response
GET thisdoesnotexist*/_refresh

# Response
{
  "_shards" : {
    "total" : 0,
    "successful" : 0,
    "failed" : 0
  }
}


# This request yields a 404 error

GET thisdoesnotexist/_refresh

# Response
{
  "error" : {
    "root_cause" : [
      {
        "type" : "index_not_found_exception",
        "reason" : "no such index [thisdoesnotexist]",
        "resource.type" : "index_or_alias",
        "resource.id" : "thisdoesnotexist",
        "index_uuid" : "_na_",
        "index" : "thisdoesnotexist"
      }
    ],
    "type" : "index_not_found_exception",
    "reason" : "no such index [thisdoesnotexist]",
    "resource.type" : "index_or_alias",
    "resource.id" : "thisdoesnotexist",
    "index_uuid" : "_na_",
    "index" : "thisdoesnotexist"
  },
  "status" : 404
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: 6c5e2bf

Copy link
Member

Choose a reason for hiding this comment

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

is allow_no_indices not good enough here?

Copy link
Member

Choose a reason for hiding this comment

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

or maybe we can just add an asterisk to the end?

allow_no_indices: true,
});
} catch (exc) {
expect(exc.statusCode).to.eql(404);
Copy link
Member

Choose a reason for hiding this comment

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

there's no assertion here when the request succeeds, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch I'll update this to fail if a 200 response is received.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: 6c5e2bf

index: APM_METRIC_INDEX_NAME,
});
// eslint-disable-next-line no-empty
} catch (exc) {}
Copy link
Member

Choose a reason for hiding this comment

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

same here, comment would be great

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah I think I can undo this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: 6c5e2bf

refresh: true,
});
// eslint-disable-next-line no-empty
} catch (exc) {}
Copy link
Member

Choose a reason for hiding this comment

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

here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: 6c5e2bf

expect(beforeDataResponse.body.hits.hits.length).to.be(0);
});
} catch (exc) {
expect(exc.message).contain('index_not_found_exception');
Copy link
Member

Choose a reason for hiding this comment

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

same here, there's only an assertion when the request fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup I'll update this to fail if a 200 is received as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: 6c5e2bf

Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if this is necessary. I think the intent here was to ensure there was no data written before the alert executed, and before violations were indexed, I don't think we need to test whether the index exists here, as long as we have a different test for that (which I think we do?). My concern here would be a) that these assertions are adding to the complexity of the test, b) might cause some false negatives to trigger in certain scenarios (e.g. when the index is not cleaned up after a test run, or the implementation changes).

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @dhurley14

Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

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

Changes in x-pack/test/apm_api_integration/tests/alerts/rule_registry.ts LGTM 👍

const TEST_URL = '/internal/rac/alerts';
const ALERTS_INDEX_URL = `${TEST_URL}/index`;
const SPACE1 = 'space1';
const APM_ALERT_INDEX = '.alerts-observability-apm';
Copy link
Contributor

Choose a reason for hiding this comment

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

Note for myself: I will need to fix this name in #109567

@@ -92,6 +96,13 @@ export default function ApiTest({ getService }: FtrProviderContext) {
.get(`/api/alerts/alert/${alert.id}`)
.set('kbn-xsrf', 'foo');

const { body: targetIndices, status: targetIndicesStatus } = await getAlertsTargetIndices();
Copy link
Member

Choose a reason for hiding this comment

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

what's the purpose of this exactly? This function only cares about whether the rule was executed. There might be a scenario where the alert index does not exist, but it's okay because no alerts were written.

Copy link
Member

@dgieselaar dgieselaar left a comment

Choose a reason for hiding this comment

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

LGTM, some questions/concerns but nothing blocking. Thanks!

@dhurley14 dhurley14 merged commit 2fea917 into elastic:master Aug 25, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 25, 2021
…on test (elastic#109715)

* removes hardcoded index from apm integration tests

* adds integration tests for rule registry's get index route

* more cleanup

* fail try-catch if response is not empty, adds comments as to why index refresh catch block is empty
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 25, 2021
…on test (elastic#109715)

* removes hardcoded index from apm integration tests

* adds integration tests for rule registry's get index route

* more cleanup

* fail try-catch if response is not empty, adds comments as to why index refresh catch block is empty
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.15
7.x

The backport PRs will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Aug 26, 2021
…tegration test (#109715) (#110108)

* [RAC] [APM] removes hardcoded alerts as data index from apm integration test (#109715)

* removes hardcoded index from apm integration tests

* adds integration tests for rule registry's get index route

* more cleanup

* fail try-catch if response is not empty, adds comments as to why index refresh catch block is empty

* fix name of index

Co-authored-by: Devin W. Hurley <devin.hurley@elastic.co>
kibanamachine added a commit that referenced this pull request Aug 26, 2021
…egration test (#109715) (#110109)

* [RAC] [APM] removes hardcoded alerts as data index from apm integration test (#109715)

* removes hardcoded index from apm integration tests

* adds integration tests for rule registry's get index route

* more cleanup

* fail try-catch if response is not empty, adds comments as to why index refresh catch block is empty

* fix index name

Co-authored-by: Devin W. Hurley <devin.hurley@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:rac auto-backport Deprecated - use backport:version if exact versions are needed Feature:Observability RAC Feature:RAC label obsolete release_note:skip Skip the PR/issue when compiling release notes review Theme: rac label obsolete v7.15.0 v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants