Skip to content

Commit

Permalink
change remotemetric tobe a sample so that it can be displayed in a hi…
Browse files Browse the repository at this point in the history
…stogram
  • Loading branch information
jmurret committed Sep 13, 2022
1 parent 96c458a commit e1b2314
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion net.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ func (m *Memberlist) decryptRemoteState(bufConn io.Reader, streamLabel string) (
// Ensure we aren't asked to download too much. This is to guard against
// an attack vector where a huge amount of state is sent
moreBytes := binary.BigEndian.Uint32(cipherText.Bytes()[1:5])
metrics.SetGaugeWithLabels([]string{"memberlist", "size", "remote"}, float32(moreBytes), m.metricLabels)
metrics.AddSampleWithLabels([]string{"memberlist", "size", "remote"}, float32(moreBytes), m.metricLabels)

if moreBytes > maxPushStateBytes {
return nil, fmt.Errorf("Remote node state is larger than limit (%d)", moreBytes)
Expand Down
2 changes: 2 additions & 0 deletions net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ func TestEncryptDecryptState(t *testing.T) {
SecretKey: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
ProtocolVersion: ProtocolVersionMax,
}
sink := registerInMemorySink(t)

m, err := Create(config)
if err != nil {
Expand All @@ -710,6 +711,7 @@ func TestEncryptDecryptState(t *testing.T) {
if err != nil {
t.Fatalf("err: %v", err)
}
verifySampleExists(t, "consul.usage.test.memberlist.size.remote", sink)

if !reflect.DeepEqual(state, plain) {
t.Fatalf("Decrypt failed: %v", plain)
Expand Down
2 changes: 2 additions & 0 deletions state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,7 @@ func getIntervalMetrics(t *testing.T, sink *metrics.InmemSink) *metrics.Interval
}

func verifyGaugeExists(t *testing.T, name string, sink *metrics.InmemSink) {
t.Helper()
interval := getIntervalMetrics(t, sink)
interval.RLock()
defer interval.RUnlock()
Expand All @@ -2432,6 +2433,7 @@ func verifyGaugeExists(t *testing.T, name string, sink *metrics.InmemSink) {
}

func verifySampleExists(t *testing.T, name string, sink *metrics.InmemSink) {
t.Helper()
interval := getIntervalMetrics(t, sink)
interval.RLock()
defer interval.RUnlock()
Expand Down

0 comments on commit e1b2314

Please sign in to comment.