mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-24 01:18:01 +02:00
chore: Datadog addon, ability to include source type name (#4196)
## About the changes Include a new configuration parameter to be able to specify source_type_name. This is an opt-in feature which provides backward compatibility to our existing users.  Closes #4109 ## Discussion points Maybe this should be hardcoded to `Unleash` but this gives additional flexibility
This commit is contained in:
parent
d5ef1dda0a
commit
b37851acea
@ -17,3 +17,12 @@ exports[`Should include customHeaders in headers when calling service 2`] = `
|
|||||||
"MY_CUSTOM_HEADER": "MY_CUSTOM_VALUE",
|
"MY_CUSTOM_HEADER": "MY_CUSTOM_VALUE",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
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) in *development* environment in project *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`] = `
|
||||||
|
{
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"DD-API-KEY": "fakeKey",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
@ -40,6 +40,15 @@ const dataDogDefinition: IAddonDefinition = {
|
|||||||
required: true,
|
required: true,
|
||||||
sensitive: true,
|
sensitive: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'sourceTypeName',
|
||||||
|
displayName: 'Datadog Source Type Name',
|
||||||
|
description:
|
||||||
|
'(Optional) source_type_name parameter to be included in Datadog events.',
|
||||||
|
type: 'text',
|
||||||
|
required: false,
|
||||||
|
sensitive: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'customHeaders',
|
name: 'customHeaders',
|
||||||
displayName: 'Extra HTTP Headers',
|
displayName: 'Extra HTTP Headers',
|
||||||
|
@ -179,3 +179,37 @@ test(`Should include customHeaders in headers when calling service`, async () =>
|
|||||||
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
|
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(`Should not include source_type_name when included in the config`, async () => {
|
||||||
|
const addon = new DatadogAddon({
|
||||||
|
getLogger: noLogger,
|
||||||
|
unleashUrl: 'http://some-url.com',
|
||||||
|
});
|
||||||
|
const event: IEvent = {
|
||||||
|
id: 2,
|
||||||
|
createdAt: new Date(),
|
||||||
|
type: FEATURE_ENVIRONMENT_DISABLED,
|
||||||
|
createdBy: 'some@user.com',
|
||||||
|
environment: 'development',
|
||||||
|
project: 'default',
|
||||||
|
featureName: 'some-toggle',
|
||||||
|
data: {
|
||||||
|
name: 'some-toggle',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const parameters = {
|
||||||
|
url: 'http://hooks.slack.com',
|
||||||
|
apiKey: 'fakeKey',
|
||||||
|
sourceTypeName: 'my-custom-source-type',
|
||||||
|
};
|
||||||
|
|
||||||
|
await addon.handleEvent(event, parameters);
|
||||||
|
expect(fetchRetryCalls).toHaveLength(1);
|
||||||
|
expect(fetchRetryCalls[0].url).toBe(parameters.url);
|
||||||
|
expect(fetchRetryCalls[0].options.body).toMatch(
|
||||||
|
/"source_type_name":"my-custom-source-type"/,
|
||||||
|
);
|
||||||
|
expect(fetchRetryCalls[0].options.body).toMatchSnapshot();
|
||||||
|
expect(fetchRetryCalls[0].options.headers).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
@ -12,9 +12,17 @@ import { IEvent } from '../types/events';
|
|||||||
interface IDatadogParameters {
|
interface IDatadogParameters {
|
||||||
url: string;
|
url: string;
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
|
sourceTypeName?: string;
|
||||||
customHeaders?: string;
|
customHeaders?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DDRequestBody {
|
||||||
|
text: string;
|
||||||
|
title: string;
|
||||||
|
tags?: string[];
|
||||||
|
source_type_name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default class DatadogAddon extends Addon {
|
export default class DatadogAddon extends Addon {
|
||||||
private msgFormatter: FeatureEventFormatter;
|
private msgFormatter: FeatureEventFormatter;
|
||||||
|
|
||||||
@ -26,7 +34,6 @@ export default class DatadogAddon extends Addon {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
||||||
async handleEvent(
|
async handleEvent(
|
||||||
event: IEvent,
|
event: IEvent,
|
||||||
parameters: IDatadogParameters,
|
parameters: IDatadogParameters,
|
||||||
@ -34,6 +41,7 @@ export default class DatadogAddon extends Addon {
|
|||||||
const {
|
const {
|
||||||
url = 'https://api.datadoghq.com/api/v1/events',
|
url = 'https://api.datadoghq.com/api/v1/events',
|
||||||
apiKey,
|
apiKey,
|
||||||
|
sourceTypeName,
|
||||||
customHeaders,
|
customHeaders,
|
||||||
} = parameters;
|
} = parameters;
|
||||||
|
|
||||||
@ -42,11 +50,14 @@ export default class DatadogAddon extends Addon {
|
|||||||
const { tags: eventTags } = event;
|
const { tags: eventTags } = event;
|
||||||
const tags =
|
const tags =
|
||||||
eventTags && eventTags.map((tag) => `${tag.type}:${tag.value}`);
|
eventTags && eventTags.map((tag) => `${tag.type}:${tag.value}`);
|
||||||
const body = {
|
const body: DDRequestBody = {
|
||||||
text: `%%% \n ${text} \n %%% `,
|
text: `%%% \n ${text} \n %%% `,
|
||||||
title: 'Unleash notification update',
|
title: 'Unleash notification update',
|
||||||
tags,
|
tags,
|
||||||
};
|
};
|
||||||
|
if (sourceTypeName) {
|
||||||
|
body.source_type_name = sourceTypeName;
|
||||||
|
}
|
||||||
let extraHeaders = {};
|
let extraHeaders = {};
|
||||||
if (typeof customHeaders === 'string' && customHeaders.length > 1) {
|
if (typeof customHeaders === 'string' && customHeaders.length > 1) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user