Skip to content

Commit 4b59fa2

Browse files
committed
fix(infra): address Greptile review feedback on Vector setup
- Fix broken heredoc delimiter by adding leading newline to REFRESH_VERSIONS_SCRIPT (P1 — Vector would never start) - Pre-seed empty allowed-versions.csv and make initial refresh best-effort so Vector starts even if npm is unreachable - Pin Vector install to specific RPM version instead of curl | bash - Derive CloudWatch region from CDK stack instead of hardcoding
1 parent 6bb9567 commit 4b59fa2

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

infrastructure/lib/constructs/Metrics.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CfnOutput } from "aws-cdk-lib";
1+
import { CfnOutput, Stack } from "aws-cdk-lib";
22
import {
33
AmazonLinuxCpuType,
44
CfnEIP,
@@ -18,7 +18,8 @@ import {
1818
import { ManagedPolicy, Role, ServicePrincipal } from "aws-cdk-lib/aws-iam";
1919
import { Construct } from "constructs";
2020

21-
const VECTOR_CONFIG = `
21+
function vectorConfig(region: string): string {
22+
return `
2223
[sources.statsd_in]
2324
type = "statsd"
2425
address = "0.0.0.0:8125"
@@ -44,10 +45,12 @@ condition = '''
4445
type = "aws_cloudwatch_metrics"
4546
inputs = ["filter_valid_versions"]
4647
default_namespace = "Skybridge"
47-
region = "us-east-1"
48+
region = "${region}"
4849
`;
50+
}
4951

50-
const REFRESH_VERSIONS_SCRIPT = `#!/bin/bash
52+
const REFRESH_VERSIONS_SCRIPT = `
53+
#!/bin/bash
5154
# Fetch all published skybridge versions from npm and extract unique major.minor pairs.
5255
# Vector reloads enrichment tables automatically when the file changes.
5356
set -euo pipefail
@@ -103,18 +106,19 @@ export class Metrics extends Construct {
103106

104107
const userData = UserData.forLinux();
105108
userData.addCommands(
106-
// Install Vector (ARM64 package for t4g instances)
107-
"curl -1sLf https://repositories.timber.io/public/vector/cfg/setup/bash.rpm.sh | bash",
108-
"yum install -y vector jq",
109+
// Install Vector (pinned ARM64 RPM) and jq
110+
"yum install -y jq",
111+
"rpm -i https://packages.timber.io/vector/0.45.0/vector-0.45.0-1.aarch64.rpm",
109112

110113
// Write Vector config
111114
"mkdir -p /etc/vector",
112-
`cat > /etc/vector/vector.toml << 'VECTORCFG'${VECTOR_CONFIG}VECTORCFG`,
115+
`cat > /etc/vector/vector.toml << 'VECTORCFG'${vectorConfig(Stack.of(this).region)}VECTORCFG`,
113116

114-
// Seed allowed-versions.csv so Vector can start before the first cron run
117+
// Seed allowed-versions.csv so Vector can start even if npm is unreachable
118+
"echo 'version' > /etc/vector/allowed-versions.csv",
115119
`cat > /etc/vector/refresh-versions.sh << 'SCRIPT'${REFRESH_VERSIONS_SCRIPT}SCRIPT`,
116120
"chmod +x /etc/vector/refresh-versions.sh",
117-
"/etc/vector/refresh-versions.sh",
121+
"/etc/vector/refresh-versions.sh || true",
118122

119123
// Schedule version list refresh every 15 minutes
120124
'echo "*/15 * * * * root /etc/vector/refresh-versions.sh" > /etc/cron.d/refresh-skybridge-versions',

0 commit comments

Comments
 (0)