|
| 1 | +import { Construct } from 'constructs'; |
| 2 | +import { utils } from '@aws-quickstart/eks-blueprints'; |
| 3 | +import * as blueprints from '@aws-quickstart/eks-blueprints'; |
| 4 | +import { GrafanaOperatorSecretAddon } from '../single-new-eks-opensource-observability-pattern/grafanaoperatorsecretaddon'; |
| 5 | +import * as amp from 'aws-cdk-lib/aws-aps'; |
| 6 | +import { ObservabilityBuilder } from '@aws-quickstart/eks-blueprints'; |
| 7 | +import * as eks from 'aws-cdk-lib/aws-eks'; |
| 8 | +import * as fs from 'fs'; |
| 9 | + |
| 10 | +export default class SingleNewEksFargateOpenSourceObservabilityConstruct { |
| 11 | + constructor(scope: Construct, id: string) { |
| 12 | + const stackId = `${id}-observability-accelerator`; |
| 13 | + |
| 14 | + const account = process.env.COA_ACCOUNT_ID! || process.env.CDK_DEFAULT_ACCOUNT!; |
| 15 | + const region = process.env.COA_AWS_REGION! || process.env.CDK_DEFAULT_REGION!; |
| 16 | + const ampWorkspaceName = process.env.COA_AMP_WORKSPACE_NAME! || 'observability-amp-Workspace'; |
| 17 | + const ampWorkspace = blueprints.getNamedResource(ampWorkspaceName) as unknown as amp.CfnWorkspace; |
| 18 | + const ampEndpoint = ampWorkspace.attrPrometheusEndpoint; |
| 19 | + const ampWorkspaceArn = ampWorkspace.attrArn; |
| 20 | + |
| 21 | + const amgEndpointUrl = process.env.COA_AMG_ENDPOINT_URL; |
| 22 | + // All Grafana Dashboard URLs from `cdk.json` |
| 23 | + const fluxRepository: blueprints.FluxGitRepo = utils.valueFromContext(scope, "fluxRepository", undefined); |
| 24 | + fluxRepository.values!.AMG_AWS_REGION = region; |
| 25 | + fluxRepository.values!.AMP_ENDPOINT_URL = ampEndpoint; |
| 26 | + fluxRepository.values!.AMG_ENDPOINT_URL = amgEndpointUrl; |
| 27 | + |
| 28 | + const ampAddOnProps: blueprints.AmpAddOnProps = { |
| 29 | + ampPrometheusEndpoint: ampEndpoint, |
| 30 | + ampRules: { |
| 31 | + ampWorkspaceArn: ampWorkspaceArn, |
| 32 | + ruleFilePaths: [ |
| 33 | + __dirname + '/../common/resources/amp-config/alerting-rules.yml', |
| 34 | + __dirname + '/../common/resources/amp-config/recording-rules.yml' |
| 35 | + ] |
| 36 | + } |
| 37 | + }; |
| 38 | + |
| 39 | + let doc = utils.readYamlDocument(__dirname + '/../common/resources/otel-collector-config.yml'); |
| 40 | + doc = utils.changeTextBetweenTokens( |
| 41 | + doc, |
| 42 | + "{{ if enableAPIserverJob }}", |
| 43 | + "{{ end }}", |
| 44 | + true |
| 45 | + ); |
| 46 | + console.log(doc); |
| 47 | + fs.writeFileSync(__dirname + '/../common/resources/otel-collector-config-new.yml', doc); |
| 48 | + |
| 49 | + |
| 50 | + if (utils.valueFromContext(scope, "java.pattern.enabled", false)) { |
| 51 | + ampAddOnProps.openTelemetryCollector = { |
| 52 | + manifestPath: __dirname + '/../common/resources/otel-collector-config-new.yml', |
| 53 | + manifestParameterMap: { |
| 54 | + javaScrapeSampleLimit: 1000, |
| 55 | + javaPrometheusMetricsEndpoint: "/metrics" |
| 56 | + } |
| 57 | + }; |
| 58 | + ampAddOnProps.ampRules?.ruleFilePaths.push( |
| 59 | + __dirname + '/../common/resources/amp-config/java/alerting-rules.yml', |
| 60 | + __dirname + '/../common/resources/amp-config/java/recording-rules.yml' |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + if (utils.valueFromContext(scope, "apiserver.pattern.enabled", false)) { |
| 65 | + ampAddOnProps.enableAPIServerJob = true, |
| 66 | + ampAddOnProps.ampRules?.ruleFilePaths.push( |
| 67 | + __dirname + '/../common/resources/amp-config/apiserver/recording-rules.yml' |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + if (utils.valueFromContext(scope, "nginx.pattern.enabled", false)) { |
| 72 | + ampAddOnProps.openTelemetryCollector = { |
| 73 | + manifestPath: __dirname + '/../common/resources/otel-collector-config-new.yml', |
| 74 | + manifestParameterMap: { |
| 75 | + javaScrapeSampleLimit: 1000, |
| 76 | + javaPrometheusMetricsEndpoint: "/metrics" |
| 77 | + } |
| 78 | + }; |
| 79 | + ampAddOnProps.ampRules?.ruleFilePaths.push( |
| 80 | + __dirname + '/../common/resources/amp-config/nginx/alerting-rules.yml' |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + Reflect.defineMetadata("ordered", true, blueprints.addons.GrafanaOperatorAddon); |
| 85 | + const addOns: Array<blueprints.ClusterAddOn> = [ |
| 86 | + new blueprints.addons.VpcCniAddOn(), |
| 87 | + new blueprints.addons.CoreDnsAddOn({ |
| 88 | + version: "v1.10.1-eksbuild.1", |
| 89 | + configurationValues: { computeType: "Fargate" } |
| 90 | + }), |
| 91 | + new blueprints.addons.KubeProxyAddOn(), |
| 92 | + new blueprints.addons.AwsLoadBalancerControllerAddOn(), |
| 93 | + new blueprints.addons.CertManagerAddOn({ |
| 94 | + installCRDs: true, |
| 95 | + createNamespace: true, |
| 96 | + namespace: "cert-manager", |
| 97 | + values: { webhook: { securePort: 10260 } } |
| 98 | + }), |
| 99 | + new blueprints.addons.KubeStateMetricsAddOn(), |
| 100 | + new blueprints.addons.MetricsServerAddOn(), |
| 101 | + new blueprints.addons.CloudWatchLogsAddon({ |
| 102 | + logGroupPrefix: `/aws/eks/${stackId}`, |
| 103 | + logRetentionDays: 30 |
| 104 | + }), |
| 105 | + new blueprints.addons.ExternalsSecretsAddOn({ |
| 106 | + namespace: "external-secrets", |
| 107 | + values: { webhook: { port: 9443 } } |
| 108 | + }), |
| 109 | + new blueprints.addons.GrafanaOperatorAddon(), |
| 110 | + new blueprints.addons.FluxCDAddOn({"repositories": [fluxRepository]}), |
| 111 | + new GrafanaOperatorSecretAddon(), |
| 112 | + new blueprints.addons.AdotCollectorAddOn(), |
| 113 | + new blueprints.addons.XrayAdotAddOn(), |
| 114 | + new blueprints.addons.AmpAddOn(ampAddOnProps) |
| 115 | + ]; |
| 116 | + |
| 117 | + |
| 118 | + const fargateProfiles: Map<string, eks.FargateProfileOptions> = new Map([ |
| 119 | + ["MyProfile", { |
| 120 | + selectors: [ |
| 121 | + { namespace: "cert-manager" }, |
| 122 | + { namespace: "opentelemetry-operator-system" }, |
| 123 | + { namespace: "external-secrets" }, |
| 124 | + { namespace: "grafana-operator" }, |
| 125 | + { namespace: "flux-system" } |
| 126 | + ] |
| 127 | + }] |
| 128 | + ]); |
| 129 | + |
| 130 | + // Define fargate cluster provider and pass the profile options |
| 131 | + const fargateClusterProvider: blueprints.FargateClusterProvider = new blueprints.FargateClusterProvider({ |
| 132 | + fargateProfiles, |
| 133 | + version: eks.KubernetesVersion.of("1.27") |
| 134 | + }); |
| 135 | + |
| 136 | + ObservabilityBuilder.builder() |
| 137 | + .account(account) |
| 138 | + .region(region) |
| 139 | + .clusterProvider(fargateClusterProvider) |
| 140 | + .resourceProvider(ampWorkspaceName, new blueprints.CreateAmpProvider(ampWorkspaceName, ampWorkspaceName)) |
| 141 | + .addOns(...addOns) |
| 142 | + .build(scope, stackId); |
| 143 | + } |
| 144 | +} |
0 commit comments