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

Feat/enhanced metrics #644

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
18 changes: 18 additions & 0 deletions doc/enhancedMetrics.md
Original file line number Diff line number Diff line change
@@ -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`
3 changes: 2 additions & 1 deletion doc/general-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ appSync:
- `resolvers`: See [Resolvers](resolvers.md)
- `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/environment-variables.html)
- `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)
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -218,6 +219,7 @@ describe('Resolvers', () => {
"FieldName": "user",
"Kind": "UNIT",
"MaxBatchSize": undefined,
"MetricsConfig": "DISABLED",
"Runtime": Object {
"Name": "APPSYNC_JS",
"RuntimeVersion": "1.0.0",
Expand Down Expand Up @@ -272,6 +274,7 @@ describe('Resolvers', () => {
"FieldName": "user",
"Kind": "UNIT",
"MaxBatchSize": undefined,
"MetricsConfig": "DISABLED",
"TypeName": "Query",
},
"Type": "AWS::AppSync::Resolver",
Expand Down Expand Up @@ -323,6 +326,7 @@ describe('Resolvers', () => {
"FieldName": "user",
"Kind": "UNIT",
"MaxBatchSize": 200,
"MetricsConfig": "DISABLED",
"TypeName": "Query",
},
"Type": "AWS::AppSync::Resolver",
Expand Down Expand Up @@ -380,6 +384,7 @@ describe('Resolvers', () => {
"FieldName": "user",
"Kind": "UNIT",
"MaxBatchSize": undefined,
"MetricsConfig": "DISABLED",
"SyncConfig": Object {
"ConflictDetection": "VERSION",
"ConflictHandler": "LAMBDA",
Expand Down Expand Up @@ -478,6 +483,7 @@ describe('Resolvers', () => {
",
"FieldName": "user",
"Kind": "PIPELINE",
"MetricsConfig": "DISABLED",
"PipelineConfig": Object {
"Functions": Array [
Object {
Expand Down Expand Up @@ -547,6 +553,7 @@ describe('Resolvers', () => {
},
"FieldName": "user",
"Kind": "PIPELINE",
"MetricsConfig": "DISABLED",
"PipelineConfig": Object {
"Functions": Array [
Object {
Expand Down Expand Up @@ -615,6 +622,7 @@ describe('Resolvers', () => {
"Code": "Bundled content of resolvers/getUserFunction.js",
"FieldName": "user",
"Kind": "PIPELINE",
"MetricsConfig": "DISABLED",
"PipelineConfig": Object {
"Functions": Array [
Object {
Expand Down Expand Up @@ -1006,6 +1014,7 @@ describe('Resolvers', () => {
"FieldName": "user",
"Kind": "UNIT",
"MaxBatchSize": undefined,
"MetricsConfig": "DISABLED",
"TypeName": "Query",
},
"Type": "AWS::AppSync::Resolver",
Expand Down Expand Up @@ -1070,6 +1079,7 @@ describe('Resolvers', () => {
"FieldName": "user",
"Kind": "UNIT",
"MaxBatchSize": undefined,
"MetricsConfig": "DISABLED",
"TypeName": "Query",
},
"Type": "AWS::AppSync::Resolver",
Expand Down Expand Up @@ -1134,6 +1144,7 @@ describe('Resolvers', () => {
"FieldName": "user",
"Kind": "UNIT",
"MaxBatchSize": undefined,
"MetricsConfig": "DISABLED",
"TypeName": "Query",
},
"Type": "AWS::AppSync::Resolver",
Expand Down
12 changes: 12 additions & 0 deletions src/resources/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/resources/Resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/types/cloudFormation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type CfnResolver = {
};
};
MaxBatchSize?: number;
MetricsConfig?: 'ENABLED' | 'DISABLED';
};
};

Expand Down
9 changes: 9 additions & 0 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ export type SyncConfig = {

export type Substitutions = Record<string, string | IntrinsicFunction>;
export type EnvironmentVariables = Record<string, string | IntrinsicFunction>;
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';
Expand Down
2 changes: 2 additions & 0 deletions src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DsNone,
Substitutions,
EnvironmentVariables,
EnhancedMetricsConfig,
} from './common';
export * from './common';

Expand All @@ -31,6 +32,7 @@ export type AppSyncConfig = {
pipelineFunctions: Record<string, PipelineFunctionConfig>;
substitutions?: Substitutions;
environment?: EnvironmentVariables;
enhancedMetrics?: EnhancedMetricsConfig;
xrayEnabled?: boolean;
logging?: LoggingConfig;
caching?: CachingConfig;
Expand Down
16 changes: 16 additions & 0 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,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: [
{
Expand Down