@@ -15,6 +15,7 @@ import * as appsync from 'aws-cdk-lib/aws-appsync';
15
15
import * as lambda from 'aws-cdk-lib/aws-lambda' ;
16
16
import * as logs from 'aws-cdk-lib/aws-logs' ;
17
17
import { Construct } from 'constructs' ;
18
+ import { ConstructName } from './construct-name-enum' ;
18
19
import { version } from '../helpers/utils' ;
19
20
20
21
@@ -43,7 +44,7 @@ export interface BaseClassProps {
43
44
* name of the construct.
44
45
*
45
46
*/
46
- readonly constructorName : string ;
47
+ readonly constructName : ConstructName ;
47
48
48
49
/**
49
50
* construct id.
@@ -62,8 +63,17 @@ export interface BaseClassProps {
62
63
63
64
export class BaseClass extends Construct {
64
65
65
- static constructIdsStr : string = '' ;
66
- static constructNamesStr : string = '' ;
66
+ protected static usageMetricMap : Record < string , number > = {
67
+ [ ConstructName . AWSRAGAPPSYNCSTEPFNOPENSEARCH ] : 0 ,
68
+ [ ConstructName . AWSQAAPPSYNCOPENSEARCH ] : 0 ,
69
+ [ ConstructName . AWSSUMMARIZATIONAPPSYNCSTEPFN ] : 0 ,
70
+ [ ConstructName . AWSMODELDEPLOYMENTSAGEMAKER ] : 0 ,
71
+ [ ConstructName . CUSTOMSAGEMAKERENDPOINT ] : 0 ,
72
+ [ ConstructName . HUGGINGFACESAGEMAKERENDPOINT ] : 0 ,
73
+ [ ConstructName . JUMPSTARTSAGEMAKERENDPOINT ] : 0 ,
74
+ [ ConstructName . AWSCONTENTGENAPPSYNCLAMBDA ] : 0 ,
75
+ } ;
76
+
67
77
68
78
/**
69
79
* construct usage metric , added in template description
@@ -123,7 +133,7 @@ export class BaseClass extends Construct {
123
133
*/
124
134
protected updateConstructUsageMetricCode ( props : BaseClassProps , scope : Construct , lambdaFunctions : lambda . DockerImageFunction [ ] ,
125
135
) {
126
- const solutionId = `genai_cdk_${ version } /${ props . constructorName } /${ props . constructId } ` ;
136
+ const solutionId = `genai_cdk_${ version } /${ props . constructName } /${ props . constructId } ` ;
127
137
128
138
const enableOperationalMetric =
129
139
props . enableOperationalMetric !== undefined &&
@@ -138,14 +148,19 @@ export class BaseClass extends Construct {
138
148
) ;
139
149
}
140
150
}
141
- // ADD unique key in template description
142
- // format (usage metric id:usbxxxx) (version:1.xx) (construct name:awsappsyncXX1,awsappsyncXX2,awsappsyncXX3) (construct id:awsappsyncxxxx1,awsappsyncxxx2,awsappsyncxxx3)
143
- BaseClass . constructIdsStr = BaseClass . constructIdsStr + ', ' + props . constructId ;
144
- BaseClass . constructNamesStr = BaseClass . constructNamesStr + ', ' + props . constructorName ;
145
-
151
+
152
+ if ( props && BaseClass . usageMetricMap . hasOwnProperty ( props . constructName ) ) {
153
+ BaseClass . usageMetricMap [ props . constructName ] = BaseClass . usageMetricMap [ props . constructName ] + 1 ;
154
+ }
155
+ else {
156
+ throw Error ( 'construct name is not present in usageMetricMap ' )
157
+ }
158
+
159
+ const usageMetricMapSerialized = JSON . stringify ( BaseClass . usageMetricMap ) ;
160
+
161
+
146
162
Stack . of ( scope ) . templateOptions . description =
147
- `(usage id :${ this . constructUsageMetric } )(version:${ version } ) (construct name:::${ BaseClass . constructIdsStr } ) (construct id:::${ BaseClass . constructNamesStr } )` ;
148
-
163
+ `(usage id :${ this . constructUsageMetric } )(version:${ version } ) (constructs :::${ usageMetricMapSerialized } ) ` ;
149
164
150
165
} ;
151
166
}
0 commit comments