Skip to content

Commit 7486ceb

Browse files
committed
fix: resolve OTEL collector YAML syntax error and add validation tools
- Fixed syntax error on line 306 of otel-collector.yaml (removed rogue 'z' character) - Added pre-commit, yamllint, and cfn-lint for automated template validation - Created validation script compatible with existing git hooks - Updated README with development validation instructions - Validation now runs automatically on every commit to prevent deployment failures Fixes #13
1 parent 02d3b5f commit 7486ceb

File tree

6 files changed

+819
-19
lines changed

6 files changed

+819
-19
lines changed

.pre-commit-config.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Pre-commit hooks for CloudFormation and YAML validation
2+
# Run `pre-commit install` to set up the git hook scripts
3+
# See https://pre-commit.com for more information
4+
5+
repos:
6+
# YAML syntax validation
7+
- repo: https://github.com/adrienverge/yamllint
8+
rev: v1.33.0
9+
hooks:
10+
- id: yamllint
11+
name: Validate YAML syntax
12+
args: ['-d', 'relaxed']
13+
files: \.(yaml|yml)$
14+
exclude: ^(source/build/|source/dist/)
15+
16+
# CloudFormation template validation
17+
- repo: https://github.com/aws-cloudformation/cfn-lint
18+
rev: v0.83.8
19+
hooks:
20+
- id: cfn-lint
21+
name: Validate CloudFormation templates
22+
files: deployment/infrastructure/.*\.(yaml|yml)$
23+
args: ['--ignore-checks', 'W3002'] # W3002 is for optional resource properties
24+
25+
# Custom AWS validation (requires AWS credentials)
26+
- repo: local
27+
hooks:
28+
- id: validate-cfn-templates
29+
name: Validate CloudFormation with AWS CLI
30+
entry: scripts/validate-cloudformation.sh
31+
language: script
32+
files: deployment/infrastructure/.*\.(yaml|yml)$
33+
pass_filenames: true
34+
# This hook will only run if AWS credentials are configured
35+
# It provides additional validation beyond cfn-lint

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,42 @@ Detailed setup guides are available for:
382382
- [Microsoft Entra ID (Azure AD)](/assets/docs/providers/microsoft-entra-id-setup.md)
383383
- [Auth0](/assets/docs/providers/auth0-setup.md)
384384

385+
## Development
386+
387+
### CloudFormation Template Validation
388+
389+
This project includes automated validation tools that catch CloudFormation and YAML syntax errors before deployment.
390+
391+
#### Setup Validation Tools
392+
393+
```bash
394+
cd source
395+
poetry install # Installs validation dependencies including pre-commit, yamllint, and cfn-lint
396+
397+
# Install pre-commit hooks
398+
poetry run pre-commit install
399+
```
400+
401+
#### How It Works
402+
403+
When you commit changes, the following validations run automatically:
404+
- **YAML validation** checks syntax in all `.yaml` files
405+
- **CloudFormation validation** checks template structure and properties
406+
- **AWS CLI validation** validates templates against AWS specifications (if credentials are configured)
407+
408+
The validation automatically catches:
409+
- YAML syntax errors that would cause deployment failures
410+
- CloudFormation template structure problems
411+
- Missing required parameters or invalid resource configurations
412+
413+
#### Manual Validation (Optional)
414+
415+
To run validation without committing:
416+
```bash
417+
cd source
418+
poetry run pre-commit run --all-files
419+
```
420+
385421
## License
386422

387423
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

