Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { Injectable } from '@nestjs/common';
import {
FeatureFlagsService,
InstrumentUsecase,
PinoLogger,
TraceRollupRepository,
WorkflowRunRepository,
} from '@novu/application-generic';
import { FeatureFlagsKeysEnum } from '@novu/shared';
import { InstrumentUsecase, PinoLogger, TraceRollupRepository } from '@novu/application-generic';
import { ActiveSubscribersDataPointDto } from '../../dtos/get-charts.response.dto';
import { BuildActiveSubscribersChartCommand } from './build-active-subscribers-chart.command';

@Injectable()
export class BuildActiveSubscribersChart {
constructor(
private traceRollupRepository: TraceRollupRepository,
private workflowRunRepository: WorkflowRunRepository,
private featureFlagsService: FeatureFlagsService,
private logger: PinoLogger
) {
this.logger.setContext(BuildActiveSubscribersChart.name);
Expand All @@ -29,45 +20,15 @@ export class BuildActiveSubscribersChart {
const previousEndDate = new Date(startDate.getTime() - 1);
const previousStartDate = new Date(previousEndDate.getTime() - periodDuration);

const featureFlagContext = {
organization: { _id: organizationId },
environment: { _id: environmentId },
};

const [isGlobalEnabled, isDedicatedEnabled] = await Promise.all([
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_LOGS_READ_GLOBAL_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_ACTIVE_SUBSCRIBERS_READ_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
]);

const useNewQuery = isGlobalEnabled || isDedicatedEnabled;

const result = useNewQuery
? await this.traceRollupRepository.getActiveSubscribersCount(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
)
: await this.workflowRunRepository.getActiveSubscribersData(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
);
const result = await this.traceRollupRepository.getActiveSubscribersCount(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
);

return {
currentPeriod: result.currentPeriod,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { Injectable } from '@nestjs/common';
import {
FeatureFlagsService,
InstrumentUsecase,
PinoLogger,
TraceRollupRepository,
WorkflowRunRepository,
} from '@novu/application-generic';
import { FeatureFlagsKeysEnum } from '@novu/shared';
import { InstrumentUsecase, PinoLogger, TraceRollupRepository } from '@novu/application-generic';
import { ActiveSubscribersTrendDataPointDto } from '../../dtos/get-charts.response.dto';
import { BuildActiveSubscribersTrendChartCommand } from './build-active-subscribers-trend-chart.command';

@Injectable()
export class BuildActiveSubscribersTrendChart {
constructor(
private traceRollupRepository: TraceRollupRepository,
private workflowRunRepository: WorkflowRunRepository,
private featureFlagsService: FeatureFlagsService,
private logger: PinoLogger
) {
this.logger.setContext(BuildActiveSubscribersTrendChart.name);
Expand All @@ -25,41 +16,13 @@ export class BuildActiveSubscribersTrendChart {
async execute(command: BuildActiveSubscribersTrendChartCommand): Promise<ActiveSubscribersTrendDataPointDto[]> {
const { environmentId, organizationId, startDate, endDate, workflowIds } = command;

const featureFlagContext = {
organization: { _id: organizationId },
environment: { _id: environmentId },
};

const [isGlobalEnabled, isDedicatedEnabled] = await Promise.all([
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_LOGS_READ_GLOBAL_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_ACTIVE_SUBSCRIBER_TREND_READ_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
]);

const useNewQuery = isGlobalEnabled || isDedicatedEnabled;

const activeSubscribers = useNewQuery
? await this.traceRollupRepository.getActiveSubscribersTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
)
: await this.workflowRunRepository.getActiveSubscribersTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
);
const activeSubscribers = await this.traceRollupRepository.getActiveSubscribersTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
);

const chartDataMap = new Map<string, number>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { Injectable } from '@nestjs/common';
import {
FeatureFlagsService,
InstrumentUsecase,
PinoLogger,
StepRunRepository,
TraceRollupRepository,
} from '@novu/application-generic';
import { FeatureFlagsKeysEnum } from '@novu/shared';
import { InstrumentUsecase, PinoLogger, TraceRollupRepository } from '@novu/application-generic';
import { AvgMessagesPerSubscriberDataPointDto } from '../../dtos/get-charts.response.dto';
import { BuildAvgMessagesPerSubscriberChartCommand } from './build-avg-messages-per-subscriber-chart.command';

@Injectable()
export class BuildAvgMessagesPerSubscriberChart {
constructor(
private traceRollupRepository: TraceRollupRepository,
private stepRunRepository: StepRunRepository,
private featureFlagsService: FeatureFlagsService,
private logger: PinoLogger
) {
this.logger.setContext(BuildAvgMessagesPerSubscriberChart.name);
Expand All @@ -29,45 +20,15 @@ export class BuildAvgMessagesPerSubscriberChart {
const previousEndDate = new Date(startDate.getTime() - 1);
const previousStartDate = new Date(previousEndDate.getTime() - periodDuration);

const featureFlagContext = {
organization: { _id: organizationId },
environment: { _id: environmentId },
};

const [isGlobalEnabled, isDedicatedEnabled] = await Promise.all([
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_LOGS_READ_GLOBAL_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_AVG_MESSAGES_PER_SUBSCRIBER_READ_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
]);

const useNewQuery = isGlobalEnabled || isDedicatedEnabled;

const result = useNewQuery
? await this.traceRollupRepository.getAvgMessagesPerSubscriberData(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
)
: await this.stepRunRepository.getAvgMessagesPerSubscriberData(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
);
const result = await this.traceRollupRepository.getAvgMessagesPerSubscriberData(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
);

return {
currentPeriod: result.currentPeriod,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { Injectable } from '@nestjs/common';
import {
DeliveryTrendCountsRepository,
FeatureFlagsService,
InstrumentUsecase,
PinoLogger,
StepRunRepository,
} from '@novu/application-generic';
import { FeatureFlagsKeysEnum } from '@novu/shared';
import { DeliveryTrendCountsRepository, InstrumentUsecase, PinoLogger } from '@novu/application-generic';
import { ChartDataPointDto } from '../../dtos/get-charts.response.dto';
import { BuildDeliveryTrendChartCommand } from './build-delivery-trend-chart.command';

@Injectable()
export class BuildDeliveryTrendChart {
constructor(
private deliveryTrendCountsRepository: DeliveryTrendCountsRepository,
private stepRunRepository: StepRunRepository,
private featureFlagsService: FeatureFlagsService,
private logger: PinoLogger
) {
this.logger.setContext(BuildDeliveryTrendChart.name);
Expand All @@ -25,41 +16,13 @@ export class BuildDeliveryTrendChart {
async execute(command: BuildDeliveryTrendChartCommand): Promise<ChartDataPointDto[]> {
const { environmentId, organizationId, startDate, endDate, workflowIds } = command;

const featureFlagContext = {
organization: { _id: organizationId },
environment: { _id: environmentId },
};

const [isGlobalEnabled, isDedicatedEnabled] = await Promise.all([
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_LOGS_READ_GLOBAL_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_DELIVERY_TREND_READ_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
]);

const useNewQuery = isGlobalEnabled || isDedicatedEnabled;

const stepRuns = useNewQuery
? await this.deliveryTrendCountsRepository.getDeliveryTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
)
: await this.stepRunRepository.getDeliveryTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
);
const stepRuns = await this.deliveryTrendCountsRepository.getDeliveryTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
);

const chartDataMap = new Map<string, Map<string, number>>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { Injectable } from '@nestjs/common';
import {
FeatureFlagsService,
InstrumentUsecase,
PinoLogger,
TraceLogRepository,
TraceRollupRepository,
} from '@novu/application-generic';
import { FeatureFlagsKeysEnum } from '@novu/shared';
import { InstrumentUsecase, PinoLogger, TraceRollupRepository } from '@novu/application-generic';
import { InteractionTrendDataPointDto } from '../../dtos/get-charts.response.dto';
import { BuildInteractionTrendChartCommand } from './build-interaction-trend-chart.command';

@Injectable()
export class BuildInteractionTrendChart {
constructor(
private traceRollupRepository: TraceRollupRepository,
private traceLogRepository: TraceLogRepository,
private featureFlagsService: FeatureFlagsService,
private logger: PinoLogger
) {
this.logger.setContext(BuildInteractionTrendChart.name);
Expand All @@ -25,41 +16,13 @@ export class BuildInteractionTrendChart {
async execute(command: BuildInteractionTrendChartCommand): Promise<InteractionTrendDataPointDto[]> {
const { environmentId, organizationId, startDate, endDate, workflowIds } = command;

const featureFlagContext = {
organization: { _id: organizationId },
environment: { _id: environmentId },
};

const [isGlobalEnabled, isDedicatedEnabled] = await Promise.all([
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_LOGS_READ_GLOBAL_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_ANALYTIC_V2_INTERACTION_TREND_READ_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
]);

const useNewQuery = isGlobalEnabled || isDedicatedEnabled;

const traces = useNewQuery
? await this.traceRollupRepository.getInteractionTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
)
: await this.traceLogRepository.getInteractionTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
);
const traces = await this.traceRollupRepository.getInteractionTrendData(
environmentId,
organizationId,
startDate,
endDate,
workflowIds
);

const chartDataMap = new Map<string, Map<string, number>>();

Expand Down
Loading
Loading