This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
go build -v -o archiver ./cmd/archiver/- Build the archiver binaryGOOS=linux go build -v -o archiver_linux ./cmd/archiver/- Build for Linux (see Makefile)go test ./...- Run all testsgo test ./storage/fileavro/- Run specific package testsgofumpt -w .- Format code (required before commits)
./archiver archive- Run the archiver (default table: log_scores)./archiver archive -t custom_table- Archive from a specific table
For local development, the easiest storage backends are:
- File Avro: Set
avro_path=/tmp/avro-datato store Avro files locally - Local ClickHouse: Set
ch_dsnto your local ClickHouse instance
The archiver uses the Kong library for centralized configuration management. All configuration is loaded from environment variables with comprehensive validation.
MySQL Database Connection:
db_host- MySQL host (e.g.,10.43.173.158)db_database- Database name (e.g.,askntp)db_user- Database usernamedb_pass- Database password
Database Connection Pool (optional, with defaults):
db_max_idle_conns=10- Maximum idle connectionsdb_max_open_conns=10- Maximum open connectionsdb_max_idle_time=2m- Maximum idle connection timedb_max_lifetime=5m- Maximum connection lifetimedb_timeout=10s- Connection timeout
Application Settings (optional, with defaults):
retention_days=15- Data retention period in daysapp_valid_tables=log_scores,log_scores_archive,log_scores_test- Valid table names
At least one storage backend must be configured:
ClickHouse:
ch_dsn- ClickHouse connection string (e.g.,tcp://10.43.92.221:9000/askntp?debug=false&compress=lz4)
BigQuery:
bq_dataset- BigQuery dataset nameGOOGLE_APPLICATION_CREDENTIALS- Path to service account key file (e.g.,keys/ntpdev-ask.json)
Google Cloud Storage (GCS):
gc_bucket- GCS bucket name for storing Avro filesGOOGLE_APPLICATION_CREDENTIALS- Path to service account key file
Local Avro Files:
avro_path- Local directory path for Avro files (e.g.,/tmp/avro-data)
retention_days- Number of days to retain data (default: 15)
- Environment files:
ntppool.*.env(various environments: beta, prod, local) - Configuration: Uses Viper for config management, supports
--configflag - Service keys: Stored in
keys/directory for different environments
- Main Application:
cmd/archiver/- CLI tool using Cobra framework - Storage Interface:
storage/storage.go- DefinesArchiverinterface withStore(),BatchSizeMinMaxTime(),Close()methods - Storage Backends: Multiple implementations in
storage/subdirectories - Data Models:
logscorepackage for log score data structures
The archiver supports multiple storage backends through a pluggable architecture:
- BigQuery:
storage/bigquery/- Google BigQuery integration - ClickHouse:
storage/clickhouse/- ClickHouse database - File Avro:
storage/fileavro/- Local Avro files - GCS Avro:
storage/gcsavro/- Avro files in Google Cloud Storage - Cleanup:
storage/cleanup/- Data cleanup operations
Backend selection is handled by SetupArchiver() function in archiver.go.
github.com/alecthomas/kong- CLI framework and configuration managementcloud.google.com/go/bigquery- BigQuery clientgithub.com/ClickHouse/clickhouse-go/v2- ClickHouse drivergithub.com/linkedin/goavro/v2- Avro serializationgo.ntppool.org/common- NTP Pool common utilities
- Uses
go.ntppool.org/archiver/dbfor database connections - MySQL integration via
github.com/go-sql-driver/mysqlandgithub.com/jmoiron/sqlx - Implements distributed locking using MySQL's
GET_LOCK()function - MySQL schema available at: https://raw.githubusercontent.com/ntppool/monitor/refs/heads/main/schema.sql
- ClickHouse schema documentation: TODO - needs to be extracted and documented
- Kong-based Configuration: Centralized configuration management with validation
- Environment Variables: All configuration loaded from environment variables
- Built-in Validation: Fail-fast startup with clear error messages for missing/invalid config
- Storage Backend Detection: Automatically detects and validates available storage backends
- Multi-environment setup: Different
.envfiles for various environments - Service account keys: Stored in
keys/directory
- Linux builds via
make linux - Kubernetes deployment
- Docker image:
askbjoernhansen/ntppool-archiver:1.0 - Drone CI integration with
drone signcommand