Skip to content

feat(mixins-preview): generate metrics facades#37334

Open
leonmk-aws wants to merge 15 commits intomainfrom
leonmk/metrics
Open

feat(mixins-preview): generate metrics facades#37334
leonmk-aws wants to merge 15 commits intomainfrom
leonmk/metrics

Conversation

@leonmk-aws
Copy link
Copy Markdown
Contributor

@leonmk-aws leonmk-aws commented Mar 23, 2026

Description of changes

Automatically generate metrics facades.
Usage:

// L1 / L2 Lambda
const fn: lambda.Function

// Scoped metrics from L2
const fnMetrics = LambdaMetrics.fromFunction(fn);

// Create metric
const metric = fnMetrics.metricErrors();

// Use metric as usual
new cloudwatch.Alarm(this, 'L2ErrorAlarm', {
  metric: metric
  alarmName: 'MixinsPreview-L2-Errors',
  threshold: 5,
  evaluationPeriods: 1,
  comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
});

Generated code structure:

// Generated structure (abbreviated)
export class LambdaMetrics {
  // Factory: create metrics from a Function reference (auto-fills dimensions)
  static fromFunction(ref: IFunctionRef): LambdaMetrics.FunctionNameMetrics;
}

export namespace LambdaMetrics {
  // Per-function metrics (dimension: FunctionName)
  class FunctionNameMetrics {
    constructor(props: { functionName: string });
    metricInvocations(options?: MetricOptions): IMetric;
    metricErrors(options?: MetricOptions): IMetric;
    metricDuration(options?: MetricOptions): IMetric;
    metricThrottles(options?: MetricOptions): IMetric;
    // ... 8 more metric methods
  }

  // Per-function + resource metrics (dimensions: FunctionName, Resource)
  class FunctionNamePerResourceMetrics {
    constructor(props: { functionName: string; resource: string });
    metricInvocations(options?: MetricOptions): IMetric;
    // ... + metricProvisionedConcurrencyUtilization
  }

  // Per-version metrics (dimensions: ExecutedVersion, FunctionName, Resource)
  class ExecutedVersionPerFunctionNamePerResourceMetrics { /* ... */ }

  // Account-level metrics (no dimensions)
  class AccountMetrics {
    constructor();
    metricInvocations(options?: MetricOptions): IMetric;
    metricUnreservedConcurrentExecutions(options?: MetricOptions): IMetric;
    // ...
  }
}

Description of how you validated changes

Added unit and integration test

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Mar 23, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team March 23, 2026 13:50
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 23, 2026
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@leonmk-aws leonmk-aws added the pr/do-not-merge This PR should not be merged at this time. label Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results48 ran48 passed
TestResult
No test annotations available

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates48 ran48 passed
TestResult
No test annotations available

@aws-cdk-automation aws-cdk-automation dismissed their stale review March 23, 2026 14:22

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Copy link
Copy Markdown
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the codegen directly into spec2cdk and just have the most minimal wrapper code in mixins-preview. I think it was a mistake to have it not in the shared package. See the cfn prop mixins on how this can be done generating into any destination.

Also, should we have a separate preview/alpha package? Feels like we have now decided that mixins-preview should be removed soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. p2 pr/do-not-merge This PR should not be merged at this time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants