Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group agent version by binary name #1369

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/boostx/stats_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/filecoin-project/boost/retrievalmarket/lp2pimpl"
transports_types "github.com/filecoin-project/boost/retrievalmarket/types"
"regexp"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -152,6 +153,7 @@ var statsCmd = &cli.Command{
if !ok {
return fmt.Errorf("AgentVersion for peer %s is not a string: type %T", addrInfo.ID, agentVersionI)
}
agentVersionShort := shortAgentVersion(agentVersion)

// Get SP's supported transports
var transports *transports_types.QueryResponse
Expand All @@ -172,15 +174,15 @@ var statsCmd = &cli.Command{
boostNodes++
boostQualityAdjPower = big.Add(boostQualityAdjPower, minerToMinerPower[maddr].QualityAdjPower)
boostRawBytePower = big.Add(boostRawBytePower, minerToMinerPower[maddr].RawBytePower)
agentVersions[agentVersion]++
agentVersions[agentVersionShort]++
if transports != nil {
for _, p := range transports.Protocols {
transportProtos[p.Name]++
}
}
} else if contains(protostrs, "/fil/storage/mk/1.1.0") {
out += " is running markets"
agentVersions[agentVersion]++
agentVersions[agentVersionShort]++
marketsNodes++
} else {
out += " is not running markets or boost"
Expand Down Expand Up @@ -258,3 +260,9 @@ func contains(sl []string, substr string) bool {

return false
}

var agentVersionRegExp = regexp.MustCompile(`^(.+)\+.+$`)

func shortAgentVersion(av string) string {
return agentVersionRegExp.ReplaceAllString(av, "$1")
}
19 changes: 19 additions & 0 deletions cmd/boostx/stats_cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

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

func TestAgentVersion(t *testing.T) {
testCases := map[string]string{
"lotus-1.20.0+gzbt+git.cddeab21d.dirty": "lotus-1.20.0+gzbt",
"boost-1.6.1+git.4931e18": "boost-1.6.1",
"boost-1.6.2-rc1+git.0b5cf47.dirty": "boost-1.6.2-rc1",
"lotus-1.20.0": "lotus-1.20.0",
}
for agentVersion, exp := range testCases {
agentVersionShort := shortAgentVersion(agentVersion)
require.Equal(t, exp, agentVersionShort)
}
}