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

fix: Reduce payload of license renewal calls (no-changelog) #12236

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
Expand Up @@ -45,10 +45,12 @@ export class WorkflowRepository extends Repository<WorkflowEntity> {
});
}

async getActiveIds() {
async getActiveIds({ maxResults }: { maxResults?: number } = {}) {
const activeWorkflows = await this.find({
select: ['id'],
where: { active: true },
// 'take' and 'order' are only needed when maxResults is provided:
...(maxResults ? { take: maxResults, order: { createdAt: 'ASC' } } : {}),
});
return activeWorkflows.map((workflow) => workflow.id);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/metrics/license-metrics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export class LicenseMetricsService {

async collectPassthroughData() {
return {
activeWorkflowIds: await this.workflowRepository.getActiveIds(),
// Get only the first 1000 active workflow IDs to avoid sending too much data to License Server
// Passthrough data is forwarded to Telemetry for further analysis, such as quota excesses
activeWorkflowIds: await this.workflowRepository.getActiveIds({ maxResults: 1000 }),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('WorkflowRepository', () => {
});

describe('getActiveIds', () => {
it('should return active workflow IDs', async () => {
it('should return all active workflow IDs when invoked without maxResults', async () => {
//
// ARRANGE
//
Expand All @@ -92,6 +92,28 @@ describe('WorkflowRepository', () => {
// ASSERT
//
expect(activeIds).toEqual([workflows[0].id]);
expect(activeIds).toHaveLength(1);
});

it('should return a capped number of active workflow IDs when invoked with maxResults', async () => {
//
// ARRANGE
//
await Promise.all([
createWorkflow({ active: true }),
createWorkflow({ active: false }),
createWorkflow({ active: true }),
]);

//
// ACT
//
const activeIds = await Container.get(WorkflowRepository).getActiveIds({ maxResults: 1 });

//
// ASSERT
//
expect(activeIds).toHaveLength(1);
});
});
});
Loading