Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up stale flag: addonUsageMetrics and event emitting from addons #8381

Merged
merged 17 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 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,10 @@ export default abstract class Addon {
integrationEvent: IntegrationEventWriteModel,
): Promise<void> {
await this.integrationEventsService.registerEvent(integrationEvent);
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
10 changes: 0 additions & 10 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 @@ -70,7 +69,6 @@ export default class SlackAppAddon extends Addon {
event,
noAccessTokenMessage,
);
return;
daveleek marked this conversation as resolved.
Show resolved Hide resolved
}

const taggedChannels = this.findTaggedChannels(event);
Expand All @@ -86,7 +84,6 @@ export default class SlackAppAddon extends Addon {
event,
noSlackChannelsMessage,
);
return;
daveleek marked this conversation as resolved.
Show resolved Hide resolved
}

this.logger.debug(
Expand Down Expand Up @@ -182,13 +179,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
1 change: 1 addition & 0 deletions src/lib/services/addon-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function getSetup() {
getLogger,
// @ts-ignore
server: { unleashUrl: 'http://test' },
eventBus: { emit: jest.fn() } as any,
},
tagTypeService,
eventService,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/services/addon-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { IAddonDefinition } from '../types/model';
import { minutesToMilliseconds } from 'date-fns';
import type EventService from '../features/events/event-service';
import { omitKeys } from '../util';
import type EventEmitter from 'events';

const SUPPORTED_EVENTS = Object.keys(events).map((k) => events[k]);

Expand All @@ -52,6 +53,8 @@ export default class AddonService {

sensitiveParams: ISensitiveParams;

eventBus: EventEmitter;

fetchAddonConfigs: (() => Promise<IAddon[]>) &
memoizee.Memoized<() => Promise<IAddon[]>>;

Expand Down Expand Up @@ -79,6 +82,7 @@ export default class AddonService {
this.logger = getLogger('services/addon-service.js');
this.tagTypeService = tagTypeService;
this.eventService = eventService;
this.eventBus = eventBus;

this.addonProviders =
addons ||
Expand Down
5 changes: 0 additions & 5 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 Down Expand Up @@ -268,10 +267,6 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_REMOVE_UNSAFE_INLINE_STYLE_SRC,
false,
),
addonUsageMetrics: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_ADDON_USAGE_METRICS,
false,
),
daveleek marked this conversation as resolved.
Show resolved Hide resolved
onboardingMetrics: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_ONBOARDING_METRICS,
false,
Expand Down
2 changes: 0 additions & 2 deletions src/server-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ process.nextTick(async () => {
manyStrategiesPagination: true,
enableLegacyVariants: false,
extendedMetrics: true,
addonUsageMetrics: true,
onboardingMetrics: true,
onboardingUI: true,
personalDashboardUI: true,
purchaseAdditionalEnvironments: true,
Expand Down