Skip to content

Commit

Permalink
Merge branch 'main' into dependency-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iansuvak authored Aug 27, 2024
2 parents bcad0ec + df148f8 commit 4b6349e
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 10 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ require (
github.com/ava-labs/teleporter v1.0.5
github.com/aws/aws-sdk-go-v2 v1.30.4
github.com/aws/aws-sdk-go-v2/config v1.27.9
github.com/aws/aws-sdk-go-v2/service/kms v1.35.4
github.com/aws/aws-sdk-go-v2/service/kms v1.35.5
github.com/ethereum/go-ethereum v1.13.8
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/onsi/ginkgo/v2 v2.20.1
github.com/onsi/gomega v1.34.1
github.com/pingcap/errors v0.11.4
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.1
github.com/prometheus/client_golang v1.20.2
github.com/redis/go-redis/v9 v9.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 h1:EyBZibR
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1/go.mod h1:JKpmtYhhPs7D97NL/ltqz7yCkERFW5dOlHyVl66ZYF8=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6 h1:b+E7zIUHMmcB4Dckjpkapoy47W6C9QBv/zoUP+Hn8Kc=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6/go.mod h1:S2fNV0rxrP78NhPbCZeQgY8H9jdDMeGtwcfZIRxzBqU=
github.com/aws/aws-sdk-go-v2/service/kms v1.35.4 h1:mG1MH6yPwT5gNEeBrhig3FHc4mK0QaZOXsmQUbphP6Y=
github.com/aws/aws-sdk-go-v2/service/kms v1.35.4/go.mod h1:A5CS0VRmxxj2YKYLCY08l/Zzbd01m6JZn0WzxgT1OCA=
github.com/aws/aws-sdk-go-v2/service/kms v1.35.5 h1:XUomV7SiclZl1QuXORdGcfFqHxEHET7rmNGtxTfNB+M=
github.com/aws/aws-sdk-go-v2/service/kms v1.35.5/go.mod h1:A5CS0VRmxxj2YKYLCY08l/Zzbd01m6JZn0WzxgT1OCA=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 h1:mnbuWHOcM70/OFUlZZ5rcdfA8PflGXXiefU/O+1S3+8=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3/go.mod h1:5HFu51Elk+4oRBZVxmHrSds5jFXmFj8C3w7DVF2gnrs=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 h1:uLq0BKatTmDzWa/Nu4WO0M1AaQDaPpwTKAeByEc6WFM=
Expand Down Expand Up @@ -518,8 +518,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.1 h1:IMJXHOD6eARkQpxo8KkhgEVFlBNm+nkrFUyGlIu7Na8=
github.com/prometheus/client_golang v1.20.1/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg=
github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
Expand Down
2 changes: 1 addition & 1 deletion peers/app_request_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewNetwork(
}

// Create the handler for handling inbound app responses
handler, err := NewRelayerExternalHandler(logger, prometheus.DefaultRegisterer)
handler, err := NewRelayerExternalHandler(logger, metrics)
if err != nil {
logger.Error(
"Failed to create p2p network handler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var (
type AppRequestNetworkMetrics struct {
infoAPICallLatencyMS prometheus.Histogram
pChainAPICallLatencyMS prometheus.Histogram
connects prometheus.Counter
disconnects prometheus.Counter
}

func newAppRequestNetworkMetrics(registerer prometheus.Registerer) (*AppRequestNetworkMetrics, error) {
Expand Down Expand Up @@ -40,8 +42,32 @@ func newAppRequestNetworkMetrics(registerer prometheus.Registerer) (*AppRequestN
}
registerer.MustRegister(pChainAPICallLatencyMS)

connects := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "connects",
Help: "Number of connected events",
},
)
if connects == nil {
return nil, ErrFailedToCreateAppRequestNetworkMetrics
}
registerer.MustRegister(connects)

disconnects := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "disconnects",
Help: "Number of disconnected events",
},
)
if disconnects == nil {
return nil, ErrFailedToCreateAppRequestNetworkMetrics
}
registerer.MustRegister(disconnects)

return &AppRequestNetworkMetrics{
infoAPICallLatencyMS: infoAPICallLatencyMS,
pChainAPICallLatencyMS: pChainAPICallLatencyMS,
connects: connects,
disconnects: disconnects,
}, nil
}
8 changes: 6 additions & 2 deletions peers/external_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type RelayerExternalHandler struct {
responseChans map[uint32]chan message.InboundMessage
responsesCount map[uint32]expectedResponses
timeoutManager timer.AdaptiveTimeoutManager
metrics *AppRequestNetworkMetrics
}

// expectedResponses counts the number of responses and compares against the expected number of responses
Expand All @@ -41,7 +42,7 @@ type expectedResponses struct {
// Teleporter application relayer, as well as handle timeouts.
func NewRelayerExternalHandler(
logger logging.Logger,
registerer prometheus.Registerer,
metrics *AppRequestNetworkMetrics,
) (*RelayerExternalHandler, error) {
// TODO: Leaving this static for now, but we may want to have this as a config option
cfg := timer.AdaptiveTimeoutConfig{
Expand All @@ -52,7 +53,7 @@ func NewRelayerExternalHandler(
TimeoutHalflife: constants.DefaultNetworkTimeoutHalflife,
}

timeoutManager, err := timer.NewAdaptiveTimeoutManager(&cfg, registerer)
timeoutManager, err := timer.NewAdaptiveTimeoutManager(&cfg, prometheus.DefaultRegisterer)
if err != nil {
logger.Error(
"Failed to create timeout manager",
Expand All @@ -69,6 +70,7 @@ func NewRelayerExternalHandler(
responseChans: make(map[uint32]chan message.InboundMessage),
responsesCount: make(map[uint32]expectedResponses),
timeoutManager: timeoutManager,
metrics: metrics,
}, nil
}

Expand Down Expand Up @@ -102,13 +104,15 @@ func (h *RelayerExternalHandler) Connected(nodeID ids.NodeID, version *version.A
zap.Stringer("version", version),
zap.Stringer("subnetID", subnetID),
)
h.metrics.connects.Inc()
}

func (h *RelayerExternalHandler) Disconnected(nodeID ids.NodeID) {
h.log.Debug(
"Disconnected",
zap.Stringer("nodeID", nodeID),
)
h.metrics.disconnects.Inc()
}

// RegisterRequestID registers an AppRequest by requestID, and marks the number of
Expand Down
3 changes: 3 additions & 0 deletions relayer/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func main() {
// TODO: remove this from here once trackedSubnets are no longer referenced
// by ping messages in avalanchego
for _, sourceBlockchain := range cfg.SourceBlockchains {
if sourceBlockchain.GetSubnetID() == constants.PrimaryNetworkID {
continue
}
trackedSubnets.Add(sourceBlockchain.GetSubnetID())
}

Expand Down
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 4b6349e

Please sign in to comment.