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

node: add metrics for shard's capacity #3022

Merged
merged 1 commit into from
Nov 25, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ attribute, which is used for container domain name in NNS contracts (#2954)
- Reloading node attributes with SIGHUP (#3005)
- Reloading pool sizes (#3018)
- Reloading pprof/metrics services with SIGHUP (#3016)
- Add metrics for shard's capacity (#3021)

### Fixed
- Do not search for tombstones when handling their expiration, use local indexes instead (#2929)
Expand Down
29 changes: 18 additions & 11 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,17 +948,9 @@
var paths []string
for _, sh := range c.applicationConfiguration.engine.shards {
for _, subStorage := range sh.SubStorages {
path := subStorage.Path

for len(path) > 1 { // Dir returns / or . if nothing else left.
fi, err := os.Stat(path)
if err == nil && fi.IsDir() {
break
}
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("accessing %q: %w", path, err)
}
path = filepath.Dir(path)
path, err := getInitPath(subStorage.Path)
if err != nil {
return err

Check warning on line 953 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L951-L953

Added lines #L951 - L953 were not covered by tests
}

paths = append(paths, path)
Expand All @@ -975,6 +967,21 @@
return nil
}

func getInitPath(path string) (string, error) {
for len(path) > 1 { // Dir returns / or . if nothing else left.
fi, err := os.Stat(path)
if err == nil && fi.IsDir() {
break

Check warning on line 974 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L970-L974

Added lines #L970 - L974 were not covered by tests
}
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return "", fmt.Errorf("accessing %q: %w", path, err)
}
path = filepath.Dir(path)

Check warning on line 979 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L976-L979

Added lines #L976 - L979 were not covered by tests
}

return path, nil

Check warning on line 982 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L982

Added line #L982 was not covered by tests
}

func (c *cfg) reloadMetricsAndPprof(oldMetrics metricConfig, oldProfiler profilerConfig) {
c.veryLastClosersLock.Lock()
defer c.veryLastClosersLock.Unlock()
Expand Down
3 changes: 3 additions & 0 deletions cmd/neofs-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@

initApp(c)

err = c.setShardsCapacity()
fatalOnErr(err)

Check warning on line 66 in cmd/neofs-node/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/main.go#L64-L66

Added lines #L64 - L66 were not covered by tests
c.setHealthStatus(control.HealthStatus_STARTING)

bootUp(c)
Expand Down
24 changes: 24 additions & 0 deletions cmd/neofs-node/metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"time"

"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
Expand Down Expand Up @@ -48,3 +49,26 @@
m1.shutdownTimeout != metricsconfig.ShutdownTimeout(c) ||
m1.address != metricsconfig.Address(c)
}

func (c *cfg) setShardsCapacity() error {
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
for _, sh := range c.cfgObject.cfgLocalStorage.localStorage.DumpInfo().Shards {
paths := make([]string, 0, len(sh.BlobStorInfo.SubStorages))
for _, subStorage := range sh.BlobStorInfo.SubStorages {
path, err := getInitPath(subStorage.Path)
if err != nil {
return err
}

Check warning on line 60 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L53-L60

Added lines #L53 - L60 were not covered by tests

paths = append(paths, path)

Check warning on line 62 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L62

Added line #L62 was not covered by tests
}

capacity, err := totalBytes(paths)
if err != nil {
return fmt.Errorf("calculating capacity on shard %s: %w", sh.ID.String(), err)
}

Check warning on line 68 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L65-L68

Added lines #L65 - L68 were not covered by tests

c.metricsCollector.SetCapacitySize(sh.ID.String(), capacity)

Check warning on line 70 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L70

Added line #L70 was not covered by tests
}

return nil

Check warning on line 73 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L73

Added line #L73 was not covered by tests
}
14 changes: 14 additions & 0 deletions pkg/metrics/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

containerSize prometheus.GaugeVec
payloadSize prometheus.GaugeVec
capacitySize prometheus.GaugeVec
}
)

Expand Down Expand Up @@ -121,6 +122,13 @@
Name: "payload_size",
Help: "Accumulated size of all objects in a shard",
}, []string{shardIDLabelKey})

capacitySize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: storageNodeNameSpace,
Subsystem: engineSubsystem,
Name: "capacity",
Help: "Contains the shard's capacity",
}, []string{shardIDLabelKey})
)

return engineMetrics{
Expand All @@ -137,6 +145,7 @@
listObjectsDuration: listObjectsDuration,
containerSize: *containerSize,
payloadSize: *payloadSize,
capacitySize: *capacitySize,
}
}

Expand All @@ -154,6 +163,7 @@
prometheus.MustRegister(m.listObjectsDuration)
prometheus.MustRegister(m.containerSize)
prometheus.MustRegister(m.payloadSize)
prometheus.MustRegister(m.capacitySize)
}

func (m engineMetrics) AddListContainersDuration(d time.Duration) {
Expand Down Expand Up @@ -211,3 +221,7 @@
func (m engineMetrics) AddToPayloadCounter(shardID string, size int64) {
m.payloadSize.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(size))
}

func (m engineMetrics) SetCapacitySize(shardID string, capacity uint64) {
m.capacitySize.With(prometheus.Labels{shardIDLabelKey: shardID}).Set(float64(capacity))

Check warning on line 226 in pkg/metrics/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/engine.go#L225-L226

Added lines #L225 - L226 were not covered by tests
}
Loading