Created
May 24, 2022 18:26
-
-
Save chriswk/f4e03d83b133e126aefbb232b92af5f2 to your computer and use it in GitHub Desktop.
Dynatrace unleash addon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
FEATURE_CREATED, | |
FEATURE_UPDATED, | |
FEATURE_ARCHIVED, | |
FEATURE_REVIVED, | |
FEATURE_STALE_ON, | |
FEATURE_STALE_OFF, | |
FEATURE_ENVIRONMENT_ENABLED, | |
FEATURE_ENVIRONMENT_DISABLED, | |
FEATURE_STRATEGY_REMOVE, | |
FEATURE_STRATEGY_UPDATE, | |
FEATURE_STRATEGY_ADD, | |
FEATURE_METADATA_UPDATED, | |
FEATURE_PROJECT_CHANGE, | |
FEATURE_VARIANTS_UPDATED, | |
} from '../types/events'; | |
import { IAddonDefinition } from '../types/model'; | |
export const dynatraceDefinition: IAddonDefinition = { | |
name: 'dynatrace', | |
displayName: 'Dynatrace', | |
description: 'Allows Unleash to post updates to Dynatrace.', | |
documentationUrl: 'https://docs.getunleash.io/docs/addons/dynatrace', | |
parameters: [], | |
events: [ | |
FEATURE_CREATED, | |
FEATURE_UPDATED, | |
FEATURE_ARCHIVED, | |
FEATURE_REVIVED, | |
FEATURE_STALE_ON, | |
FEATURE_STALE_OFF, | |
FEATURE_ENVIRONMENT_ENABLED, | |
FEATURE_ENVIRONMENT_DISABLED, | |
FEATURE_STRATEGY_REMOVE, | |
FEATURE_STRATEGY_UPDATE, | |
FEATURE_STRATEGY_ADD, | |
FEATURE_METADATA_UPDATED, | |
FEATURE_PROJECT_CHANGE, | |
FEATURE_VARIANTS_UPDATED, | |
], | |
tagTypes: [ | |
{ | |
name: 'dynatrace', | |
description: 'All dynatrace tags...', | |
icon: 'Dyna', | |
}, | |
], | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Addon from './addon'; | |
import { IAddonConfig } from '../types/model'; | |
import { IUnleashStores } from '../types'; | |
import { dynatraceDefinition } from './dynatrace-definition'; | |
import { IEvent } from '../types/events'; | |
import { IClientMetricsStoreV2 } from '../types/stores/client-metrics-store-v2'; | |
export class DynatraceAddon extends Addon { | |
metricsStore: IClientMetricsStoreV2; | |
constructor( | |
addon: IAddonConfig, | |
{ clientMetricsStoreV2 }: Pick<IUnleashStores, 'clientMetricsStoreV2'>, | |
) { | |
super(dynatraceDefinition, addon); | |
this.metricsStore = clientMetricsStoreV2; | |
} | |
async handleEvent(event: IEvent, parameters: any): Promise<void> { | |
const url = 'dynatraceUrl'; | |
const { tags: eventTags } = event; | |
const tags = | |
eventTags && eventTags.map((tag) => `${tag.type}:${tag.value}`); | |
const seenApplications = | |
await this.metricsStore.getSeenAppsForFeatureToggle( | |
event.featureName, | |
); | |
const body = { tags, seenApplications }; | |
const requestOpts = { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify(body), | |
}; | |
const res = await this.fetchRetry(url, requestOpts); | |
this.logger.info( | |
`Handled event ${event.type}. Status codes=${res.status}`, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment