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

lib/connections: Add syncthing_connections_active metric (fixes #9527) #9528

Merged
merged 4 commits into from May 4, 2024

Conversation

DerRockWolf
Copy link
Contributor

@DerRockWolf DerRockWolf commented May 4, 2024

Purpose

Adds a new metric syncthing_connections_active which equals to the amount of active connections per device.

Fixes #9527

Testing

I've manually tested it by running syncthing with these changes locally and examining the returned metrics from /metrics.
I've done the following things:

  • Connect & disconnect a device
  • Increase & decrease the number of connections and verify that the value of the metric matches with the amount displayed in the GUI.

Documentation

https://github.com/syncthing/docs/blob/main/includes/metrics-list.rst needs to be regenerated with find-metrics.go

Authorship

Your name and email will be added automatically to the AUTHORS file
based on the commit metadata.

@@ -441,6 +441,8 @@ func (s *service) handleHellos(ctx context.Context) error {
// connections are limited.
rd, wr := s.limiter.getLimiters(remoteID, c, c.IsLocal())

registerDeviceMetrics(remoteID.String())
Copy link
Member

Choose a reason for hiding this comment

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

How about doing this in func (*service) CommitConfiguration(), which is called with the config (incl. list of remote devices) at startup and when the config changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not 100% sure if I put it to the correct place 😅

I've additionally added a call to remove the metric if the device got deleted from the config. But I just noticed that this probably won't work because the connections are handled at a later point... Where would I best put the metric deletion part?

I could probably first call metricDeviceActiveConnections.DeleteLabelValues(dev.DeviceID.String()) directly followed by registerDeviceMetrics(dev.DeviceID.String()) in the for _, dev := range to.Devices { loop, but that could in theory be racy 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@calmh have you missed my last comment? The metric deletion probably isn't critical but still worth looking into I think.

And thanks for helping and reviewing so quickly and also for building syncthing ❤️

lib/connections/metrics.go Outdated Show resolved Hide resolved
@calmh calmh changed the title Add syncthing_connections_active metric lib/connections: Add syncthing_connections_active metric (fixes #9527) May 4, 2024
@calmh calmh merged commit debbe72 into syncthing:main May 4, 2024
21 checks passed
@calmh
Copy link
Member

calmh commented May 4, 2024

Nice, thank you!

calmh added a commit to calmh/syncthing that referenced this pull request May 9, 2024
* main: (45 commits)
  build: Use Go 1.22.3 at minimum
  build: Use Go 1.22.3 at minimum
  gui: Add Hindi (hi) translation template (syncthing#9530)
  gui, man, authors: Update docs, translations, and contributors
  lib/connections: Add syncthing_connections_active metric (fixes syncthing#9527) (syncthing#9528)
  etc: Use 7MiB buffer size (syncthing#9524)
  gui: Fix Firefox bookmark favicon (fixes syncthing#9506) (syncthing#9507)
  gui, man, authors: Update docs, translations, and contributors
  gui, man, authors: Update docs, translations, and contributors
  gui, man, authors: Update docs, translations, and contributors
  lib/nat: Don't crash on empty address list (fixes syncthing#9503) (syncthing#9504)
  lib/db: Drop indexes for outgoing data to force refresh (ref syncthing#9496) (syncthing#9502)
  gui: Fix missing link to device editor for names with superscript (ref syncthing#9472) (syncthing#9494)
  lib/db: Hold update lock while taking snapshot (syncthing#9496)
  build: Update dependencies (syncthing#9497)
  gui, man, authors: Update docs, translations, and contributors
  gui, man, authors: Update docs, translations, and contributors
  Removed no longer relevant Bountysource link (syncthing#9480)
  lib/api: Missing return after HTTP error
  lib/api: Extract session store (syncthing#9425)
  ...
@calmh calmh added this to the v1.27.8 milestone May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Device connection state metric
2 participants