Skip to content

Commit

Permalink
fix: apply account/region to more metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
echeung-amzn committed Jul 31, 2024
1 parent ac4c320 commit 3f16a10
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 50 deletions.
34 changes: 34 additions & 0 deletions lib/common/metric/MetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ export class MetricFactory {
label,
metric.color,
metric.period,
this.getRegion(metric),
this.getAccount(metric),
);
}
}
Expand Down Expand Up @@ -306,6 +308,8 @@ export class MetricFactory {
label,
metric.color,
metric.period,
this.getRegion(metric),
this.getAccount(metric),
);
}
}
Expand Down Expand Up @@ -361,6 +365,8 @@ export class MetricFactory {
avgLabel,
avgMetric.color,
avgMetric.period,
this.getRegion(avgMetric),
this.getAccount(avgMetric),
);
}
return avgMetric;
Expand All @@ -380,6 +386,8 @@ export class MetricFactory {
perSecondLabel,
metric.color,
metric.period,
this.getRegion(metric),
this.getAccount(metric),
);
case RateComputationMethod.PER_MINUTE:
return this.createMetricMath(
Expand All @@ -388,6 +396,8 @@ export class MetricFactory {
`${labelPrefix}/m${labelAppendix}`,
metric.color,
metric.period,
this.getRegion(metric),
this.getAccount(metric),
);
case RateComputationMethod.PER_HOUR:
return this.createMetricMath(
Expand All @@ -396,6 +406,8 @@ export class MetricFactory {
`${labelPrefix}/h${labelAppendix}`,
metric.color,
metric.period,
this.getRegion(metric),
this.getAccount(metric),
);
case RateComputationMethod.PER_DAY:
return this.createMetricMath(
Expand All @@ -404,6 +416,8 @@ export class MetricFactory {
`${labelPrefix}/d${labelAppendix}`,
metric.color,
metric.period,
this.getRegion(metric),
this.getAccount(metric),
);
}
}
Expand Down Expand Up @@ -480,6 +494,16 @@ export class MetricFactory {

return;
}
private getAccount(metric: MetricWithAlarmSupport): string | undefined {
let metricAccount: string | undefined;
if (metric instanceof MathExpression) {
metricAccount = metric.searchAccount;
} else {
metricAccount = metric.account;
}

return this.resolveAccount(metricAccount);
}

/**
* Attempts to get the region from the metric if it differs from the scope.
Expand All @@ -496,4 +520,14 @@ export class MetricFactory {

return;
}
private getRegion(metric: MetricWithAlarmSupport): string | undefined {
let metricRegion: string | undefined;
if (metric instanceof MathExpression) {
metricRegion = metric.searchRegion;
} else {
metricRegion = metric.region;
}

return this.resolveRegion(metricRegion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class DynamoTableGlobalSecondaryIndexMetricFactory extends BaseMetricFact
consumed_rcu_sum: this.table.metricConsumedReadCapacityUnits({
statistic: MetricStatistic.SUM,
dimensionsMap: this.dimensionsMap,
region: this.region,
account: this.account,
}),
},
"Consumed",
Expand All @@ -81,6 +83,8 @@ export class DynamoTableGlobalSecondaryIndexMetricFactory extends BaseMetricFact
consumed_wcu_sum: this.table.metricConsumedWriteCapacityUnits({
statistic: MetricStatistic.SUM,
dimensionsMap: this.dimensionsMap,
region: this.region,
account: this.account,
}),
},
"Consumed",
Expand Down
20 changes: 20 additions & 0 deletions lib/monitoring/aws-dynamo/DynamoTableMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export class DynamoTableMetricFactory extends BaseMetricFactory<DynamoTableMetri
}),
},
ConsumedLabel,
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -86,6 +90,10 @@ export class DynamoTableMetricFactory extends BaseMetricFactory<DynamoTableMetri
}),
},
ConsumedLabel,
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -97,6 +105,10 @@ export class DynamoTableMetricFactory extends BaseMetricFactory<DynamoTableMetri
provisioned_read_cap: this.metricProvisionedReadCapacityUnits(),
},
"Utilization",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -108,6 +120,10 @@ export class DynamoTableMetricFactory extends BaseMetricFactory<DynamoTableMetri
provisioned_write_cap: this.metricProvisionedWriteCapacityUnits(),
},
"Utilization",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -121,6 +137,10 @@ export class DynamoTableMetricFactory extends BaseMetricFactory<DynamoTableMetri
},
MetricStatistic.AVERAGE,
DynamoDbNamespace,
undefined,
undefined,
this.region,
this.account,
);
}

Expand Down
12 changes: 12 additions & 0 deletions lib/monitoring/aws-kinesis/KinesisFirehoseMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export class KinesisFirehoseMetricFactory extends BaseMetricFactory<KinesisFireh
bytes_max: this.metricBytesPerSecondLimit(),
},
"Incoming Bytes / Limit",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -162,6 +166,10 @@ export class KinesisFirehoseMetricFactory extends BaseMetricFactory<KinesisFireh
records_max: this.metricRecordsPerSecondLimit(),
},
"Incoming Records / Limit",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -173,6 +181,10 @@ export class KinesisFirehoseMetricFactory extends BaseMetricFactory<KinesisFireh
requests_max: this.metricPutRequestsPerSecondLimit(),
},
"Incoming PutRequests / Limit",
undefined,
undefined,
this.region,
this.account,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export class LambdaFunctionEnhancedMetricFactory extends BaseMetricFactory<Lambd
return this.metricFactory.adaptMetric(
this.lambdaFunction.metricDuration({
statistic: MetricStatistic.SUM,
region: this.region,
account: this.account,
}),
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/monitoring/aws-lambda/LambdaFunctionMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export class LambdaFunctionMetricFactory extends BaseMetricFactory<LambdaFunctio
return this.metricFactory.adaptMetric(
this.lambdaFunction.metricInvocations({
label: "Invocations",
region: this.region,
account: this.account,
}),
);
}
Expand Down
20 changes: 20 additions & 0 deletions lib/monitoring/aws-redshift/RedshiftClusterMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export class RedshiftClusterMetricFactory extends BaseMetricFactory<RedshiftClus
"sQueryLatency90 / 1000",
{ sQueryLatency90 },
"Short P90",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -73,6 +77,10 @@ export class RedshiftClusterMetricFactory extends BaseMetricFactory<RedshiftClus
"mQueryLatency90 / 1000",
{ mQueryLatency90 },
"Medium P90",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -86,6 +94,10 @@ export class RedshiftClusterMetricFactory extends BaseMetricFactory<RedshiftClus
"lQueryLatency90 / 1000",
{ lQueryLatency90 },
"Long P90",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -104,6 +116,10 @@ export class RedshiftClusterMetricFactory extends BaseMetricFactory<RedshiftClus
"readLatency * 1000",
{ readLatency },
"Read P90",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -118,6 +134,10 @@ export class RedshiftClusterMetricFactory extends BaseMetricFactory<RedshiftClus
"writeLatency * 1000",
{ writeLatency },
"Write P90",
undefined,
undefined,
this.region,
this.account,
);
}

Expand Down
12 changes: 12 additions & 0 deletions lib/monitoring/aws-sqs/SqsQueueMetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class SqsQueueMetricFactory extends BaseMetricFactory<SqsQueueMetricFacto
productionVolume: this.metricIncomingMessageCount(),
},
"Production TPS (avg: ${AVG}, max: ${MAX})",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -89,6 +93,10 @@ export class SqsQueueMetricFactory extends BaseMetricFactory<SqsQueueMetricFacto
consumptionVolume: this.metricDeletedMessageCount(),
},
"Consumption TPS (avg: ${AVG}, max: ${MAX})",
undefined,
undefined,
this.region,
this.account,
);
}

Expand All @@ -103,6 +111,10 @@ export class SqsQueueMetricFactory extends BaseMetricFactory<SqsQueueMetricFacto
consumptionVolume: this.metricDeletedMessageCount(),
},
"Time to Drain (seconds) (avg: ${AVG}, max: ${MAX})",
undefined,
undefined,
this.region,
this.account,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ export class StepFunctionServiceIntegrationMetricFactory extends BaseMetricFacto
this.dimensionsMap,
undefined,
Namespace,
undefined,
this.region,
this.account,
);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/monitoring/aws-wafv2/WafV2MetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export class WafV2MetricFactory extends BaseMetricFactory<WafV2MetricFactoryProp
blocked: this.metricBlockedRequests(),
},
"Blocked (rate)",
undefined,
undefined,
this.region,
this.account,
);
}
}
16 changes: 8 additions & 8 deletions test/common/metric/__snapshots__/MetricFactory.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/facade/__snapshots__/MonitoringAspect.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3f16a10

Please sign in to comment.