Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
437e45b
feat(api): Add ClickHouse data seeding scripts and materialized view …
djabarovgeorge Jan 8, 2026
844f5f9
refactor(analytic-logs): Remove unused WorkflowRunOptimizeCronService…
djabarovgeorge Jan 11, 2026
038e027
refactor(analytic-logs): Replace TraceLogRepository with MessageSentC…
djabarovgeorge Jan 11, 2026
2fc70fe
feat(analytic-logs): Implement feature flag logic for message deliver…
djabarovgeorge Jan 11, 2026
6269f12
refactor(analytic-logs): Rename method for fetching message delivery …
djabarovgeorge Jan 11, 2026
8bacfe5
refactor(analytic-logs): Remove MessageSentCountsRepository as it is …
djabarovgeorge Jan 11, 2026
f35251e
refactor(analytic-logs): Replace MessageSentCountsRepository with Wor…
djabarovgeorge Jan 11, 2026
2bb1208
feat(analytic-logs): Add new method for average messages per subscrib…
djabarovgeorge Jan 11, 2026
0eb0e1f
feat(activity): Implement provider volume data retrieval
djabarovgeorge Jan 11, 2026
7dfb2d5
refactor(vscode): Update settings to exclude additional build artifac…
djabarovgeorge Jan 12, 2026
49559ae
feat(activity): Integrate feature flag logic for interaction trend an…
djabarovgeorge Jan 12, 2026
971585c
feat(activity): Enhance delivery trend chart with feature flag integr…
djabarovgeorge Jan 12, 2026
7073aaf
feat(activity): Integrate feature flag logic for workflow volume data…
djabarovgeorge Jan 12, 2026
2fb6a67
refactor(analytic-logs): Remove InteractionCountsRepository and relat…
djabarovgeorge Jan 12, 2026
6897c70
refactor(analytic-logs): Remove WorkflowVolumeCounts and related comp…
djabarovgeorge Jan 12, 2026
6325722
refactor(analytic-logs): Remove deprecated SQL migrations for workflo…
djabarovgeorge Jan 12, 2026
e04aa3b
refactor(activity): update feature flag keys for various charts
djabarovgeorge Jan 13, 2026
2f671ca
feat(analytic-logs): Add provider_id column to traces table and updat…
djabarovgeorge Jan 13, 2026
0cbd9f6
refactor(analytic-logs): Replace ProviderVolumeCounts with WorkflowAc…
djabarovgeorge Jan 13, 2026
c7a96d8
refactor(analytic-logs): Rename WorkflowActivityCounts to TraceRollup…
djabarovgeorge Jan 13, 2026
6285055
feat: update hash
djabarovgeorge Jan 13, 2026
c24394d
Merge branch 'next' into wip-improve-pref-usage-2
djabarovgeorge Jan 13, 2026
618db5c
refactor(activity): update feature flag keys for various charts to an…
djabarovgeorge Jan 13, 2026
b281e92
feat(analytics): add provider_id column to traces table and update re…
djabarovgeorge Jan 13, 2026
b83443b
fix(clickhouse-seeder): update trace event type selection logic and a…
djabarovgeorge Jan 13, 2026
86e3791
refactor(analytics): update trace rollup table and materialized view …
djabarovgeorge Jan 13, 2026
f67b588
fix(analytic-logs): change provider_id type to non-nullable string in…
djabarovgeorge Jan 13, 2026
b51bfa2
refactor(analytics): reorder columns in trace rollup table and schema…
djabarovgeorge Jan 14, 2026
80d4bce
chore: update hash to next
djabarovgeorge Jan 14, 2026
9b61f6c
chore: update hash to next
djabarovgeorge Jan 14, 2026
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
Prev Previous commit
Next Next commit
feat(analytic-logs): Implement feature flag logic for message deliver…
…y data retrieval
  • Loading branch information
djabarovgeorge committed Jan 11, 2026
commit 2fc70fe8b15a63e18578468bb4293b978f7e4336
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { Injectable } from '@nestjs/common';
import { InstrumentUsecase, MessageSentCountsRepository, PinoLogger } from '@novu/application-generic';
import {
FeatureFlagsService,
InstrumentUsecase,
MessageSentCountsRepository,
PinoLogger,
StepRunRepository,
} from '@novu/application-generic';
import { FeatureFlagsKeysEnum } from '@novu/shared';
import { MessagesDeliveredDataPointDto } from '../../dtos/get-charts.response.dto';
import { BuildMessagesDeliveredChartCommand } from './build-messages-delivered-chart.command';

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

