Skip to content

Commit

Permalink
changing sample to a guage
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Aug 29, 2022
1 parent 12b962d commit 832dddd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions net.go
Expand Up @@ -1043,7 +1043,7 @@ func (m *Memberlist) sendLocalState(conn net.Conn, join bool, streamLabel string
}

moreBytes := binary.BigEndian.Uint32(bufConn.Bytes()[1:5])
metrics.AddSampleWithLabels([]string{"memberlist", "size", "local"}, float32(moreBytes), m.metricLabels)
metrics.SetGaugeWithLabels([]string{"memberlist", "size", "local"}, float32(moreBytes), m.metricLabels)

// Get the send buffer
return m.rawSendMsgStream(conn, bufConn.Bytes(), streamLabel)
Expand Down Expand Up @@ -1091,7 +1091,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.AddSampleWithLabels([]string{"memberlist", "size", "remote"}, float32(moreBytes), m.metricLabels)
metrics.SetGaugeWithLabels([]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
6 changes: 3 additions & 3 deletions net_test.go
Expand Up @@ -719,10 +719,10 @@ func TestEncryptDecryptState(t *testing.T) {

intv := getIntervalMetrics(t, sink)

sampleName := "consul.usage.test.memberlist.size.remote"
actualSample := intv.Samples[sampleName]
gaugeName := "consul.usage.test.memberlist.size.remote"
actualGauge := intv.Gauges[gaugeName]

if actualSample.Count == 0 {
if actualGauge.Value == 0 {
t.Fatalf("memberlist.size.remote sample not taken")
}
}
Expand Down
8 changes: 4 additions & 4 deletions state_test.go
Expand Up @@ -2319,11 +2319,11 @@ func TestMemberlist_PushPull(t *testing.T) {

intv := getIntervalMetrics(t, sink)

sampleName := "consul.usage.test.memberlist.size.local"
actualSample := intv.Samples[sampleName]
gaugeName := "consul.usage.test.memberlist.size.local"
actualGauge := intv.Gauges[gaugeName]

if actualSample.Count == 0 {
t.Fatalf("memberlist.size.local sample not taken")
if actualGauge.Value == 0 {
t.Fatalf("memberlist.size.local gauge not emitted")
}
})
}
Expand Down

0 comments on commit 832dddd

Please sign in to comment.