package types import ( "fmt" "github.com/cespare/xxhash/v2" ) // MetricID is the internal immutable 64-bit identifier mapped from string tags. type MetricID int64 // HashMetricID computes a deterministic 63-bit positive MetricID from host, service, and optional tags // using xxHash64. Guarantees identical IDs across independent instances, offline converters, and restarts. func HashMetricID(host, service, tags string) MetricID { key := host + "\x00" + service if tags != "" { key += "\x00" + tags } return MetricID(xxhash.Sum64String(key) & 0x7FFFFFFFFFFFFFFF) } // BucketID represents a fixed coarse time epoch (e.g., unix_seconds / bucket_duration_seconds). type BucketID uint32 // DataPoint is the fundamental unboxed numeric telemetry point. // Fits in exactly 24 contiguous bytes (3 x 8 bytes). type DataPoint struct { MetricID MetricID // 8 bytes Timestamp int64 // 8 bytes (Unix timestamp in milliseconds) Value float64 // 8 bytes (Float64 value) } func (dp DataPoint) String() string { return fmt.Sprintf("DataPoint(metric=%d, ts=%d, val=%f)", dp.MetricID, dp.Timestamp, dp.Value) } // SeriesMetadata represents the human-readable metadata associated with a MetricID. type SeriesMetadata struct { MetricID MetricID Host string Service string Tags string // Canonical sorted key-value pairs or JSON string } // BucketState represents the lifecycle status of a time bucket. type BucketState string const ( BucketStateActive BucketState = "ACTIVE" BucketStateSealed BucketState = "SEALED" BucketStateCommitted BucketState = "COMMITTED" BucketStateCompacted BucketState = "COMPACTED" ) // BucketManifest records the immutable cold Parquet metadata. type BucketManifest struct { BucketID BucketID StorageKey string MinTS int64 MaxTS int64 RecordCount int64 SizeBytes int64 State BucketState } // SeriesFilter represents query constraints to resolve matching MetricIDs. type SeriesFilter struct { HostRegex string ServiceRegex string TagsExact map[string]string } // BucketIterator traverses all points within a single sealed time bucket. type BucketIterator interface { Next() bool MetricID() MetricID Timestamp() int64 Value() float64 Error() error Close() error }