Skip to content

Commit

Permalink
metrics are disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Feb 27, 2024
1 parent 66cb875 commit bc173fd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cmd/thor/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ var (
Value: 16,
Usage: "set tx limit per account in pool",
}
disableTelemetryFlag = cli.BoolFlag{
Name: "disable-telemetry",
Usage: "disable telemetry server",
enableTelemetryFlag = cli.BoolFlag{
Name: "enable-telemetry",
Usage: "enables telemetry server",
}
)
8 changes: 4 additions & 4 deletions cmd/thor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
pprofFlag,
verifyLogsFlag,
disablePrunerFlag,
disableTelemetryFlag,
enableTelemetryFlag,
},
Action: defaultAction,
Commands: []cli.Command{
Expand All @@ -113,7 +113,7 @@ func main() {
txPoolLimitFlag,
txPoolLimitPerAccountFlag,
disablePrunerFlag,
disableTelemetryFlag,
enableTelemetryFlag,
},
Action: soloAction,
},
Expand Down Expand Up @@ -143,7 +143,7 @@ func defaultAction(ctx *cli.Context) error {

initLogger(ctx)
// enable telemetry as soon as possible
enableTelemetry := !ctx.Bool(disableTelemetryFlag.Name) // positive booleans are easier to read
enableTelemetry := ctx.Bool(enableTelemetryFlag.Name)
if enableTelemetry {
telemetry.InitializePrometheusTelemetry()
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func soloAction(ctx *cli.Context) error {
initLogger(ctx)

// enable telemetry as soon as possible
enableTelemetry := !ctx.Bool(disableTelemetryFlag.Name) // positive booleans are easier to read
enableTelemetry := ctx.Bool(enableTelemetryFlag.Name)
if enableTelemetry {
telemetry.InitializePrometheusTelemetry()
}
Expand Down
43 changes: 43 additions & 0 deletions telemetry/noop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package telemetry

import (
"github.com/stretchr/testify/require"

Check failure on line 4 in telemetry/noop_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `goimports`-ed (goimports)
"math/rand"
"net/http"
"net/http/httptest"
"testing"
)

func TestNoopTelemetry(t *testing.T) {
server := httptest.NewServer(Handler())

t.Cleanup(func() {
server.Close()
})

// 2 ways of accessing it - useful to avoid lookups
count1 := Counter("count1")
Counter("count2")

count1.Add(1)
randCount2 := rand.Intn(100) + 1
for i := 0; i < randCount2; i++ {
Counter("count2").Add(1)
}

hist := Histogram("hist1")
histTotal := 0
for i := 0; i < rand.Intn(100)+1; i++ {
hist.Observe(int64(i))
histTotal += i
}

// Make a request to the metrics endpoint
resp, err := http.Get(server.URL + "/metrics")
if err != nil {
t.Errorf("Failed to make GET request: %v", err)
}

defer resp.Body.Close()
require.Equal(t, resp.StatusCode, 404)
}

0 comments on commit bc173fd

Please sign in to comment.