diff --git a/doc/enhancedMetrics.md b/doc/enhancedMetrics.md new file mode 100644 index 00000000..3463bcfa --- /dev/null +++ b/doc/enhancedMetrics.md @@ -0,0 +1,18 @@ +# Enhanced Metrics + +AppSync supports [Enhanced metrics](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cw-metrics). You can find the metrics configuration under the `appSync.enhancedMetrics` attribute. + +## Quick start + +```yaml +appSync: + name: my-api + enhancedMetrics: + DataSourceLevelMetricsBehavior: 'FULL_REQUEST_DATA_SOURCE_METRICS' + OperationLevelMetricsConfig: 'ENABLED' +``` + +## Configuration +See [official documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-enhancedmetricsconfig.html). + +Note `ResolverLevelMetricsBehavior` is fixed to `PER_RESOLVER_METRICS` with each resolver's `MetricsConfig` set to `DISABLED` diff --git a/doc/general-config.md b/doc/general-config.md index 8cb91965..7225943a 100644 --- a/doc/general-config.md +++ b/doc/general-config.md @@ -46,6 +46,7 @@ appSync: - `pipelineFunctions`: See [Pipeline functions](pipeline-functions.md) - `substitutions`: See [Substitutions](substitutions.md). Deprecated: Use environment variables. - `environment`: A list of environment variables for the API. See [Official Documentation](https://docs.aws.amazon.com/appsync/latest/devguide/environmental-variables.html) +- `enhancedMetrics`: See [enhanced metrics](enhancedMetrics.md) - `caching`: See [Cacing](caching.md) - `waf`: See [Web Application Firefall](WAF.md) - `logging`: See [Logging](#Logging) diff --git a/src/__tests__/resolvers.test.ts b/src/__tests__/resolvers.test.ts index 55439d64..c2af4724 100644 --- a/src/__tests__/resolvers.test.ts +++ b/src/__tests__/resolvers.test.ts @@ -164,6 +164,7 @@ describe('Resolvers', () => { "FieldName": "user", "Kind": "UNIT", "MaxBatchSize": undefined, + "MetricsConfig": "DISABLED", "RequestMappingTemplate": "Content of path/to/mappingTemplates/Query.user.request.vtl", "ResponseMappingTemplate": "Content of path/to/mappingTemplates/Query.user.response.vtl", "TypeName": "Query", @@ -218,6 +219,7 @@ describe('Resolvers', () => { "FieldName": "user", "Kind": "UNIT", "MaxBatchSize": undefined, + "MetricsConfig": "DISABLED", "Runtime": Object { "Name": "APPSYNC_JS", "RuntimeVersion": "1.0.0", @@ -272,6 +274,7 @@ describe('Resolvers', () => { "FieldName": "user", "Kind": "UNIT", "MaxBatchSize": undefined, + "MetricsConfig": "DISABLED", "TypeName": "Query", }, "Type": "AWS::AppSync::Resolver", @@ -323,6 +326,7 @@ describe('Resolvers', () => { "FieldName": "user", "Kind": "UNIT", "MaxBatchSize": 200, + "MetricsConfig": "DISABLED", "TypeName": "Query", }, "Type": "AWS::AppSync::Resolver", @@ -380,6 +384,7 @@ describe('Resolvers', () => { "FieldName": "user", "Kind": "UNIT", "MaxBatchSize": undefined, + "MetricsConfig": "DISABLED", "SyncConfig": Object { "ConflictDetection": "VERSION", "ConflictHandler": "LAMBDA", @@ -478,6 +483,7 @@ describe('Resolvers', () => { ", "FieldName": "user", "Kind": "PIPELINE", + "MetricsConfig": "DISABLED", "PipelineConfig": Object { "Functions": Array [ Object { @@ -547,6 +553,7 @@ describe('Resolvers', () => { }, "FieldName": "user", "Kind": "PIPELINE", + "MetricsConfig": "DISABLED", "PipelineConfig": Object { "Functions": Array [ Object { @@ -615,6 +622,7 @@ describe('Resolvers', () => { "Code": "Bundled content of resolvers/getUserFunction.js", "FieldName": "user", "Kind": "PIPELINE", + "MetricsConfig": "DISABLED", "PipelineConfig": Object { "Functions": Array [ Object { @@ -1006,6 +1014,7 @@ describe('Resolvers', () => { "FieldName": "user", "Kind": "UNIT", "MaxBatchSize": undefined, + "MetricsConfig": "DISABLED", "TypeName": "Query", }, "Type": "AWS::AppSync::Resolver", @@ -1070,6 +1079,7 @@ describe('Resolvers', () => { "FieldName": "user", "Kind": "UNIT", "MaxBatchSize": undefined, + "MetricsConfig": "DISABLED", "TypeName": "Query", }, "Type": "AWS::AppSync::Resolver", @@ -1134,6 +1144,7 @@ describe('Resolvers', () => { "FieldName": "user", "Kind": "UNIT", "MaxBatchSize": undefined, + "MetricsConfig": "DISABLED", "TypeName": "Query", }, "Type": "AWS::AppSync::Resolver", diff --git a/src/resources/Api.ts b/src/resources/Api.ts index 92a9663a..6da7433b 100644 --- a/src/resources/Api.ts +++ b/src/resources/Api.ts @@ -112,6 +112,18 @@ export class Api { }); } + if (this.config.enhancedMetrics) { + merge(endpointResource.Properties, { + EnhancedMetricsConfig: { + DataSourceLevelMetricsBehavior: + this.config.enhancedMetrics.DataSourceLevelMetricsBehavior, + OperationLevelMetricsConfig: + this.config.enhancedMetrics.OperationLevelMetricsConfig, + ResolverLevelMetricsBehavior: 'PER_RESOLVER_METRICS', + }, + }); + } + if (this.config.introspection !== undefined) { merge(endpointResource.Properties, { IntrospectionConfig: this.config.introspection ? 'ENABLED' : 'DISABLED', diff --git a/src/resources/Resolver.ts b/src/resources/Resolver.ts index e7f11029..09027738 100644 --- a/src/resources/Resolver.ts +++ b/src/resources/Resolver.ts @@ -29,6 +29,7 @@ export class Resolver { ApiId: this.api.getApiId(), TypeName: this.config.type, FieldName: this.config.field, + MetricsConfig: 'DISABLED', }; const isVTLResolver = 'request' in this.config || 'response' in this.config; diff --git a/src/types/cloudFormation.ts b/src/types/cloudFormation.ts index 6100d4e9..a52572cf 100644 --- a/src/types/cloudFormation.ts +++ b/src/types/cloudFormation.ts @@ -117,6 +117,7 @@ export type CfnResolver = { }; }; MaxBatchSize?: number; + MetricsConfig?: 'ENABLED' | 'DISABLED'; }; }; diff --git a/src/types/common.ts b/src/types/common.ts index cc8157b9..20660c78 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -46,6 +46,7 @@ export type WafRuleThrottle = { }; export type WafRuleCustom = { + overrideAction?: any; name: string; priority?: number; action?: WafRuleAction; @@ -129,6 +130,15 @@ export type SyncConfig = { export type Substitutions = Record; export type EnvironmentVariables = Record; +export type EnhancedMetricsConfig = { + DataSourceLevelMetricsBehavior: + | 'FULL_REQUEST_DATA_SOURCE_METRICS' + | 'PER_DATA_SOURCE_METRICS'; + OperationLevelMetricsConfig: 'ENABLED' | ' DISABLED'; + ResolverLevelMetricsBehavior: + | 'FULL_REQUEST_RESOLVER_METRICS' + | 'PER_RESOLVER_METRICS'; +}; export type DsDynamoDBConfig = { type: 'AMAZON_DYNAMODB'; diff --git a/src/types/plugin.ts b/src/types/plugin.ts index 0b8bf8f0..4d04d5a3 100644 --- a/src/types/plugin.ts +++ b/src/types/plugin.ts @@ -16,6 +16,7 @@ import { DsNone, Substitutions, EnvironmentVariables, + EnhancedMetricsConfig, } from './common'; export * from './common'; @@ -31,6 +32,7 @@ export type AppSyncConfig = { pipelineFunctions: Record; substitutions?: Substitutions; environment?: EnvironmentVariables; + enhancedMetrics?: EnhancedMetricsConfig; xrayEnabled?: boolean; logging?: LoggingConfig; caching?: CachingConfig; diff --git a/src/validation.ts b/src/validation.ts index 4cc292e0..1cbe5959 100644 --- a/src/validation.ts +++ b/src/validation.ts @@ -810,6 +810,22 @@ export const appSyncSchema = { }, required: ['level'], }, + enhancedMetrics: { + type: 'object', + properties: { + DataSourceLevelMetricsBehavior: { + type: 'string', + enum: ['FULL_REQUEST_DATA_SOURCE_METRICS', 'PER_DATA_SOURCE_METRICS'], + errorMessage: + "must be 'FULL_REQUEST_DATA_SOURCE_METRICS' or 'PER_DATA_SOURCE_METRICS'", + }, + OperationLevelMetricsConfig: { + type: 'string', + enum: ['ENABLED', ' DISABLED'], + errorMessage: "must be 'ENABLED' or ' DISABLED'", + }, + }, + }, dataSources: { oneOf: [ {