import { StepDecorator } from "./stepDecorator"; import MetricService, { EndFunction } from "../../services/metric.service"; import { Step } from "../step"; import { ChoiceRequest } from "../../models"; import { StepResult } from "../stepResult"; import constants from "../../utils/constants"; class MetricStep extends StepDecorator { private readonly metricService: MetricService; constructor(step: Step) { super(step); this.metricService = MetricService.getInstance(); this.metricService.addSection( this.step.getMetricName(), this.step.getLabels(), this.step.getMetricBucket() ); this.metricService.addHistogram( constants.STEP_CAMPAIGN_NUM_METRIC, "Number of campaigns in and out of the step", ["step", "stage"], [1, 2, 5, 10, 20, 30, 50, 70, 100, 200] ); } async execute(request: ChoiceRequest): Promise { this.metricService.observeWithReq( request, constants.STEP_CAMPAIGN_NUM_METRIC, request.campaigns.length, { step: this.getName(), stage: "in", } ); const end: EndFunction = this.metricService.startSectionWithReq( request, this.step.getMetricName() ); const result: StepResult = await this.step.execute(request); result.setMetricLabel("fill", result.passedCampaigns.length > 0); if (result.error) { result.setMetricLabel("error_code", result.error.code); end(false, result.labelValues); } else { end(true, result.labelValues); } this.metricService.observeWithReq( request, constants.STEP_CAMPAIGN_NUM_METRIC, result.passedCampaigns.length, { step: this.getName(), stage: "out", } ); return result; } } export default MetricStep;