storj/cmd/statreceiver/version.go
Jeff Wendling bd78945116 statreceiver: add v2/v3 splitter and downgrade
this allows for us to roll out monkit v3 while keeping the
old v2 code and dependencies working.

Change-Id: I0758ee2bb66685b0819502368fc2c20cb35b958a
2020-02-02 22:56:14 +00:00

34 lines
835 B
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"bytes"
"time"
)
// VersionSplit downgrades known v3 metrics into v2 versions for backwards compat.
type VersionSplit struct {
v2dest MetricDest
v3dest MetricDest
}
// NewVersionSplit constructs a VersionSplit that passes known v3 metrics as
// v2 metrics to the provided dest.
func NewVersionSplit(v2dest, v3dest MetricDest) *VersionSplit {
return &VersionSplit{
v2dest: v2dest,
v3dest: v3dest,
}
}
// Metric implements MetricDest
func (k *VersionSplit) Metric(application, instance string, key []byte, val float64, ts time.Time) error {
comma := bytes.IndexByte(key, ',')
if comma < 0 {
return k.v2dest.Metric(application, instance, key, val, ts)
}
return k.v3dest.Metric(application, instance, key, val, ts)
}