mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
# Backport This will backport the following commits from `main` to `8.6`: - [[RAM] Fix bulk edit references (#153370)](https://github.com/elastic/kibana/pull/153370) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Xavier Mouligneau","email":"xavier.mouligneau@elastic.co"},"sourceCommit":{"committedDate":"2023-03-23T01:09:22Z","message":"[RAM] Fix bulk edit references (#153370)\n\n## Summary\r\n\r\nFix: https://github.com/elastic/kibana/issues/152961\r\nhttps://github.com/elastic/kibana/issues/152960\r\nhttps://github.com/elastic/kibana/issues/153175\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"58b36366cae363a64697df7d2e131fbc919af899","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","impact:high","v8.5.4","v8.8.0","v8.6.3","v8.7.1"],"number":153370,"url":"https://github.com/elastic/kibana/pull/153370","mergeCommit":{"message":"[RAM] Fix bulk edit references (#153370)\n\n## Summary\r\n\r\nFix: https://github.com/elastic/kibana/issues/152961\r\nhttps://github.com/elastic/kibana/issues/152960\r\nhttps://github.com/elastic/kibana/issues/153175\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"58b36366cae363a64697df7d2e131fbc919af899"}},"sourceBranch":"main","suggestedTargetBranches":["8.5","8.6","8.7"],"targetPullRequestStates":[{"branch":"8.5","label":"v8.5.4","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/153370","number":153370,"mergeCommit":{"message":"[RAM] Fix bulk edit references (#153370)\n\n## Summary\r\n\r\nFix: https://github.com/elastic/kibana/issues/152961\r\nhttps://github.com/elastic/kibana/issues/152960\r\nhttps://github.com/elastic/kibana/issues/153175\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"58b36366cae363a64697df7d2e131fbc919af899"}},{"branch":"8.6","label":"v8.6.3","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.7","label":"v8.7.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
37e622de0d
commit
30123023ce
2 changed files with 130 additions and 3 deletions
|
@ -2499,9 +2499,13 @@ export class RulesClient {
|
|||
}
|
||||
}
|
||||
|
||||
const ruleParams = paramsModifier
|
||||
? await paramsModifier(attributes.params as Params)
|
||||
: attributes.params;
|
||||
const params = this.injectReferencesIntoParams<Params, RuleTypeParams>(
|
||||
rule.id,
|
||||
ruleType,
|
||||
attributes.params,
|
||||
rule.references || []
|
||||
);
|
||||
const ruleParams = paramsModifier ? await paramsModifier(params) : params;
|
||||
|
||||
// validate rule params
|
||||
const validatedAlertTypeParams = validateRuleTypeParams(
|
||||
|
|
|
@ -18,6 +18,8 @@ import {
|
|||
} from '../../../../common/lib';
|
||||
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
|
||||
|
||||
const SOURCE_LOG_DATA_INDEX = 'log-bulk-edit-rule';
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default function createUpdateTests({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
|
@ -608,5 +610,126 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe('do NOT delete reference for rule type like', () => {
|
||||
const es = getService('es');
|
||||
|
||||
const createDataView = async (dataView: string) => {
|
||||
return await supertest
|
||||
.post(`/api/data_views/data_view`)
|
||||
.set('kbn-xsrf', 'foo')
|
||||
.send({ data_view: { title: dataView, timeFieldName: '@timestamp' } })
|
||||
.expect(200);
|
||||
};
|
||||
|
||||
const deleteDataView = async (dataViewId: string) => {
|
||||
return await supertest
|
||||
.delete(`/api/data_views/data_view/${dataViewId}`)
|
||||
.set('kbn-xsrf', 'foo')
|
||||
.expect(200);
|
||||
};
|
||||
|
||||
const createSourceIndex = () => {
|
||||
es.index({
|
||||
index: SOURCE_LOG_DATA_INDEX,
|
||||
body: {
|
||||
settings: { number_of_shards: 1 },
|
||||
mappings: {
|
||||
properties: {
|
||||
'@timestamp': { type: 'date' },
|
||||
message: { type: 'keyword' },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
await createSourceIndex();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await es.transport.request({
|
||||
path: `${SOURCE_LOG_DATA_INDEX}`,
|
||||
method: 'DELETE',
|
||||
});
|
||||
});
|
||||
|
||||
it('.esquery', async () => {
|
||||
const dv = await createDataView(SOURCE_LOG_DATA_INDEX);
|
||||
const space1 = UserAtSpaceScenarios[1].space.id;
|
||||
const { body: createdRule } = await supertest
|
||||
.post(`${getUrlPrefix(space1)}/api/alerting/rule`)
|
||||
.set('kbn-xsrf', 'foo')
|
||||
.send(
|
||||
getTestRuleData({
|
||||
params: {
|
||||
searchConfiguration: {
|
||||
query: {
|
||||
query: '_id:*',
|
||||
language: 'kuery',
|
||||
},
|
||||
index: dv.body.data_view.id,
|
||||
},
|
||||
searchType: 'searchSource',
|
||||
timeWindowSize: 5,
|
||||
timeWindowUnit: 'm',
|
||||
threshold: [1000],
|
||||
thresholdComparator: '>',
|
||||
size: 100,
|
||||
excludeHitsFromPreviousRun: true,
|
||||
},
|
||||
consumer: 'alerts',
|
||||
schedule: { interval: '1m' },
|
||||
tags: [],
|
||||
name: 'Es Query',
|
||||
rule_type_id: '.es-query',
|
||||
actions: [],
|
||||
})
|
||||
)
|
||||
.expect(200);
|
||||
objectRemover.add(space1, createdRule.id, 'rule', 'alerting');
|
||||
|
||||
const searchRule = () =>
|
||||
es.search<{ references: unknown }>({
|
||||
index: '.kibana*',
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{
|
||||
term: {
|
||||
_id: `alert:${createdRule.id}`,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
fields: ['alert.params', 'references'],
|
||||
});
|
||||
|
||||
const {
|
||||
hits: { hits: alertHitsV1 },
|
||||
} = await searchRule();
|
||||
|
||||
await supertest
|
||||
.post(`${getUrlPrefix(space1)}/internal/alerting/rules/_bulk_edit`)
|
||||
.set('kbn-xsrf', 'foo')
|
||||
.send({
|
||||
ids: [createdRule.id],
|
||||
operations: [{ operation: 'set', field: 'apiKey' }],
|
||||
});
|
||||
|
||||
const {
|
||||
hits: { hits: alertHitsV2 },
|
||||
} = await searchRule();
|
||||
|
||||
expect(alertHitsV1[0].fields).to.eql(alertHitsV2[0].fields);
|
||||
expect(alertHitsV1[0]?._source?.references ?? true).to.eql(
|
||||
alertHitsV2[0]?._source?.references ?? false
|
||||
);
|
||||
|
||||
await deleteDataView(dv.body.data_view.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue