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

Replace all chain namespaces with labels #3053

Merged
merged 72 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a832333
Start metrics revamp
StephenButtolph May 28, 2024
d609481
nit
StephenButtolph May 28, 2024
eeceb4a
nit
StephenButtolph May 28, 2024
eb1bac2
nit
StephenButtolph May 28, 2024
76f8864
update readme
StephenButtolph May 28, 2024
73bb510
update readme
StephenButtolph May 28, 2024
5e8c0f7
update readme
StephenButtolph May 28, 2024
a90f1cf
update readme
StephenButtolph May 28, 2024
6d5c742
update readme
StephenButtolph May 28, 2024
f781967
update networking metrics
StephenButtolph May 28, 2024
00630c6
update more metrics
StephenButtolph May 28, 2024
5fb44f5
update more metrics
StephenButtolph May 28, 2024
e9a4b60
wip updating metrics
StephenButtolph May 28, 2024
38c7bd6
seems to be working
StephenButtolph May 28, 2024
a634e7f
nit
StephenButtolph May 28, 2024
582f45b
finish rpcchainvm
StephenButtolph May 28, 2024
ca30268
rename meterdb
StephenButtolph May 28, 2024
ca64267
rename
StephenButtolph May 28, 2024
9098df0
wip
StephenButtolph May 28, 2024
fe4ffc8
wip
StephenButtolph May 28, 2024
90649ce
maybe done
StephenButtolph May 29, 2024
cd44e3c
use interfaces
StephenButtolph May 29, 2024
8abf9de
nits
StephenButtolph May 29, 2024
744eb79
comments
StephenButtolph May 29, 2024
50e9172
nir
StephenButtolph May 29, 2024
bb2eab1
make const
StephenButtolph May 29, 2024
6e41c15
nit
StephenButtolph May 29, 2024
09651fa
Merge branch 'master' into revamp-metrics
StephenButtolph May 29, 2024
131bcc3
nits
StephenButtolph May 29, 2024
43b00f7
nit
StephenButtolph May 29, 2024
3fce9d9
Add constants.VMName function
StephenButtolph May 30, 2024
3532c18
nit
StephenButtolph May 30, 2024
1fb2c5f
merged
StephenButtolph May 30, 2024
393342c
Remove unused metrics namespaces
StephenButtolph May 30, 2024
33cfc07
merged
StephenButtolph May 30, 2024
86a50c3
nit
StephenButtolph May 30, 2024
017f90c
Merge branch 'remove-unused-namespaces' into revamp-metrics
StephenButtolph May 30, 2024
d6425d7
remove moar
StephenButtolph May 30, 2024
d1214fc
Remove api namespace
StephenButtolph May 30, 2024
073ac5c
Remove network namespace
StephenButtolph May 31, 2024
3f67a1d
Merge branch 'remove-unused-namespaces' into all-metrics-revamped
StephenButtolph May 31, 2024
0fa1691
merged
StephenButtolph May 31, 2024
d19acc6
Remove db namespace
StephenButtolph May 31, 2024
0c5488a
merged
StephenButtolph May 31, 2024
6f114a9
merged
StephenButtolph May 31, 2024
98aa009
merged
StephenButtolph May 31, 2024
06e7c7e
Remove _chain_ separator in metrics
StephenButtolph May 31, 2024
4ddc2c5
Implement label gatherer
StephenButtolph May 31, 2024
b5d9855
cleanup
StephenButtolph Jun 3, 2024
66a95ef
add comment
StephenButtolph Jun 3, 2024
d518ac5
nit
StephenButtolph Jun 3, 2024
4da46d0
Merge branch 'master' into implement-label-gatherer
StephenButtolph Jun 3, 2024
1b35bc3
merged
StephenButtolph Jun 3, 2024
6145c7c
merged
StephenButtolph Jun 3, 2024
648274e
Merge branch 'implement-label-gatherer' into revamp-metrics
StephenButtolph Jun 3, 2024
487f6fb
merged
StephenButtolph Jun 3, 2024
4728e52
fix vm namespace
StephenButtolph Jun 4, 2024
d8db8d2
merged
StephenButtolph Jun 4, 2024
d564c9a
remove readme
StephenButtolph Jun 5, 2024
1411f1b
use constants
StephenButtolph Jun 5, 2024
ee318aa
remove avalanche registerer from context
StephenButtolph Jun 5, 2024
22f652c
Remove avalanche metrics registerer from consensus context
StephenButtolph Jun 6, 2024
890a57c
merged
StephenButtolph Jun 6, 2024
7dffd6c
nit
StephenButtolph Jun 6, 2024
409b8a3
nit
StephenButtolph Jun 6, 2024
7e54864
nit
StephenButtolph Jun 6, 2024
db6285c
merged
StephenButtolph Jun 6, 2024
577fdf0
Small metrics cleanup
StephenButtolph Jun 6, 2024
725f6b0
merged
StephenButtolph Jun 6, 2024
7f25cf4
nit
StephenButtolph Jun 6, 2024
20674ec
merged
StephenButtolph Jun 6, 2024
c9e449f
Merge branch 'master' into revamp-metrics
StephenButtolph Jun 6, 2024
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
38 changes: 30 additions & 8 deletions api/metrics/prefix_gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package metrics