deployment/infrastructure/otel-collector.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Resources:
303303
304304
receivers:
305305
otlp:
306-
protocols:z
306+
protocols:
307307
grpc:
308308
endpoint: 0.0.0.0:4317
309309
include_metadata: true
@@ -374,43 +374,43 @@ Resources:
374374
# Core user dimensions
375375
- dimensions: [[user.id, aws.account_id, OTelLib]]
376376
metric_name_selectors: [".*"]
377-
377+
378378
# Team and organization dimensions
379379
- dimensions: [[department, team.id, cost_center, organization, OTelLib]]
380380
metric_name_selectors: [".*"]
381381
- dimensions: [[department, team.id, OTelLib]]
382382
metric_name_selectors: [".*"]
383383
- dimensions: [[cost_center, organization, OTelLib]]
384384
metric_name_selectors: [".*"]
385-
385+
386386
# User + team combinations for filtering
387387
- dimensions: [[user.id, department, team.id, OTelLib]]
388388
metric_name_selectors: [".*"]
389389
- dimensions: [[user.id, cost_center, OTelLib]]
390390
metric_name_selectors: [".*"]
391-
391+
392392
# Model and session tracking
393393
- dimensions: [[model, department, team.id, OTelLib]]
394394
metric_name_selectors: ["claude_code.token.usage", "claude_code.cost.usage"]
395395
- dimensions: [[session.id, user.id, OTelLib]]
396396
metric_name_selectors: ["claude_code.active_time.*"]
397-
397+
398398
# Cost tracking dimensions
399399
- dimensions: [[cost_center, aws.account_id, OTelLib]]
400400
metric_name_selectors: ["claude_code.cost.usage"]
401401
- dimensions: [[department, cost_center, model, OTelLib]]
402402
metric_name_selectors: ["claude_code.cost.usage", "claude_code.token.usage"]
403-
403+
404404
# Location and role based
405405
- dimensions: [[location, department, OTelLib]]
406406
metric_name_selectors: [".*"]
407407
- dimensions: [[role, team.id, OTelLib]]
408408
metric_name_selectors: [".*"]
409-
409+
410410
# Environment tracking
411411
- dimensions: [[deployment.environment, organization, OTelLib]]
412412
metric_name_selectors: [".*"]
413-
413+
414414
# Minimal dimension for overall metrics
415415
- dimensions: [[OTelLib]]
416416
metric_name_selectors: [".*"]

scripts/validate-cloudformation.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# ABOUTME: Validates CloudFormation templates using AWS CLI
3+
# ABOUTME: Used by pre-commit hooks to ensure templates are valid before committing
4+
5+
set -e
6+
7+
# Color codes for output
8+
RED='\033[0;31m'
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
NC='\033[0m' # No Color
12+
13+
# Check if AWS CLI is installed
14+
if ! command -v aws &> /dev/null; then
15+
echo -e "${YELLOW}⚠️ AWS CLI not found. Skipping AWS validation.${NC}"
16+
echo " Install AWS CLI for complete CloudFormation validation."
17+
exit 0
18+
fi
19+
20+
# Check if AWS credentials are configured
21+
if ! aws sts get-caller-identity &> /dev/null; then
22+
echo -e "${YELLOW}⚠️ AWS credentials not configured. Skipping AWS validation.${NC}"
23+
echo " Configure AWS credentials for complete CloudFormation validation."
24+
exit 0
25+
fi
26+
27+
# Validate each template passed as argument
28+
for template in "$@"; do
29+
# Only validate files in deployment/infrastructure directory
30+
if [[ "$template" == *"deployment/infrastructure"* ]]; then
31+
echo -n "Validating $template with AWS CLI... "
32+
33+
# Create a temporary file for error output
34+
ERROR_FILE=$(mktemp)
35+
36+
# Use AWS CLI to validate template
37+
if aws cloudformation validate-template \
38+
--template-body file://"$template" \
39+
--region us-east-1 >/dev/null 2>"$ERROR_FILE"; then
40+
echo -e "${GREEN}${NC}"
41+
else
42+
echo -e "${RED}${NC}"
43+
echo -e "${RED}CloudFormation validation failed for $template:${NC}"
44+
cat "$ERROR_FILE"
45+
rm -f "$ERROR_FILE"
46+
exit 1
47+
fi
48+
49+
rm -f "$ERROR_FILE"
50+
fi
51+
done
52+
53+
echo -e "${GREEN}All CloudFormation templates are valid!${NC}"

0 commit comments

Comments
 (0)