const result = await this.messageSentCountsRepository.getMessagesSentData(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
);
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_V2_MESSAGE_SENT_COUNTS_READ_ENABLED,
defaultValue: false,
...featureFlagContext,
}),
]);

const useNewLogic = isGlobalEnabled || isDedicatedEnabled;

const result = useNewLogic
? await this.messageSentCountsRepository.getMessagesSentData(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
)
: await this.stepRunRepository.getMessagesDeliveredData(
environmentId,
organizationId,
startDate,
endDate,
previousStartDate,
previousEndDate,
workflowIds
);

return {
currentPeriod: result.currentPeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,83 @@ export class StepRunRepository extends LogRepository<typeof stepRunSchema, StepR
return result.data;
}

async getMessagesDeliveredData(
environmentId: string,
organizationId: string,
startDate: Date,
endDate: Date,
previousStartDate: Date,
previousEndDate: Date,
workflowIds?: string[]
): Promise<{ currentPeriod: number; previousPeriod: number }> {
const workflowFilter =
workflowIds && workflowIds.length > 0 ? `AND workflow_id IN {workflowIds:Array(String)}` : '';

// Query for current period
const currentPeriodQuery = `
SELECT count(*) as count
FROM step_runs FINAL
WHERE
environment_id = {environmentId:String}
AND organization_id = {organizationId:String}
AND created_at >= {startDate:DateTime64(3)}
AND created_at <= {endDate:DateTime64(3)}
AND step_type IN ('in_app', 'email', 'sms', 'chat', 'push')
AND status = 'completed'
${workflowFilter}
`;

// Query for previous period
const previousPeriodQuery = `
SELECT count(*) as count
FROM step_runs FINAL
WHERE
environment_id = {environmentId:String}
AND organization_id = {organizationId:String}
AND created_at >= {previousStartDate:DateTime64(3)}
AND created_at <= {previousEndDate:DateTime64(3)}
AND step_type IN ('in_app', 'email', 'sms', 'chat', 'push')
AND status = 'completed'
${workflowFilter}
`;

const baseParams: Record<string, unknown> = {
environmentId,
organizationId,
};

if (workflowIds && workflowIds.length > 0) {
baseParams.workflowIds = workflowIds;
}

const [currentResult, previousResult] = await Promise.all([
this.clickhouseService.query<{ count: string }>({
query: currentPeriodQuery,
params: {
...baseParams,
startDate: LogRepository.formatDateTime64(startDate),
endDate: LogRepository.formatDateTime64(endDate),
},
}),
this.clickhouseService.query<{ count: string }>({
query: previousPeriodQuery,
params: {
...baseParams,
previousStartDate: LogRepository.formatDateTime64(previousStartDate),
previousEndDate: LogRepository.formatDateTime64(previousEndDate),
},
}),
]);

const currentPeriod = parseInt(currentResult.data[0]?.count || '0', 10);
const previousPeriod = parseInt(previousResult.data[0]?.count || '0', 10);

return {
currentPeriod,
previousPeriod,
};
}

async getAvgMessagesPerSubscriberData(
environmentId: string,
organizationId: string,
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/types/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export enum FeatureFlagsKeysEnum {
IS_CONTEXTUAL_HELP_DRAWER_ENABLED = 'IS_CONTEXTUAL_HELP_DRAWER_ENABLED',
IS_SUBSCRIPTION_PREFERENCES_ENABLED = 'IS_SUBSCRIPTION_PREFERENCES_ENABLED',
IS_LRU_CACHE_ENABLED = 'IS_LRU_CACHE_ENABLED',
IS_ANALYTIC_V2_LOGS_READ_GLOBAL_ENABLED = 'IS_ANALYTIC_V2_LOGS_READ_GLOBAL_ENABLED',
IS_V2_MESSAGE_SENT_COUNTS_READ_ENABLED = 'IS_V2_MESSAGE_SENT_COUNTS_READ_ENABLED',

// String flags
CF_SCHEDULER_MODE = 'CF_SCHEDULER_MODE', // Values: "off" | "shadow" | "live" | "complete"
Expand Down