mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
chore: register integration events in Datadog integration (#7635)
https://linear.app/unleash/issue/2-2461/register-integration-events-datadog Registers integration events in the **Datadog** integration. Similar to: - #7634 - #7631 - #7626 - #7621
This commit is contained in:
parent
e07ded9455
commit
47ff73afb2
@ -1,18 +1,18 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Should call datadog webhook for archived toggle 1`] = `"{"text":"%%% \\n *some@user.com* archived *some-toggle* in project ** \\n %%% ","title":"Unleash notification update"}"`;
|
exports[`Datadog integration Should call datadog webhook for archived toggle 1`] = `"{"text":"%%% \\n *some@user.com* archived *some-toggle* in project ** \\n %%% ","title":"Unleash notification update"}"`;
|
||||||
|
|
||||||
exports[`Should call datadog webhook for archived toggle with project info 1`] = `"{"text":"%%% \\n *some@user.com* archived *some-toggle* in project *[some-project](http://some-url.com/projects/some-project)* \\n %%% ","title":"Unleash notification update"}"`;
|
exports[`Datadog integration Should call datadog webhook for archived toggle with project info 1`] = `"{"text":"%%% \\n *some@user.com* archived *some-toggle* in project *[some-project](http://some-url.com/projects/some-project)* \\n %%% ","title":"Unleash notification update"}"`;
|
||||||
|
|
||||||
exports[`Should call datadog webhook 1`] = `"{"text":"%%% \\n *some@user.com* created *[some-toggle](http://some-url.com/projects//features/some-toggle)* in project ** \\n %%% ","title":"Unleash notification update"}"`;
|
exports[`Datadog integration Should call datadog webhook 1`] = `"{"text":"%%% \\n *some@user.com* created *[some-toggle](http://some-url.com/projects//features/some-toggle)* in project ** \\n %%% ","title":"Unleash notification update"}"`;
|
||||||
|
|
||||||
exports[`Should call datadog webhook for toggled environment 1`] = `"{"text":"%%% \\n *some@user.com* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update"}"`;
|
exports[`Datadog integration Should call datadog webhook for toggled environment 1`] = `"{"text":"%%% \\n *some@user.com* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update"}"`;
|
||||||
|
|
||||||
exports[`Should call datadog webhook with JSON when template set 1`] = `"{"text":"{\\n \\"event\\": \\"feature-created\\",\\n \\"createdBy\\": \\"some@user.com\\"\\n}","title":"Unleash notification update"}"`;
|
exports[`Datadog integration Should call datadog webhook with JSON when template set 1`] = `"{"text":"{\\n \\"event\\": \\"feature-created\\",\\n \\"createdBy\\": \\"some@user.com\\"\\n}","title":"Unleash notification update"}"`;
|
||||||
|
|
||||||
exports[`Should include customHeaders in headers when calling service 1`] = `"{"text":"%%% \\n *some@user.com* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update"}"`;
|
exports[`Datadog integration Should include customHeaders in headers when calling service 1`] = `"{"text":"%%% \\n *some@user.com* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update"}"`;
|
||||||
|
|
||||||
exports[`Should include customHeaders in headers when calling service 2`] = `
|
exports[`Datadog integration Should include customHeaders in headers when calling service 2`] = `
|
||||||
{
|
{
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"DD-API-KEY": "fakeKey",
|
"DD-API-KEY": "fakeKey",
|
||||||
@ -20,9 +20,9 @@ exports[`Should include customHeaders in headers when calling service 2`] = `
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Should not include source_type_name when included in the config 1`] = `"{"text":"%%% \\n *some@user.com* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update","source_type_name":"my-custom-source-type"}"`;
|
exports[`Datadog integration Should not include source_type_name when included in the config 1`] = `"{"text":"%%% \\n *some@user.com* disabled *[some-toggle](http://some-url.com/projects/default/features/some-toggle)* for the *development* environment in project *[default](http://some-url.com/projects/default)* \\n %%% ","title":"Unleash notification update","source_type_name":"my-custom-source-type"}"`;
|
||||||
|
|
||||||
exports[`Should not include source_type_name when included in the config 2`] = `
|
exports[`Datadog integration Should not include source_type_name when included in the config 2`] = `
|
||||||
{
|
{
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"DD-API-KEY": "fakeKey",
|
"DD-API-KEY": "fakeKey",
|
||||||
|
@ -9,10 +9,15 @@ import type { Logger } from '../logger';
|
|||||||
import DatadogAddon from './datadog';
|
import DatadogAddon from './datadog';
|
||||||
|
|
||||||
import noLogger from '../../test/fixtures/no-logger';
|
import noLogger from '../../test/fixtures/no-logger';
|
||||||
import type { IAddonConfig, IFlagResolver } from '../types';
|
import {
|
||||||
|
serializeDates,
|
||||||
|
type IAddonConfig,
|
||||||
|
type IFlagResolver,
|
||||||
|
} from '../types';
|
||||||
import type { IntegrationEventsService } from '../services';
|
import type { IntegrationEventsService } from '../services';
|
||||||
|
|
||||||
let fetchRetryCalls: any[] = [];
|
let fetchRetryCalls: any[] = [];
|
||||||
|
const registerEventMock = jest.fn();
|
||||||
|
|
||||||
const INTEGRATION_ID = 1337;
|
const INTEGRATION_ID = 1337;
|
||||||
const ARGS: IAddonConfig = {
|
const ARGS: IAddonConfig = {
|
||||||
@ -40,207 +45,266 @@ jest.mock(
|
|||||||
retries,
|
retries,
|
||||||
backoff,
|
backoff,
|
||||||
});
|
});
|
||||||
return Promise.resolve({ status: 200 });
|
return Promise.resolve({ ok: true, status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
async registerEvent(_) {
|
async registerEvent(event) {
|
||||||
return Promise.resolve();
|
return registerEventMock(event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
test('Should call datadog webhook', async () => {
|
describe('Datadog integration', () => {
|
||||||
const addon = new DatadogAddon(ARGS);
|
beforeEach(() => {
|
||||||
const event: IEvent = {
|
registerEventMock.mockClear();
|
||||||
id: 1,
|
});
|
||||||
createdAt: new Date(),
|
|
||||||
type: FEATURE_CREATED,
|
|
||||||
createdBy: 'some@user.com',
|
|
||||||
createdByUserId: -1337,
|
|
||||||
featureName: 'some-toggle',
|
|
||||||
data: {
|
|
||||||
name: 'some-toggle',
|
|
||||||
enabled: false,
|
|
||||||
strategies: [{ name: 'default' }],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const parameters = {
|
test('Should call datadog webhook', async () => {
|
||||||
url: 'http://api.datadoghq.com/api/v1/events',
|
const addon = new DatadogAddon(ARGS);
|
||||||
apiKey: 'fakeKey',
|
const event: IEvent = {
|
||||||
};
|
id: 1,
|
||||||
|
createdAt: new Date(),
|
||||||
|
type: FEATURE_CREATED,
|
||||||
|
createdBy: 'some@user.com',
|
||||||
|
createdByUserId: -1337,
|
||||||
|
featureName: 'some-toggle',
|
||||||
|
data: {
|
||||||
|
name: 'some-toggle',
|
||||||
|
enabled: false,
|
||||||
|
strategies: [{ name: 'default' }],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
const parameters = {
|
||||||
expect(fetchRetryCalls.length).toBe(1);
|
url: 'http://api.datadoghq.com/api/v1/events',
|
||||||
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
apiKey: 'fakeKey',
|
||||||
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
};
|
||||||
});
|
|
||||||
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
||||||
test('Should call datadog webhook for archived toggle', async () => {
|
expect(fetchRetryCalls.length).toBe(1);
|
||||||
const addon = new DatadogAddon(ARGS);
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
||||||
const event: IEvent = {
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
id: 2,
|
});
|
||||||
createdAt: new Date(),
|
|
||||||
type: FEATURE_ARCHIVED,
|
test('Should call datadog webhook for archived toggle', async () => {
|
||||||
createdBy: 'some@user.com',
|
const addon = new DatadogAddon(ARGS);
|
||||||
createdByUserId: -1337,
|
const event: IEvent = {
|
||||||
featureName: 'some-toggle',
|
id: 2,
|
||||||
data: {
|
createdAt: new Date(),
|
||||||
name: 'some-toggle',
|
type: FEATURE_ARCHIVED,
|
||||||
},
|
createdBy: 'some@user.com',
|
||||||
};
|
createdByUserId: -1337,
|
||||||
|
featureName: 'some-toggle',
|
||||||
const parameters = {
|
data: {
|
||||||
url: 'http://api.datadoghq.com/api/v1/events',
|
name: 'some-toggle',
|
||||||
apiKey: 'fakeKey',
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
const parameters = {
|
||||||
expect(fetchRetryCalls.length).toBe(1);
|
url: 'http://api.datadoghq.com/api/v1/events',
|
||||||
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
apiKey: 'fakeKey',
|
||||||
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
};
|
||||||
});
|
|
||||||
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
||||||
test('Should call datadog webhook for archived toggle with project info', async () => {
|
expect(fetchRetryCalls.length).toBe(1);
|
||||||
const addon = new DatadogAddon(ARGS);
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
||||||
const event: IEvent = {
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
id: 2,
|
});
|
||||||
createdAt: new Date(),
|
|
||||||
type: FEATURE_ARCHIVED,
|
test('Should call datadog webhook for archived toggle with project info', async () => {
|
||||||
createdBy: 'some@user.com',
|
const addon = new DatadogAddon(ARGS);
|
||||||
featureName: 'some-toggle',
|
const event: IEvent = {
|
||||||
createdByUserId: -1337,
|
id: 2,
|
||||||
project: 'some-project',
|
createdAt: new Date(),
|
||||||
data: {
|
type: FEATURE_ARCHIVED,
|
||||||
name: 'some-toggle',
|
createdBy: 'some@user.com',
|
||||||
},
|
featureName: 'some-toggle',
|
||||||
};
|
createdByUserId: -1337,
|
||||||
|
project: 'some-project',
|
||||||
const parameters = {
|
data: {
|
||||||
url: 'http://api.datadoghq.com/api/v1/events',
|
name: 'some-toggle',
|
||||||
apiKey: 'fakeKey',
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
const parameters = {
|
||||||
expect(fetchRetryCalls.length).toBe(1);
|
url: 'http://api.datadoghq.com/api/v1/events',
|
||||||
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
apiKey: 'fakeKey',
|
||||||
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
};
|
||||||
});
|
|
||||||
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
||||||
test('Should call datadog webhook for toggled environment', async () => {
|
expect(fetchRetryCalls.length).toBe(1);
|
||||||
const addon = new DatadogAddon(ARGS);
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
||||||
const event: IEvent = {
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
id: 2,
|
});
|
||||||
createdAt: new Date(),
|
|
||||||
type: FEATURE_ENVIRONMENT_DISABLED,
|
test('Should call datadog webhook for toggled environment', async () => {
|
||||||
createdBy: 'some@user.com',
|
const addon = new DatadogAddon(ARGS);
|
||||||
createdByUserId: -1337,
|
const event: IEvent = {
|
||||||
environment: 'development',
|
id: 2,
|
||||||
project: 'default',
|
createdAt: new Date(),
|
||||||
featureName: 'some-toggle',
|
type: FEATURE_ENVIRONMENT_DISABLED,
|
||||||
data: {
|
createdBy: 'some@user.com',
|
||||||
name: 'some-toggle',
|
createdByUserId: -1337,
|
||||||
},
|
environment: 'development',
|
||||||
};
|
project: 'default',
|
||||||
|
featureName: 'some-toggle',
|
||||||
const parameters = {
|
data: {
|
||||||
url: 'http://hooks.slack.com',
|
name: 'some-toggle',
|
||||||
apiKey: 'fakeKey',
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
const parameters = {
|
||||||
expect(fetchRetryCalls).toHaveLength(1);
|
url: 'http://hooks.slack.com',
|
||||||
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
apiKey: 'fakeKey',
|
||||||
expect(fetchRetryCalls[0].options.body).toMatch(/disabled/);
|
};
|
||||||
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
|
||||||
});
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
||||||
|
expect(fetchRetryCalls).toHaveLength(1);
|
||||||
test('Should include customHeaders in headers when calling service', async () => {
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
||||||
const addon = new DatadogAddon(ARGS);
|
expect(fetchRetryCalls[0].options.body).toMatch(/disabled/);
|
||||||
const event: IEvent = {
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
id: 2,
|
});
|
||||||
createdAt: new Date(),
|
|
||||||
type: FEATURE_ENVIRONMENT_DISABLED,
|
test('Should include customHeaders in headers when calling service', async () => {
|
||||||
createdBy: 'some@user.com',
|
const addon = new DatadogAddon(ARGS);
|
||||||
environment: 'development',
|
const event: IEvent = {
|
||||||
createdByUserId: -1337,
|
id: 2,
|
||||||
project: 'default',
|
createdAt: new Date(),
|
||||||
featureName: 'some-toggle',
|
type: FEATURE_ENVIRONMENT_DISABLED,
|
||||||
data: {
|
createdBy: 'some@user.com',
|
||||||
name: 'some-toggle',
|
environment: 'development',
|
||||||
},
|
createdByUserId: -1337,
|
||||||
};
|
project: 'default',
|
||||||
|
featureName: 'some-toggle',
|
||||||
const parameters = {
|
data: {
|
||||||
url: 'http://hooks.slack.com',
|
name: 'some-toggle',
|
||||||
apiKey: 'fakeKey',
|
},
|
||||||
customHeaders: `{ "MY_CUSTOM_HEADER": "MY_CUSTOM_VALUE" }`,
|
};
|
||||||
};
|
|
||||||
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
const parameters = {
|
||||||
expect(fetchRetryCalls).toHaveLength(1);
|
url: 'http://hooks.slack.com',
|
||||||
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
apiKey: 'fakeKey',
|
||||||
expect(fetchRetryCalls[0].options.body).toMatch(/disabled/);
|
customHeaders: `{ "MY_CUSTOM_HEADER": "MY_CUSTOM_VALUE" }`,
|
||||||
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
};
|
||||||
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
||||||
});
|
expect(fetchRetryCalls).toHaveLength(1);
|
||||||
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
||||||
test('Should not include source_type_name when included in the config', async () => {
|
expect(fetchRetryCalls[0].options.body).toMatch(/disabled/);
|
||||||
const addon = new DatadogAddon(ARGS);
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
const event: IEvent = {
|
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
|
||||||
id: 2,
|
});
|
||||||
createdAt: new Date(),
|
|
||||||
type: FEATURE_ENVIRONMENT_DISABLED,
|
test('Should not include source_type_name when included in the config', async () => {
|
||||||
createdBy: 'some@user.com',
|
const addon = new DatadogAddon(ARGS);
|
||||||
createdByUserId: -1337,
|
const event: IEvent = {
|
||||||
environment: 'development',
|
id: 2,
|
||||||
project: 'default',
|
createdAt: new Date(),
|
||||||
featureName: 'some-toggle',
|
type: FEATURE_ENVIRONMENT_DISABLED,
|
||||||
data: {
|
createdBy: 'some@user.com',
|
||||||
name: 'some-toggle',
|
createdByUserId: -1337,
|
||||||
},
|
environment: 'development',
|
||||||
};
|
project: 'default',
|
||||||
|
featureName: 'some-toggle',
|
||||||
const parameters = {
|
data: {
|
||||||
url: 'http://hooks.slack.com',
|
name: 'some-toggle',
|
||||||
apiKey: 'fakeKey',
|
},
|
||||||
sourceTypeName: 'my-custom-source-type',
|
};
|
||||||
};
|
|
||||||
|
const parameters = {
|
||||||
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
url: 'http://hooks.slack.com',
|
||||||
expect(fetchRetryCalls).toHaveLength(1);
|
apiKey: 'fakeKey',
|
||||||
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
sourceTypeName: 'my-custom-source-type',
|
||||||
expect(fetchRetryCalls[0].options.body).toMatch(
|
};
|
||||||
/"source_type_name":"my-custom-source-type"/,
|
|
||||||
);
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
||||||
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
expect(fetchRetryCalls).toHaveLength(1);
|
||||||
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
||||||
});
|
expect(fetchRetryCalls[0].options.body).toMatch(
|
||||||
|
/"source_type_name":"my-custom-source-type"/,
|
||||||
test('Should call datadog webhook with JSON when template set', async () => {
|
);
|
||||||
const addon = new DatadogAddon(ARGS);
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
const event: IEvent = {
|
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
|
||||||
id: 1,
|
});
|
||||||
createdAt: new Date(),
|
|
||||||
type: FEATURE_CREATED,
|
test('Should call datadog webhook with JSON when template set', async () => {
|
||||||
createdBy: 'some@user.com',
|
const addon = new DatadogAddon(ARGS);
|
||||||
createdByUserId: -1337,
|
const event: IEvent = {
|
||||||
featureName: 'some-toggle',
|
id: 1,
|
||||||
data: {
|
createdAt: new Date(),
|
||||||
name: 'some-toggle',
|
type: FEATURE_CREATED,
|
||||||
enabled: false,
|
createdBy: 'some@user.com',
|
||||||
strategies: [{ name: 'default' }],
|
createdByUserId: -1337,
|
||||||
},
|
featureName: 'some-toggle',
|
||||||
};
|
data: {
|
||||||
|
name: 'some-toggle',
|
||||||
const parameters = {
|
enabled: false,
|
||||||
url: 'http://api.datadoghq.com/api/v1/events',
|
strategies: [{ name: 'default' }],
|
||||||
apiKey: 'fakeKey',
|
},
|
||||||
bodyTemplate:
|
};
|
||||||
'{\n "event": "{{event.type}}",\n "createdBy": "{{event.createdBy}}"\n}',
|
|
||||||
};
|
const parameters = {
|
||||||
|
url: 'http://api.datadoghq.com/api/v1/events',
|
||||||
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
apiKey: 'fakeKey',
|
||||||
expect(fetchRetryCalls.length).toBe(1);
|
bodyTemplate:
|
||||||
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
'{\n "event": "{{event.type}}",\n "createdBy": "{{event.createdBy}}"\n}',
|
||||||
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
};
|
||||||
|
|
||||||
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
||||||
|
expect(fetchRetryCalls.length).toBe(1);
|
||||||
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
||||||
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should call registerEvent', async () => {
|
||||||
|
const addon = new DatadogAddon(ARGS);
|
||||||
|
const event: IEvent = {
|
||||||
|
id: 1,
|
||||||
|
createdAt: new Date(),
|
||||||
|
type: FEATURE_CREATED,
|
||||||
|
createdBy: 'some@user.com',
|
||||||
|
createdByUserId: -1337,
|
||||||
|
featureName: 'some-toggle',
|
||||||
|
data: {
|
||||||
|
name: 'some-toggle',
|
||||||
|
enabled: false,
|
||||||
|
strategies: [{ name: 'default' }],
|
||||||
|
},
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
type: 'test',
|
||||||
|
value: '1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'test',
|
||||||
|
value: '2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const parameters = {
|
||||||
|
url: 'http://api.datadoghq.com/api/v1/events',
|
||||||
|
apiKey: 'fakeKey',
|
||||||
|
bodyTemplate:
|
||||||
|
'{\n "event": "{{event.type}}",\n "createdBy": "{{event.createdBy}}"\n}',
|
||||||
|
};
|
||||||
|
|
||||||
|
await addon.handleEvent(event, parameters, INTEGRATION_ID);
|
||||||
|
|
||||||
|
expect(registerEventMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(registerEventMock).toHaveBeenCalledWith({
|
||||||
|
integrationId: INTEGRATION_ID,
|
||||||
|
state: 'success',
|
||||||
|
stateDetails:
|
||||||
|
'Datadog Events API request was successful with status code: 200.',
|
||||||
|
event: serializeDates(event),
|
||||||
|
details: {
|
||||||
|
url: parameters.url,
|
||||||
|
body: {
|
||||||
|
text: `{\n "event": "${event.type}",\n "createdBy": "${event.createdBy}"\n}`,
|
||||||
|
title: 'Unleash notification update',
|
||||||
|
tags: ['test:1', 'test:2'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,13 +2,14 @@ import Addon from './addon';
|
|||||||
|
|
||||||
import definition from './datadog-definition';
|
import definition from './datadog-definition';
|
||||||
import Mustache from 'mustache';
|
import Mustache from 'mustache';
|
||||||
import type { IAddonConfig } from '../types/model';
|
import { type IAddonConfig, serializeDates } from '../types';
|
||||||
import {
|
import {
|
||||||
type FeatureEventFormatter,
|
type FeatureEventFormatter,
|
||||||
FeatureEventFormatterMd,
|
FeatureEventFormatterMd,
|
||||||
LinkStyle,
|
LinkStyle,
|
||||||
} from './feature-event-formatter-md';
|
} from './feature-event-formatter-md';
|
||||||
import type { IEvent } from '../types/events';
|
import type { IEvent } from '../types/events';
|
||||||
|
import type { IntegrationEventState } from '../features/integration-events/integration-events-store';
|
||||||
|
|
||||||
interface IDatadogParameters {
|
interface IDatadogParameters {
|
||||||
url: string;
|
url: string;
|
||||||
@ -41,6 +42,9 @@ export default class DatadogAddon extends Addon {
|
|||||||
parameters: IDatadogParameters,
|
parameters: IDatadogParameters,
|
||||||
integrationId: number,
|
integrationId: number,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
let state: IntegrationEventState = 'success';
|
||||||
|
const stateDetails: string[] = [];
|
||||||
|
|
||||||
const {
|
const {
|
||||||
url = 'https://api.datadoghq.com/api/v1/events',
|
url = 'https://api.datadoghq.com/api/v1/events',
|
||||||
apiKey,
|
apiKey,
|
||||||
@ -75,9 +79,11 @@ export default class DatadogAddon extends Addon {
|
|||||||
try {
|
try {
|
||||||
extraHeaders = JSON.parse(customHeaders);
|
extraHeaders = JSON.parse(customHeaders);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.warn(
|
state = 'successWithErrors';
|
||||||
`Could not parse the json in the customHeaders parameter. [${customHeaders}]`,
|
const badHeadersMessage =
|
||||||
);
|
'Could not parse the JSON in the customHeaders parameter.';
|
||||||
|
stateDetails.push(badHeadersMessage);
|
||||||
|
this.logger.warn(badHeadersMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const requestOpts = {
|
const requestOpts = {
|
||||||
@ -90,8 +96,29 @@ export default class DatadogAddon extends Addon {
|
|||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
};
|
};
|
||||||
const res = await this.fetchRetry(url, requestOpts);
|
const res = await this.fetchRetry(url, requestOpts);
|
||||||
this.logger.info(
|
|
||||||
`Handled event ${event.type}. Status codes=${res.status}`,
|
this.logger.info(`Handled event "${event.type}".`);
|
||||||
);
|
|
||||||
|
if (res.ok) {
|
||||||
|
const successMessage = `Datadog Events API request was successful with status code: ${res.status}.`;
|
||||||
|
stateDetails.push(successMessage);
|
||||||
|
this.logger.info(successMessage);
|
||||||
|
} else {
|
||||||
|
state = 'failed';
|
||||||
|
const failedMessage = `Datadog Events API request failed with status code: ${res.status}.`;
|
||||||
|
stateDetails.push(failedMessage);
|
||||||
|
this.logger.warn(failedMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.registerEvent({
|
||||||
|
integrationId,
|
||||||
|
state,
|
||||||
|
stateDetails: stateDetails.join('\n'),
|
||||||
|
event: serializeDates(event),
|
||||||
|
details: {
|
||||||
|
url,
|
||||||
|
body,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user