Backport of fix: emit consul version metric on a regular interval into release/1.16.x (#18728)
* backport of commit a4f77878e74d5f4f5c737554ee0b7ebf15ae6872 * backport of commit 29da4339bff6a7d2269551f9e7d63d65b2575eea --------- Co-authored-by: Semir Patel <semir.patel@hashicorp.com>
This commit is contained in:
parent
612e7e2ff3
commit
1eb12f79c0
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
telemetry: emit consul version metric on a regular interval.
|
||||||
|
```
|
|
@ -856,12 +856,6 @@ func (a *Agent) Start(ctx context.Context) error {
|
||||||
go m.Monitor(&lib.StopChannelContext{StopCh: a.shutdownCh})
|
go m.Monitor(&lib.StopChannelContext{StopCh: a.shutdownCh})
|
||||||
}
|
}
|
||||||
|
|
||||||
// consul version metric with labels
|
|
||||||
metrics.SetGaugeWithLabels([]string{"version"}, 1, []metrics.Label{
|
|
||||||
{Name: "version", Value: a.config.VersionWithMetadata()},
|
|
||||||
{Name: "pre_release", Value: a.config.VersionPrerelease},
|
|
||||||
})
|
|
||||||
|
|
||||||
// start a go routine to reload config based on file watcher events
|
// start a go routine to reload config based on file watcher events
|
||||||
if a.configFileWatcher != nil {
|
if a.configFileWatcher != nil {
|
||||||
a.baseDeps.Logger.Debug("starting file watcher")
|
a.baseDeps.Logger.Debug("starting file watcher")
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/consul/state"
|
"github.com/hashicorp/consul/agent/consul/state"
|
||||||
"github.com/hashicorp/consul/logging"
|
"github.com/hashicorp/consul/logging"
|
||||||
|
"github.com/hashicorp/consul/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Gauges = []prometheus.GaugeDefinition{
|
var Gauges = []prometheus.GaugeDefinition{
|
||||||
|
@ -95,6 +96,10 @@ var Gauges = []prometheus.GaugeDefinition{
|
||||||
Name: []string{"state", "billable_service_instances"},
|
Name: []string{"state", "billable_service_instances"},
|
||||||
Help: "Total number of billable service instances in the local datacenter.",
|
Help: "Total number of billable service instances in the local datacenter.",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: []string{"version"},
|
||||||
|
Help: "Represents the Consul version.",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type getMembersFunc func() []serf.Member
|
type getMembersFunc func() []serf.Member
|
||||||
|
@ -244,6 +249,7 @@ func (u *UsageMetricsReporter) runOnce() {
|
||||||
}
|
}
|
||||||
|
|
||||||
u.emitConfigEntryUsage(configUsage)
|
u.emitConfigEntryUsage(configUsage)
|
||||||
|
u.emitVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UsageMetricsReporter) memberUsage() []serf.Member {
|
func (u *UsageMetricsReporter) memberUsage() []serf.Member {
|
||||||
|
@ -266,3 +272,26 @@ func (u *UsageMetricsReporter) memberUsage() []serf.Member {
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *UsageMetricsReporter) emitVersion() {
|
||||||
|
// consul version metric with labels
|
||||||
|
metrics.SetGaugeWithLabels(
|
||||||
|
[]string{"version"},
|
||||||
|
1,
|
||||||
|
[]metrics.Label{
|
||||||
|
{Name: "version", Value: versionWithMetadata()},
|
||||||
|
{Name: "pre_release", Value: version.VersionPrerelease},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func versionWithMetadata() string {
|
||||||
|
vsn := version.Version
|
||||||
|
metadata := version.VersionMetadata
|
||||||
|
|
||||||
|
if metadata != "" {
|
||||||
|
vsn += "+" + metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
return vsn
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package usagemetrics
|
package usagemetrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ import (
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
"github.com/hashicorp/consul/proto/private/pbpeering"
|
"github.com/hashicorp/consul/proto/private/pbpeering"
|
||||||
"github.com/hashicorp/consul/sdk/testutil"
|
"github.com/hashicorp/consul/sdk/testutil"
|
||||||
|
"github.com/hashicorp/consul/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newStateStore() (*state.Store, error) {
|
func newStateStore() (*state.Store, error) {
|
||||||
|
@ -504,6 +506,15 @@ var baseCases = map[string]testCase{
|
||||||
{Name: "kind", Value: "control-plane-request-limit"},
|
{Name: "kind", Value: "control-plane-request-limit"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// --- version ---
|
||||||
|
fmt.Sprintf("consul.usage.test.version;version=%s;pre_release=%s", versionWithMetadata(), version.VersionPrerelease): {
|
||||||
|
Name: "consul.usage.test.version",
|
||||||
|
Value: 1,
|
||||||
|
Labels: []metrics.Label{
|
||||||
|
{Name: "version", Value: versionWithMetadata()},
|
||||||
|
{Name: "pre_release", Value: version.VersionPrerelease},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
getMembersFunc: func() []serf.Member { return []serf.Member{} },
|
getMembersFunc: func() []serf.Member { return []serf.Member{} },
|
||||||
},
|
},
|
||||||
|
@ -995,6 +1006,15 @@ var baseCases = map[string]testCase{
|
||||||
{Name: "kind", Value: "control-plane-request-limit"},
|
{Name: "kind", Value: "control-plane-request-limit"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// --- version ---
|
||||||
|
fmt.Sprintf("consul.usage.test.version;version=%s;pre_release=%s", versionWithMetadata(), version.VersionPrerelease): {
|
||||||
|
Name: "consul.usage.test.version",
|
||||||
|
Value: 1,
|
||||||
|
Labels: []metrics.Label{
|
||||||
|
{Name: "version", Value: versionWithMetadata()},
|
||||||
|
{Name: "pre_release", Value: version.VersionPrerelease},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func assertEqualGaugeMaps(t *testing.T, expectedMap, foundMap map[string]metrics
|
||||||
|
|
||||||
for key := range foundMap {
|
for key := range foundMap {
|
||||||
if _, ok := expectedMap[key]; !ok {
|
if _, ok := expectedMap[key]; !ok {
|
||||||
t.Errorf("found unexpected gauge key: %s", key)
|
t.Errorf("found unexpected gauge key: %s with value: %v", key, foundMap[key])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue