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

feat!: add method for 'action.invoked' new metric to be implemented #15

Merged
merged 2 commits into from
Nov 20, 2023
Merged
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
6 changes: 5 additions & 1 deletion src/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ export class Recorder {
this.record(new Metric(name, MetricType.Gauge, value, metadata));
}

async recordActionExecution(actionName: string, metadata: MetricMetadata = {}) {
async recordActionExecuted(actionName: string, metadata: MetricMetadata = {}) {
metadata['action'] = actionName;
this.record(new Metric('action.executed', MetricType.Counter, 1, metadata));
}
async recordActionInvoked(actionName: string, metadata: MetricMetadata = {}) {
metadata['action'] = actionName;
this.record(new Metric('action.invoked', MetricType.Counter, 1, metadata));
}

async record(metric: Metric) {
metric.name = this.prefix.endsWith('.') ? this.prefix + metric.name : `${ this.prefix }.${ metric.name }`;
Expand Down
16 changes: 13 additions & 3 deletions test/recorder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ describe('Recorder', function() {
expect(recorderMetricsSpy[0]).toEqual(expectedMetric);
});

it('recordActionExecution()', async function() {
it('recordActionExecuted()', async function() {
const recorderMetricsSpy = [];
const recorder = new Recorder('test', new testSink(), recorderMetricsSpy);
const expectedMetric = new Metric('test.action.executed', MetricType.Counter, 1, { action: 'validate', success: true });

await recorder.recordActionExecution('validate', { success: true });
await recorder.recordActionExecuted('validate', { success: true });
expect(recorderMetricsSpy).toHaveLength(1);
expect(recorderMetricsSpy[0]).toEqual(expectedMetric);
});

it('recordActionInvoked()', async function() {
const recorderMetricsSpy = [];
const recorder = new Recorder('test', new testSink(), recorderMetricsSpy);
const expectedMetric = new Metric('test.action.invoked', MetricType.Counter, 1, { action: 'convert' });

await recorder.recordActionInvoked('convert');
expect(recorderMetricsSpy).toHaveLength(1);
expect(recorderMetricsSpy[0]).toEqual(expectedMetric);
});
Expand All @@ -68,7 +78,7 @@ describe('Recorder', function() {
const {recorder, stop} = WithPeriodicFlushRecorder(new Recorder('test', sink, recorderMetricsSpy), 100);
const expectedMetric = new Metric('test.action.executed', MetricType.Counter, 1, { action: 'validate', success: true });

await recorder.recordActionExecution('validate', { success: true });
await recorder.recordActionExecuted('validate', { success: true });
expect(recorderMetricsSpy).toHaveLength(1);
expect(recorderMetricsSpy[0]).toEqual(expectedMetric);

Expand Down