mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[8.8] [RAM] Fix updates also updating createdAt/createdBy for maintenance window and rules settings (#158028) (#158081)
# Backport This will backport the following commits from `main` to `8.8`: - [[RAM] Fix updates also updating createdAt/createdBy for maintenance window and rules settings (#158028)](https://github.com/elastic/kibana/pull/158028) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jiawei Wu","email":"74562234+JiaweiWu@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-05-18T14:13:15Z","message":"[RAM] Fix updates also updating createdAt/createdBy for maintenance window and rules settings (#158028)\n\n## Summary\r\n\r\nFix a small bug where our update functions were also updating the\r\n`createdBy/createdAt` fields for some of our saved objects, we should\r\njust be updating the `updatedBy/updatedAt` fields\r\n\r\n### Checklist\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","sha":"833ece60d7cd77cb58f694215aef9c289f0fd284","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","Feature:Alerting/RulesFramework","v8.9.0","v8.8.1"],"number":158028,"url":"https://github.com/elastic/kibana/pull/158028","mergeCommit":{"message":"[RAM] Fix updates also updating createdAt/createdBy for maintenance window and rules settings (#158028)\n\n## Summary\r\n\r\nFix a small bug where our update functions were also updating the\r\n`createdBy/createdAt` fields for some of our saved objects, we should\r\njust be updating the `updatedBy/updatedAt` fields\r\n\r\n### Checklist\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","sha":"833ece60d7cd77cb58f694215aef9c289f0fd284"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/158028","number":158028,"mergeCommit":{"message":"[RAM] Fix updates also updating createdAt/createdBy for maintenance window and rules settings (#158028)\n\n## Summary\r\n\r\nFix a small bug where our update functions were also updating the\r\n`createdBy/createdAt` fields for some of our saved objects, we should\r\njust be updating the `updatedBy/updatedAt` fields\r\n\r\n### Checklist\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","sha":"833ece60d7cd77cb58f694215aef9c289f0fd284"}},{"branch":"8.8","label":"v8.8.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Jiawei Wu <74562234+JiaweiWu@users.noreply.github.com>
This commit is contained in:
parent
961fc971fb
commit
8d8034cc60
9 changed files with 34 additions and 16 deletions
|
@ -85,7 +85,8 @@ describe('MaintenanceWindowClient - archive', () => {
|
|||
{ gte: '2023-03-05T00:00:00.000Z', lte: '2023-03-05T01:00:00.000Z' },
|
||||
],
|
||||
expirationDate: new Date().toISOString(),
|
||||
...updatedMetadata,
|
||||
updatedAt: updatedMetadata.updatedAt,
|
||||
updatedBy: updatedMetadata.updatedBy,
|
||||
},
|
||||
{ version: '123' }
|
||||
);
|
||||
|
@ -132,7 +133,8 @@ describe('MaintenanceWindowClient - archive', () => {
|
|||
{ gte: '2023-03-05T00:00:00.000Z', lte: '2023-03-05T01:00:00.000Z' },
|
||||
],
|
||||
expirationDate: moment.utc().add(1, 'year').toISOString(),
|
||||
...updatedMetadata,
|
||||
updatedAt: updatedMetadata.updatedAt,
|
||||
updatedBy: updatedMetadata.updatedBy,
|
||||
},
|
||||
{ version: '123' }
|
||||
);
|
||||
|
@ -182,7 +184,8 @@ describe('MaintenanceWindowClient - archive', () => {
|
|||
...mockMaintenanceWindow,
|
||||
events: modifiedEvents.slice(0, 4),
|
||||
expirationDate: new Date().toISOString(),
|
||||
...updatedMetadata,
|
||||
updatedAt: updatedMetadata.updatedAt,
|
||||
updatedBy: updatedMetadata.updatedBy,
|
||||
},
|
||||
{ version: '123' }
|
||||
);
|
||||
|
|
|
@ -77,7 +77,8 @@ async function archiveWithOCC(
|
|||
...attributes,
|
||||
events,
|
||||
expirationDate,
|
||||
...modificationMetadata,
|
||||
updatedAt: modificationMetadata.updatedAt,
|
||||
updatedBy: modificationMetadata.updatedBy,
|
||||
},
|
||||
{
|
||||
version,
|
||||
|
|
|
@ -105,7 +105,8 @@ async function finishWithOCC(
|
|||
{
|
||||
events: eventsWithFinishedEvent,
|
||||
expirationDate: expirationDate.toISOString(),
|
||||
...modificationMetadata,
|
||||
updatedAt: modificationMetadata.updatedAt,
|
||||
updatedBy: modificationMetadata.updatedBy,
|
||||
},
|
||||
{
|
||||
version,
|
||||
|
|
|
@ -48,7 +48,7 @@ const mockContext: jest.Mocked<MaintenanceWindowClientContext> = {
|
|||
|
||||
describe('MaintenanceWindowClient - update', () => {
|
||||
beforeEach(() => {
|
||||
mockContext.getModificationMetadata.mockResolvedValueOnce(updatedMetadata);
|
||||
mockContext.getModificationMetadata.mockResolvedValue(updatedMetadata);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -101,7 +101,10 @@ describe('MaintenanceWindowClient - update', () => {
|
|||
{ gte: '2023-04-01T23:00:00.000Z', lte: '2023-04-02T01:00:00.000Z' }, // Daylight savings
|
||||
],
|
||||
expirationDate: moment(new Date(secondTimestamp)).tz('UTC').add(1, 'year').toISOString(),
|
||||
...updatedMetadata,
|
||||
createdAt: '2023-02-26T00:00:00.000Z',
|
||||
createdBy: 'test-user',
|
||||
updatedAt: updatedMetadata.updatedAt,
|
||||
updatedBy: updatedMetadata.updatedBy,
|
||||
},
|
||||
{ id: 'test-id' }
|
||||
);
|
||||
|
|
|
@ -84,7 +84,8 @@ async function updateWithOCC(
|
|||
...(typeof enabled === 'boolean' ? { enabled } : {}),
|
||||
expirationDate,
|
||||
events,
|
||||
...modificationMetadata,
|
||||
updatedBy: modificationMetadata.updatedBy,
|
||||
updatedAt: modificationMetadata.updatedAt,
|
||||
};
|
||||
|
||||
// We are deleting and then creating rather than updating because SO.update
|
||||
|
|
|
@ -29,9 +29,9 @@ const getMockRulesSettings = (): RulesSettings => {
|
|||
lookBackWindow: DEFAULT_FLAPPING_SETTINGS.lookBackWindow,
|
||||
statusChangeThreshold: DEFAULT_FLAPPING_SETTINGS.statusChangeThreshold,
|
||||
createdBy: 'test name',
|
||||
createdAt: '2023-03-24T00:00:00.000Z',
|
||||
updatedBy: 'test name',
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedAt: '2023-03-24T00:00:00.000Z',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -50,7 +50,17 @@ const rulesSettingsFlappingClientParams: jest.Mocked<RulesSettingsFlappingClient
|
|||
savedObjectsClient,
|
||||
};
|
||||
|
||||
const updatedMetadata = {
|
||||
createdAt: '2023-03-26T00:00:00.000Z',
|
||||
updatedAt: '2023-03-26T00:00:00.000Z',
|
||||
createdBy: 'updated-user',
|
||||
updatedBy: 'updated-user',
|
||||
};
|
||||
|
||||
describe('RulesSettingsFlappingClient', () => {
|
||||
beforeEach(() =>
|
||||
rulesSettingsFlappingClientParams.getModificationMetadata.mockResolvedValue(updatedMetadata)
|
||||
);
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers();
|
||||
jest.setSystemTime(new Date(mockDateString));
|
||||
|
@ -115,10 +125,10 @@ describe('RulesSettingsFlappingClient', () => {
|
|||
enabled: false,
|
||||
lookBackWindow: 19,
|
||||
statusChangeThreshold: 3,
|
||||
updatedAt: '2023-03-26T00:00:00.000Z',
|
||||
updatedBy: 'updated-user',
|
||||
createdBy: 'test name',
|
||||
updatedBy: 'test name',
|
||||
createdAt: expect.any(String),
|
||||
updatedAt: expect.any(String),
|
||||
createdAt: '2023-03-24T00:00:00.000Z',
|
||||
}),
|
||||
},
|
||||
{ version: '123' }
|
||||
|
|
|
@ -92,7 +92,8 @@ export class RulesSettingsFlappingClient {
|
|||
flapping: {
|
||||
...attributes.flapping,
|
||||
...newFlappingProperties,
|
||||
...modificationMetadata,
|
||||
updatedAt: modificationMetadata.updatedAt,
|
||||
updatedBy: modificationMetadata.updatedBy,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -57,7 +57,6 @@ export default function getFlappingSettingsTests({ getService }: FtrProviderCont
|
|||
expect(response.body.status_change_threshold).to.eql(
|
||||
DEFAULT_FLAPPING_SETTINGS.statusChangeThreshold
|
||||
);
|
||||
expect(response.body.created_by).to.be.a('string');
|
||||
expect(response.body.updated_by).to.be.a('string');
|
||||
expect(Date.parse(response.body.created_at)).to.be.greaterThan(0);
|
||||
expect(Date.parse(response.body.updated_at)).to.be.greaterThan(0);
|
||||
|
|
|
@ -53,7 +53,6 @@ export default function updateFlappingSettingsTest({ getService }: FtrProviderCo
|
|||
expect(response.body.enabled).to.eql(false);
|
||||
expect(response.body.look_back_window).to.eql(20);
|
||||
expect(response.body.status_change_threshold).to.eql(20);
|
||||
expect(response.body.created_by).to.eql(user.username);
|
||||
expect(response.body.updated_by).to.eql(user.username);
|
||||
expect(Date.parse(response.body.created_at)).to.be.greaterThan(0);
|
||||
expect(Date.parse(response.body.updated_at)).to.be.greaterThan(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue