Skip to content

Commit

Permalink
Remove drand_version metric (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcamou committed Mar 30, 2022
1 parent fdd6145 commit d823174
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
18 changes: 3 additions & 15 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,11 @@ var (
[]string{"url"},
)

// DrandVersion emits the current version of the drand binary
DrandVersion = prometheus.NewUntypedFunc(prometheus.UntypedOpts{
Name: "drand_version",
Help: "Version of the drand binary, in MMMNNNPPP format",
ConstLabels: map[string]string{"build": common.COMMIT},
}, func() float64 { return float64(getVersionNum(common.GetAppVersion())) })

// DrandBuildTime emits the timestamp when the binary was built in Unix time.
DrandBuildTime = prometheus.NewUntypedFunc(prometheus.UntypedOpts{
Name: "drand_build_time",
Help: "Timestamp when the binary was built in seconds since the Epoch",
ConstLabels: map[string]string{"build": common.COMMIT},
ConstLabels: map[string]string{"build": common.COMMIT, "version": common.GetAppVersion().String()},
}, func() float64 { return float64(getBuildTimestamp(common.BUILDDATE)) })

metricsBound = false
Expand All @@ -184,7 +177,6 @@ func bindMetrics() error {

// Private metrics
private := []prometheus.Collector{
DrandVersion,
DrandBuildTime,
}
for _, c := range private {
Expand Down Expand Up @@ -340,19 +332,15 @@ func (l *lazyPeerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
handler.ServeHTTP(w, r)
}

func getVersionNum(version common.Version) uint32 {
return version.Major*1_000_000 + version.Minor*1_000 + version.Patch
}

func getBuildTimestamp(buildDate string) int64 {
if buildDate == "" {
return 0.0
return 0
}

layout := "02/01/2006@15:04:05"
t, err := time.Parse(layout, buildDate)
if err != nil {
return 0.0
return 0
}
return t.Unix()
}
15 changes: 0 additions & 15 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"net/http"
"testing"
"time"

"github.com/drand/drand/common"
)

func TestMetricReshare(t *testing.T) {
Expand Down Expand Up @@ -53,19 +51,6 @@ func TestMetricReshare(t *testing.T) {
_ = resp.Body.Close()
}

func TestAppVersionFormat(t *testing.T) {
version := common.Version{
Major: 1,
Minor: 2,
Patch: 3,
}
expected := uint32(1002003)
actual := getVersionNum(version)
if actual != expected {
t.Fatalf("Error converting version to number. Expected %v, actual %v", expected, actual)
}
}

func TestBuildTimestamp(t *testing.T) {
buildTimestamp := "29/04/2021@20:23:35"

Expand Down

0 comments on commit d823174

Please sign in to comment.