Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dockerize-sig-aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
feuGeneA committed Aug 22, 2024
2 parents b9b671f + 3272c9d commit 0f14f23
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions signature-aggregator/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func (s *SignatureAggregator) CreateSignedMessage(
s.metrics.FailuresToGetValidatorSet.Inc()
return nil, fmt.Errorf("%s: %w", msg, err)
}
s.metrics.ConnectedStakeWeightPercentage.WithLabelValues(
signingSubnet.String(),
).Set(
float64(connectedValidators.ConnectedWeight) /
float64(connectedValidators.TotalValidatorWeight) * 100,
)

if !utils.CheckStakeWeightPercentageExceedsThreshold(
big.NewInt(0).SetUint64(connectedValidators.ConnectedWeight),
Expand Down
11 changes: 11 additions & 0 deletions signature-aggregator/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var Opts = struct {
InvalidSignatureResponses prometheus.CounterOpts
SignatureCacheHits prometheus.CounterOpts
SignatureCacheMisses prometheus.CounterOpts
ConnectedStakeWeightPercentage prometheus.GaugeOpts
}{
AggregateSignaturesLatencyMS: prometheus.GaugeOpts{
Name: "agg_sigs_latency_ms",
Expand Down Expand Up @@ -72,6 +73,10 @@ var Opts = struct {
Name: "signature_cache_misses",
Help: "Number of signatures that were not found in the cache",
},
ConnectedStakeWeightPercentage: prometheus.GaugeOpts{
Name: "connected_stake_weight_percentage",
Help: "The percentage of connected stake weight for a specific subnet",
},
}

type SignatureAggregatorMetrics struct {
Expand All @@ -85,6 +90,7 @@ type SignatureAggregatorMetrics struct {
InvalidSignatureResponses prometheus.Counter
SignatureCacheHits prometheus.Counter
SignatureCacheMisses prometheus.Counter
ConnectedStakeWeightPercentage *prometheus.GaugeVec

// TODO: consider other failures to monitor. Issue #384 requires
// "network failures", but we probably don't handle those directly.
Expand Down Expand Up @@ -129,6 +135,10 @@ func NewSignatureAggregatorMetrics(
SignatureCacheMisses: prometheus.NewCounter(
Opts.SignatureCacheMisses,
),
ConnectedStakeWeightPercentage: prometheus.NewGaugeVec(
Opts.ConnectedStakeWeightPercentage,
[]string{"subnetID"},
),
}

registerer.MustRegister(m.AggregateSignaturesLatencyMS)
Expand All @@ -141,6 +151,7 @@ func NewSignatureAggregatorMetrics(
registerer.MustRegister(m.InvalidSignatureResponses)
registerer.MustRegister(m.SignatureCacheHits)
registerer.MustRegister(m.SignatureCacheMisses)
registerer.MustRegister(m.ConnectedStakeWeightPercentage)

return &m
}
Expand Down
14 changes: 13 additions & 1 deletion tests/signature_aggregator_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ func SignatureAggregatorAPI(network interfaces.LocalNetwork) {
{metrics.Opts.InvalidSignatureResponses.Name, "==", 0},
{metrics.Opts.SignatureCacheHits.Name, "==", 0},
{metrics.Opts.SignatureCacheMisses.Name, "==", 0},
{
fmt.Sprintf(
"%s{subnetID=\"%s\"}",
metrics.Opts.ConnectedStakeWeightPercentage.Name,
subnetAInfo.SubnetID.String(),
),
"==",
100,
},
} {
Expect(metricsSample[m.name]).Should(
BeNumerically(m.op, m.value),
Expand Down Expand Up @@ -191,6 +200,7 @@ func sampleMetrics(port uint16) map[string]uint64 {
metrics.Opts.InvalidSignatureResponses.Name,
metrics.Opts.SignatureCacheHits.Name,
metrics.Opts.SignatureCacheMisses.Name,
metrics.Opts.ConnectedStakeWeightPercentage.Name,
} {
if strings.HasPrefix(
line,
Expand All @@ -199,7 +209,9 @@ func sampleMetrics(port uint16) map[string]uint64 {
log.Debug("Found metric line", "line", line)
parts := strings.Fields(line)

// Fetch the metric count from the last field of the line
metricName = strings.Replace(parts[0], "U__signature_2d_aggregator_", "", 1)

// Parse the metric count from the last field of the line
value, err := strconv.ParseUint(parts[len(parts)-1], 10, 64)
if err != nil {
log.Warn("failed to parse value from metric line")
Expand Down

0 comments on commit 0f14f23

Please sign in to comment.