summaryrefslogtreecommitdiff
path: root/internal/metrics/sample.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/metrics/sample.go')
-rw-r--r--internal/metrics/sample.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/metrics/sample.go b/internal/metrics/sample.go
new file mode 100644
index 0000000..04360f5
--- /dev/null
+++ b/internal/metrics/sample.go
@@ -0,0 +1,34 @@
+package metrics
+
+import "time"
+
+// Sample represents a single metric sample with timestamp
+type Sample struct {
+ MetricName string
+ Labels map[string]string
+ Value float64
+ Timestamp time.Time
+}
+
+// NewSample creates a new Sample
+func NewSample(name string, labels map[string]string, value float64, timestamp time.Time) Sample {
+ if labels == nil {
+ labels = make(map[string]string)
+ }
+ return Sample{
+ MetricName: name,
+ Labels: labels,
+ Value: value,
+ Timestamp: timestamp,
+ }
+}
+
+// Age returns how old the sample is
+func (s Sample) Age() time.Duration {
+ return time.Since(s.Timestamp)
+}
+
+// IsRecent returns true if the sample is recent enough for realtime ingestion
+func (s Sample) IsRecent(threshold time.Duration) bool {
+ return s.Age() < threshold
+}