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

V3 canary #556

Merged
merged 3 commits into from
Dec 5, 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
63 changes: 63 additions & 0 deletions modules/metrics/cron-duration-metrics.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
CloudWatchClient,
CloudWatchClientConfig,
MetricDatum,
PutMetricDataCommand,
} from '@aws-sdk/client-cloudwatch';
import { env } from '../../app/env';

export interface NotificationsCloudwatchMetric {
merticData: MetricDatum[];
nameSpace: string;
}

export class CloudwatchCronDurationMetricsPublisher {
protected environment: string;
protected configuration?: CloudWatchClientConfig;
private client: CloudWatchClient;
public namespace: string;

constructor(
namespace: string = 'default',
environment: string = env.DEPLOYMENT_ENV,
configuration?: CloudWatchClientConfig,
) {
this.namespace = namespace;
this.environment = environment;
this.client = new CloudWatchClient({ region: env.AWS_REGION, ...configuration });
}

public async publish(metricName: string, count?: number): Promise<void> {
const [major, minor, patch] = process.versions.node.split('.').map(Number);
try {
const command = new PutMetricDataCommand({
MetricData: [
{
MetricName: metricName,
Dimensions: [
{
Name: 'Environment',
Value: this.environment,
},
{
Name: 'NodeVersion',
Value: major.toString(),
},
],
Unit: 'None',
Timestamp: new Date(),
Value: count ? count : 1,
},
],
Namespace: this.namespace,
});

await this.client.send(command);
} catch (err) {
// Sentry.captureException(`Failed to publish "${metricName}" in "${this.environment}: ${err}`);
console.log(`Failed to publish "${metricName}" in "${this.environment}: ${err}`);
}
}
}

export const cronsDurationMetricPublisher = new CloudwatchCronDurationMetricsPublisher('backendCronsDuration');
1 change: 0 additions & 1 deletion modules/pool/lib/pool-onchain-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ const getTotalSupplyFn = (type: PoolInput['type'], version: number) => {
} else if (
type === 'COMPOSABLE_STABLE' ||
(type === 'WEIGHTED' && version > 1) ||
(type === 'GYROE' && version > 1) ||
(type === 'UNKNOWN' && version > 1)
) {
return 'getActualSupply';
Expand Down
7 changes: 7 additions & 0 deletions worker/job-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { networkContext } from '../modules/network/network-context.service';
import { veBalService } from '../modules/vebal/vebal.service';
import { veBalVotingListService } from '../modules/vebal/vebal-voting-list.service';
import { cronsMetricPublisher } from '../modules/metrics/metrics.client';
import moment from 'moment';
import { cronsDurationMetricPublisher } from '../modules/metrics/cron-duration-metrics.client';

const runningJobs: Set<string> = new Set();

Expand All @@ -31,6 +33,7 @@ async function runIfNotAlreadyRunning(
res.sendStatus(200);
return;
}
const startJobTime = moment();
try {
runningJobs.add(jobId);

Expand All @@ -44,13 +47,17 @@ async function runIfNotAlreadyRunning(

await fn();

const durationSuccess = moment.duration(moment().diff(startJobTime)).asSeconds();
if (process.env.AWS_ALERTS === 'true') {
await cronsMetricPublisher.publish(`${jobId}-done`);
await cronsDurationMetricPublisher.publish(`${jobId}-done`, durationSuccess);
}
console.log(`Successful job ${jobId}-done`);
} catch (error) {
const durationError = moment.duration(moment().diff(startJobTime)).asSeconds();
if (process.env.AWS_ALERTS === 'true') {
await cronsMetricPublisher.publish(`${jobId}-error`);
await cronsDurationMetricPublisher.publish(`${jobId}-error`, durationError);
}
console.log(`Error job ${jobId}-error`, error);
next(error);
Expand Down