[Response Ops] Fix Deprecated E&C ES APIs for Kibana 9.0 (#203514)

## Summary

Resolves: https://github.com/elastic/response-ops-team/issues/258

Related Issue: https://github.com/elastic/kibana-team/issues/1173

Based on the issue outlining E&C's deprecated ES usages for 9.0, it
seems like we're mostly fine to proceed with the upgrade. The only issue
that was found was the usage of a `.` pre-fixed index used in the E2E
test that triggered the `index name [.kibana-alerting-test-data] starts
with a dot '.', in the next major version, index names starting with a
dot are reserved for hidden indices and system indices` warning message.
The solution is to simply remove the `.` prefix in our tests.

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Mike Côté <mikecote@users.noreply.github.com>
This commit is contained in:
Jiawei Wu 2025-04-01 15:01:46 -06:00 committed by GitHub
parent f2aa2012fc
commit 539f77f816
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 46 additions and 46 deletions

View file

@ -179,7 +179,7 @@ function getHookedActionType() {
source: config.source,
};
logger.info(`running hook pre-save for ${JSON.stringify(body)}`);
await services.scopedClusterClient.asInternalUser.index({
await services.scopedClusterClient.asCurrentUser.index({
index: config.index,
refresh: 'wait_for',
body,
@ -206,7 +206,7 @@ function getHookedActionType() {
source: config.source,
};
logger.info(`running hook post-save for ${JSON.stringify(body)}`);
await services.scopedClusterClient.asInternalUser.index({
await services.scopedClusterClient.asCurrentUser.index({
index: config.index,
refresh: 'wait_for',
body,
@ -222,7 +222,7 @@ function getHookedActionType() {
source: config.source,
};
logger.info(`running hook post-delete for ${JSON.stringify(body)}`);
await services.scopedClusterClient.asInternalUser.index({
await services.scopedClusterClient.asCurrentUser.index({
index: config.index,
refresh: 'wait_for',
body,

View file

@ -8,7 +8,7 @@ import { omit } from 'lodash';
import type { Client } from '@elastic/elasticsearch';
import type { DeleteByQueryRequest } from '@elastic/elasticsearch/lib/api/types';
export const ES_TEST_INDEX_NAME = '.kibana-alerting-test-data';
export const ES_TEST_INDEX_NAME = 'kibana-alerting-test-data';
export class ESTestIndexTool {
constructor(

View file

@ -259,7 +259,7 @@ export default function createAlertingAndActionsTelemetryTests({ getService }: F
notify_when: 'onActiveAlert',
throttle: null,
params: {
index: '.kibana-alerting-test-data',
index: 'kibana-alerting-test-data',
reference: 'test',
},
actions: [

View file

@ -1503,7 +1503,7 @@ instanceStateValue: true
severity_improving: false,
rule: {
parameters: {
index: '.kibana-alerting-test-data',
index: 'kibana-alerting-test-data',
reference,
},
category: 'Test: Always Firing Alert As Data',
@ -1548,7 +1548,7 @@ instanceStateValue: true
severity_improving: false,
rule: {
parameters: {
index: '.kibana-alerting-test-data',
index: 'kibana-alerting-test-data',
reference,
},
category: 'Test: Always Firing Alert As Data',
@ -1609,7 +1609,7 @@ instanceStateValue: true
previous_action_group: 'default',
rule: {
parameters: {
index: '.kibana-alerting-test-data',
index: 'kibana-alerting-test-data',
reference,
},
category: 'Test: Always Firing Alert As Data',
@ -1654,7 +1654,7 @@ instanceStateValue: true
previous_action_group: 'default',
rule: {
parameters: {
index: '.kibana-alerting-test-data',
index: 'kibana-alerting-test-data',
reference,
},
category: 'Test: Always Firing Alert As Data',
@ -1763,7 +1763,7 @@ instanceStateValue: true
severity_improving: false,
rule: {
parameters: {
index: '.kibana-alerting-test-data',
index: 'kibana-alerting-test-data',
reference,
},
category: 'Test: Always Firing Alert As Data',
@ -1808,7 +1808,7 @@ instanceStateValue: true
severity_improving: false,
rule: {
parameters: {
index: '.kibana-alerting-test-data',
index: 'kibana-alerting-test-data',
reference,
},
category: 'Test: Always Firing Alert As Data',
@ -1986,7 +1986,7 @@ instanceStateValue: true
expect(doc.params).to.eql({
myParam: 'param from rule action',
index: '.kibana-alerting-test-data',
index: 'kibana-alerting-test-data',
reference: 'alert-utils-ref:1:superuser',
/**
* Param was injected by the connector adapter in

View file

@ -143,7 +143,7 @@ export default function ({ getService }: FtrProviderContext) {
actionTypeId: 'test.failing',
outcome: 'failure',
message: `action execution failure: test.failing:${createdConnector.id}: failing connector`,
errorMessage: `an error occurred while running the action: expected failure for .kibana-alerting-test-data actions-failure-1:space1; retry: true`,
errorMessage: `an error occurred while running the action: expected failure for kibana-alerting-test-data actions-failure-1:space1; retry: true`,
source: ActionExecutionSourceType.HTTP_REQUEST,
});
});

View file

@ -73,12 +73,12 @@ export default function ruleTests({ getService }: FtrProviderContext) {
await createRule({
name: 'never fire',
esqlQuery:
'from .kibana-alerting-test-data | stats c = count(date) by host.hostname, host.name, host.id | where c < 0',
'from kibana-alerting-test-data | stats c = count(date) by host.hostname, host.name, host.id | where c < 0',
});
await createRule({
name: 'always fire',
esqlQuery:
'from .kibana-alerting-test-data | stats c = count(date) by host.hostname, host.name, host.id | where c > -1',
'from kibana-alerting-test-data | stats c = count(date) by host.hostname, host.name, host.id | where c > -1',
});
const docs = await waitForDocs(2);
@ -117,13 +117,13 @@ export default function ruleTests({ getService }: FtrProviderContext) {
await createEsDocumentsInGroups(ES_GROUPS_TO_WRITE, endDate);
await createRule({
name: 'never fire',
esqlQuery: 'from .kibana-alerting-test-data | stats c = count(date) | where c < 0',
esqlQuery: 'from kibana-alerting-test-data | stats c = count(date) | where c < 0',
timeField: 'date_epoch_millis',
});
await createRule({
name: 'always fire',
esqlQuery: 'from .kibana-alerting-test-data | stats c = count(date) | where c > -1',
esqlQuery: 'from kibana-alerting-test-data | stats c = count(date) | where c > -1',
timeField: 'date_epoch_millis',
});
@ -145,7 +145,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
it('runs correctly: no matches', async () => {
await createRule({
name: 'always fire',
esqlQuery: 'from .kibana-alerting-test-data | stats c = count(date) | where c < 1',
esqlQuery: 'from kibana-alerting-test-data | stats c = count(date) | where c < 1',
});
const docs = await waitForDocs(1);
@ -167,7 +167,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
// and then recover when we add more documents.
await createRule({
name: 'fire then recovers',
esqlQuery: 'from .kibana-alerting-test-data | stats c = count(date) | where c < 1',
esqlQuery: 'from kibana-alerting-test-data | stats c = count(date) | where c < 1',
notifyWhen: 'onActionGroupChange',
timeWindowSize: RULE_INTERVAL_SECONDS,
@ -272,7 +272,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
searchType: 'esqlQuery',
timeField: 'date',
esqlQuery: {
esql: 'from .kibana-alerting-test-data | stats c = count(date) | where c < 0',
esql: 'from kibana-alerting-test-data | stats c = count(date) | where c < 0',
},
},
})
@ -303,7 +303,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
searchType: 'esqlQuery',
timeField: 'date',
esqlQuery: {
esql: 'from .kibana-alerting-test-data | stats c = count(date) | where c < 0',
esql: 'from kibana-alerting-test-data | stats c = count(date) | where c < 0',
},
},
})
@ -331,7 +331,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
threshold: [0],
searchType: 'esqlQuery',
esqlQuery: {
esql: 'from .kibana-alerting-test-data | stats c = count(date) | where c < 0',
esql: 'from kibana-alerting-test-data | stats c = count(date) | where c < 0',
},
},
})

View file

@ -151,7 +151,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
const docs = await waitForDocs(2);
const messagePattern =
/Document count is \d+.?\d* in the last 30s in .kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
/Document count is \d+.?\d* in the last 30s in kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
for (let i = 0; i < docs.length; i++) {
const doc = docs[i];
@ -269,7 +269,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
await initData();
const messagePattern =
/Document count is \d+.?\d* in the last 30s in .kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
/Document count is \d+.?\d* in the last 30s in kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
const docs = await waitForDocs(2);
for (let i = 0; i < docs.length; i++) {
@ -391,7 +391,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
await initData();
const messagePattern =
/Document count is \d+.?\d* in the last 30s for group-\d+ in .kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
/Document count is \d+.?\d* in the last 30s for group-\d+ in kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
const titlePattern = /rule 'always fire' matched query for group group-\d/;
const conditionPattern =
/Number of matching documents for group "group-\d" is greater than -1/;
@ -478,7 +478,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
await initData();
const messagePattern =
/Document count is \d+.?\d* in the last 30s for group-\d+,\d+ in .kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
/Document count is \d+.?\d* in the last 30s for group-\d+,\d+ in kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
const titlePattern = /rule 'always fire' matched query for group group-\d+,\d+/;
const conditionPattern =
/Number of matching documents for group "group-\d+,\d+" is greater than -1/;
@ -608,7 +608,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
const titlePattern = /rule 'always fire' matched query for group group-\d/;
expect(title).to.match(titlePattern);
const messagePattern =
/Document count is \d+.?\d* in the last 30s for group-\d+ in .kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
/Document count is \d+.?\d* in the last 30s for group-\d+ in kibana-alerting-test-data (?:index|data view). Alert when greater than -1./;
expect(message).to.match(messagePattern);
expect(hits).not.to.be.empty();
@ -696,7 +696,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
expect(name).to.be('always fire');
expect(title).to.be(`rule 'always fire' matched query`);
const messagePattern =
/Document count is \d+.?\d* in the last 30s in .kibana-alerting-test-data (?:index|data view). ./;
/Document count is \d+.?\d* in the last 30s in kibana-alerting-test-data (?:index|data view). ./;
expect(message).to.match(messagePattern);
expect(hits).not.to.be.empty();
@ -806,7 +806,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
expect(name).to.be('fires once');
expect(title).to.be(`rule 'fires once' matched query`);
const messagePattern =
/Document count is \d+.?\d* in the last 30s in .kibana-alerting-test-data (?:index|data view). Alert when greater than or equal to 0./;
/Document count is \d+.?\d* in the last 30s in kibana-alerting-test-data (?:index|data view). Alert when greater than or equal to 0./;
expect(message).to.match(messagePattern);
expect(hits).not.to.be.empty();
expect(previousTimestamp).to.be.empty();
@ -866,7 +866,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
expect(name).to.be('always fire');
expect(title).to.be(`rule 'always fire' matched query`);
const messagePattern =
/Document count is \d+.?\d* in the last 30s in .kibana-alerting-test-data (?:index|data view). Alert when less than 1./;
/Document count is \d+.?\d* in the last 30s in kibana-alerting-test-data (?:index|data view). Alert when less than 1./;
expect(message).to.match(messagePattern);
expect(hits).to.be.empty();
@ -944,7 +944,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
expect(activeTitle).to.be(`rule 'fire then recovers' matched query`);
expect(activeValue).to.be('0');
expect(activeMessage).to.match(
/Document count is \d+.?\d* in the last 6s in .kibana-alerting-test-data (?:index|data view). Alert when less than 1./
/Document count is \d+.?\d* in the last 6s in kibana-alerting-test-data (?:index|data view). Alert when less than 1./
);
await createEsDocumentsInGroups(1, endDate);
@ -959,7 +959,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
expect(recoveredName).to.be('fire then recovers');
expect(recoveredTitle).to.be(`rule 'fire then recovers' recovered`);
expect(recoveredMessage).to.match(
/Document count is \d+.?\d* in the last 6s in .kibana-alerting-test-data (?:index|data view). Alert when less than 1./
/Document count is \d+.?\d* in the last 6s in kibana-alerting-test-data (?:index|data view). Alert when less than 1./
);
})
);
@ -1101,7 +1101,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
const docs = await waitForDocs(2);
const messagePattern =
/Document count is \d+.?\d* in the last 300s in .kibana-alerting-test-data (?:index|data view). Alert when greater than 0./;
/Document count is \d+.?\d* in the last 300s in kibana-alerting-test-data (?:index|data view). Alert when greater than 0./;
expect(docs[0]._source.hits.length).greaterThan(0);
expect(docs[0]._source.params.message).to.match(messagePattern);
@ -1125,7 +1125,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
const docs = await waitForDocs(2);
const messagePattern =
/Document count is \d+.?\d* in the last 300s in .kibana-alerting-test-data (?:index|data view). Alert when greater than 0./;
/Document count is \d+.?\d* in the last 300s in kibana-alerting-test-data (?:index|data view). Alert when greater than 0./;
expect(docs[0]._source.hits.length).greaterThan(0);
expect(docs[0]._source.params.message).to.match(messagePattern);
@ -1150,7 +1150,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
const docs = await waitForDocs(2);
const messagePattern =
/Document count is \d+.?\d* in the last 300s in .kibana-alerting-test-data (?:index|data view). Alert when greater than 0./;
/Document count is \d+.?\d* in the last 300s in kibana-alerting-test-data (?:index|data view). Alert when greater than 0./;
expect(docs[0]._source.hits.length).greaterThan(0);
expect(docs[0]._source.params.message).to.match(messagePattern);
@ -1179,7 +1179,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
expect(docs[0]._source.hits.length).greaterThan(0);
const messagePattern =
/Document count is \d+.?\d* in the last 30s in .kibana-alerting-test-data (?:index|data view). Alert when greater than 0./;
/Document count is \d+.?\d* in the last 30s in kibana-alerting-test-data (?:index|data view). Alert when greater than 0./;
expect(docs[0]._source.params.message).to.match(messagePattern);
expect(docs[1]._source.hits.length).to.be(0);

View file

@ -34,7 +34,7 @@
"actionTypeId": "test.index-record",
"group": "default",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"message": "alertId: {{alertId}},\nalertName: {{alertName}},\nspaceId: {{spaceId}},\ntags: {{tags}},\nalertInstanceId: {{alertInstanceId}},\ninstanceContextValue: {{context.instanceContextValue}},\ninstanceStateValue: {{state.instanceStateValue}}",
"reference": "alert:migrated-to-7.10:space_1_all_alerts_none_actions"
}
@ -52,7 +52,7 @@
],
"name": "abc",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"reference": "alert:migrated-to-7.10:space_1_all_alerts_none_actions"
},
"schedule": {
@ -96,7 +96,7 @@
"actionTypeId": "test.index-record",
"group": "default",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"message": "alertId: {{alertId}},\nalertName: {{alertName}},\nspaceId: {{spaceId}},\ntags: {{tags}},\nalertInstanceId: {{alertInstanceId}},\ninstanceContextValue: {{context.instanceContextValue}},\ninstanceStateValue: {{state.instanceStateValue}}",
"reference": "alert:migrated-to-7.10:superuser"
}
@ -114,7 +114,7 @@
],
"name": "abc",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"reference": "alert:migrated-to-7.10:superuser"
},
"schedule": {
@ -158,7 +158,7 @@
"actionTypeId": "test.index-record",
"group": "default",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"message": "alertId: {{alertId}},\nalertName: {{alertName}},\nspaceId: {{spaceId}},\ntags: {{tags}},\nalertInstanceId: {{alertInstanceId}},\ninstanceContextValue: {{context.instanceContextValue}},\ninstanceStateValue: {{state.instanceStateValue}}",
"reference": "alert:migrated-to-7.10:space_1_all_with_restricted_fixture"
}
@ -176,7 +176,7 @@
],
"name": "abc",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"reference": "alert:migrated-to-7.10:space_1_all_with_restricted_fixture"
},
"schedule": {
@ -220,7 +220,7 @@
"actionTypeId": "test.index-record",
"group": "default",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"message": "alertId: {{alertId}},\nalertName: {{alertName}},\nspaceId: {{spaceId}},\ntags: {{tags}},\nalertInstanceId: {{alertInstanceId}},\ninstanceContextValue: {{context.instanceContextValue}},\ninstanceStateValue: {{state.instanceStateValue}}",
"reference": "alert:migrated-to-7.10:space_1_all"
}
@ -238,7 +238,7 @@
],
"name": "abc",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"reference": "alert:migrated-to-7.10:space_1_all"
},
"schedule": {
@ -282,7 +282,7 @@
"actionTypeId": "test.index-record",
"group": "default",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"message": "alertId: {{alertId}},\nalertName: {{alertName}},\nspaceId: {{spaceId}},\ntags: {{tags}},\nalertInstanceId: {{alertInstanceId}},\ninstanceContextValue: {{context.instanceContextValue}},\ninstanceStateValue: {{state.instanceStateValue}}",
"reference": "alert:migrated-to-7.10:global_read"
}
@ -300,7 +300,7 @@
],
"name": "abc",
"params": {
"index": ".kibana-alerting-test-data",
"index": "kibana-alerting-test-data",
"reference": "alert:migrated-to-7.10:global_read"
},
"schedule": {