import (
"errors"
"fmt"
"slices"

"github.com/prometheus/client_golang/prometheus"
"google.golang.org/protobuf/proto"
Expand All @@ -15,7 +15,11 @@ import (
dto "github.com/prometheus/client_model/go"
)

var _ MultiGatherer = (*prefixGatherer)(nil)
var (
_ MultiGatherer = (*prefixGatherer)(nil)

errOverlappingNamespaces = errors.New("prefix could create overlapping namespaces")
)

// NewPrefixGatherer returns a new MultiGatherer that merges metrics by adding a
// prefix to their names.
Expand All @@ -31,12 +35,14 @@ func (g *prefixGatherer) Register(prefix string, gatherer prometheus.Gatherer) e
g.lock.Lock()
defer g.lock.Unlock()

// TODO: Restrict prefixes to avoid potential conflicts
if slices.Contains(g.names, prefix) {
return fmt.Errorf("%w: %q",
errDuplicateGatherer,
prefix,
)
for _, existingPrefix := range g.names {
if eitherIsPrefix(prefix, existingPrefix) {
return fmt.Errorf("%w: %q conflicts with %q",
errOverlappingNamespaces,
prefix,
existingPrefix,
)
}
}

g.names = append(g.names, prefix)
Expand Down Expand Up @@ -64,3 +70,19 @@ func (g *prefixedGatherer) Gather() ([]*dto.MetricFamily, error) {
}
return metricFamilies, err
}

// eitherIsPrefix returns true if either [a] is a prefix of [b] or [b] is a
// prefix of [a].
//
// This function accounts for the usage of the namespace boundary, so "hello" is
// not considered a prefix of "helloworld". However, "hello" is considered a
// prefix of "hello_world".
func eitherIsPrefix(a, b string) bool {
if len(a) > len(b) {
a, b = b, a
}
return a == b[:len(a)] && // a is a prefix of b
(len(a) == 0 || // a is empty
len(a) == len(b) || // a is equal to b
b[len(a)] == metric.NamespaceSeparatorByte) // a ends at a namespace boundary of b
}
56 changes: 55 additions & 1 deletion api/metrics/prefix_gatherer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestPrefixGatherer_Register(t *testing.T) {
prefixGatherer: firstPrefixGatherer(),
prefix: firstPrefixedGatherer.prefix,
gatherer: secondPrefixedGatherer.gatherer,
expectedErr: errDuplicateGatherer,
expectedErr: errOverlappingNamespaces,
expectedPrefixGatherer: firstPrefixGatherer(),
},
}
Expand All @@ -148,3 +148,57 @@ func TestPrefixGatherer_Register(t *testing.T) {
})
}
}

func TestEitherIsPrefix(t *testing.T) {
tests := []struct {
name string
a string
b string
expected bool
}{
{
name: "empty strings",
a: "",
b: "",
expected: true,
},
{
name: "an empty string",
a: "",
b: "hello",
expected: true,
},
{
name: "same strings",
a: "x",
b: "x",
expected: true,
},
{
name: "different strings",
a: "x",
b: "y",
expected: false,
},
{
name: "splits namespace",
a: "hello",
b: "hello_world",
expected: true,
},
{
name: "is prefix before separator",
a: "hello",
b: "helloworld",
expected: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require := require.New(t)

require.Equal(test.expected, eitherIsPrefix(test.a, test.b))
require.Equal(test.expected, eitherIsPrefix(test.b, test.a))
})
}
}
3 changes: 0 additions & 3 deletions chains/linearizable_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package chains
import (
"context"

"github.com/ava-labs/avalanchego/api/metrics"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
Expand All @@ -29,7 +28,6 @@ type initializeOnLinearizeVM struct {
vmToInitialize common.VM
vmToLinearize *linearizeOnInitializeVM

registerer metrics.MultiGatherer
ctx *snow.Context
db database.Database
genesisBytes []byte
Expand All @@ -42,7 +40,6 @@ type initializeOnLinearizeVM struct {

func (vm *initializeOnLinearizeVM) Linearize(ctx context.Context, stopVertexID ids.ID) error {
vm.vmToLinearize.stopVertexID = stopVertexID
vm.ctx.Metrics = vm.registerer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely resolves #1581.

return vm.vmToInitialize.Initialize(
ctx,
vm.ctx,
Expand Down
Loading
Loading