Skip to content

Commit

Permalink
chore: improve addon metrics usage
Browse files Browse the repository at this point in the history
  • Loading branch information
gitar-bot[bot] authored Oct 14, 2024
1 parent e2354dc commit d8ddb57
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 55 deletions.
7 changes: 7 additions & 0 deletions src/lib/addons/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { IntegrationEventsService } from '../features/integration-events/in
import type { IntegrationEventWriteModel } from '../features/integration-events/integration-events-store';
import type EventEmitter from 'events';
import type { IFlagResolver } from '../types';
import { ADDON_EVENTS_HANDLED } from '../metric-events';

export default abstract class Addon {
logger: Logger;
Expand Down Expand Up @@ -93,6 +94,12 @@ export default abstract class Addon {
integrationEvent: IntegrationEventWriteModel,
): Promise<void> {
await this.integrationEventsService.registerEvent(integrationEvent);
if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: integrationEvent.state,
destination: this.name,
});
}
}

destroy?(): void;
Expand Down
8 changes: 0 additions & 8 deletions src/lib/addons/datadog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from './feature-event-formatter-md';
import type { IEvent } from '../types/events';
import type { IntegrationEventState } from '../features/integration-events/integration-events-store';
import { ADDON_EVENTS_HANDLED } from '../metric-events';

interface IDatadogParameters {
url: string;
Expand Down Expand Up @@ -116,13 +115,6 @@ export default class DatadogAddon extends Addon {
this.logger.warn(failedMessage);
}

if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'datadog',
});
}

this.registerEvent({
integrationId,
state,
Expand Down
8 changes: 0 additions & 8 deletions src/lib/addons/new-relic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { gzip } from 'node:zlib';
import { promisify } from 'util';
import type { IntegrationEventState } from '../features/integration-events/integration-events-store';
import { ADDON_EVENTS_HANDLED } from '../metric-events';

const asyncGzip = promisify(gzip);

Expand Down Expand Up @@ -120,13 +119,6 @@ export default class NewRelicAddon extends Addon {
this.logger.warn(failedMessage);
}

if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'new-relic',
});
}

this.registerEvent({
integrationId,
state,
Expand Down
8 changes: 0 additions & 8 deletions src/lib/addons/slack-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from './feature-event-formatter-md';
import type { IEvent } from '../types/events';
import type { IntegrationEventState } from '../features/integration-events/integration-events-store';
import { ADDON_EVENTS_HANDLED } from '../metric-events';

interface ISlackAppAddonParameters {
accessToken: string;
Expand Down Expand Up @@ -182,13 +181,6 @@ export default class SlackAppAddon extends Addon {
stateDetails.push(errorMessage);
this.logger.warn(errorMessage, error);
} finally {
if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'slack-app',
});
}

this.registerEvent({
integrationId,
state,
Expand Down
8 changes: 0 additions & 8 deletions src/lib/addons/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from './feature-event-formatter-md';
import type { IEvent } from '../types/events';
import type { IntegrationEventState } from '../features/integration-events/integration-events-store';
import { ADDON_EVENTS_HANDLED } from '../metric-events';

interface ISlackAddonParameters {
url: string;
Expand Down Expand Up @@ -134,13 +133,6 @@ export default class SlackAddon extends Addon {
this.logger.warn(successWithErrorsMessage);
}

if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'slack',
});
}

this.registerEvent({
integrationId,
state,
Expand Down
8 changes: 0 additions & 8 deletions src/lib/addons/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from './feature-event-formatter-md';
import type { IEvent } from '../types/events';
import type { IntegrationEventState } from '../features/integration-events/integration-events-store';
import { ADDON_EVENTS_HANDLED } from '../metric-events';

interface ITeamsParameters {
url: string;
Expand Down Expand Up @@ -110,13 +109,6 @@ export default class TeamsAddon extends Addon {
this.logger.warn(failedMessage);
}

if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'teams',
});
}

this.registerEvent({
integrationId,
state,
Expand Down
8 changes: 0 additions & 8 deletions src/lib/addons/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
type FeatureEventFormatter,
FeatureEventFormatterMd,
} from './feature-event-formatter-md';
import { ADDON_EVENTS_HANDLED } from '../metric-events';

interface IParameters {
url: string;
Expand Down Expand Up @@ -104,13 +103,6 @@ export default class Webhook extends Addon {
this.logger.warn(failedMessage);
}

if (this.flagResolver.isEnabled('addonUsageMetrics')) {
this.eventBus.emit(ADDON_EVENTS_HANDLED, {
result: state,
destination: 'webhook',
});
}

if (this.flagResolver.isEnabled('webhookDomainLogging')) {
const domain = new URL(url).hostname;
this.logger.info(`Webhook invoked`, {
Expand Down
12 changes: 6 additions & 6 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export type IFlagKey =
| 'navigationSidebar'
| 'extendedMetrics'
| 'removeUnsafeInlineStyleSrc'
| 'addonUsageMetrics'
| 'onboardingMetrics'
| 'onboardingUI'
| 'projectRoleAssignment'
Expand All @@ -63,7 +62,8 @@ export type IFlagKey =
| 'purchaseAdditionalEnvironments'
| 'originMiddlewareRequestLogging'
| 'unleashAI'
| 'webhookDomainLogging';
| 'webhookDomainLogging'
| 'addonUsageMetrics';

export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;

Expand Down Expand Up @@ -268,10 +268,6 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_REMOVE_UNSAFE_INLINE_STYLE_SRC,
false,
),
addonUsageMetrics: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_ADDON_USAGE_METRICS,
false,
),
onboardingMetrics: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_ONBOARDING_METRICS,
false,
Expand Down Expand Up @@ -312,6 +308,10 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENT_WEBHOOK_DOMAIN_LOGGING,
false,
),
addonUsageMetrics: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_ADDON_USAGE_METRICS,
false,
),
};

export const defaultExperimentalOptions: IExperimentalOptions = {
Expand Down
2 changes: 1 addition & 1 deletion src/server-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ process.nextTick(async () => {
manyStrategiesPagination: true,
enableLegacyVariants: false,
extendedMetrics: true,
addonUsageMetrics: true,
onboardingMetrics: true,
onboardingUI: true,
personalDashboardUI: true,
purchaseAdditionalEnvironments: true,
originMiddlewareRequestLogging: true,
unleashAI: true,
webhookDomainLogging: true,
addonUsageMetrics: true,
},
},
authentication: {
Expand Down

0 comments on commit d8ddb57

Please sign in to comment.