Page MenuHomeSoftware Heritage

storage: Add a timed decorator to count calls and time it
ClosedPublic

Authored by ardumont on Mar 27 2019, 8:15 PM.

Details

Summary

Add @timed decorator around all storage.api.server endpoints.

Test Plan

from docker-dev:

Start storage server:

docker-compose down --volumes; SWH_SERVICE=swh-storage; docker-compose build $SWH_SERVICE; docker-compose up $SWH_SERVICE

Then in another shell:

docker-compose exec swh-storage bash -c 'ngrep -d lo udp and port 8125

Run some ingestion and check we see counters like the following:

U 127.0.0.1:39597 -> 127.0.0.1:8125
  swh_storage_request_duration_seconds:0.003577995812520385|ms|#endpoint:get_storage
#
U 127.0.0.1:52223 -> 127.0.0.1:8125
  swh_storage_request_count:1|c|#endpoint:snapshot_add
#
U 127.0.0.1:35545 -> 127.0.0.1:8125
  swh_storage_request_duration_seconds:0.005665002390742302|ms|#endpoint:get_storage
#
U 127.0.0.1:39042 -> 127.0.0.1:8125
  swh_storage_request_count:1|c|#endpoint:fetch_history_end
#
U 127.0.0.1:55143 -> 127.0.0.1:8125
  swh_storage_request_duration_seconds:0.0034950062399730086|ms|#endpoint:get_storage
#
U 127.0.0.1:56208 -> 127.0.0.1:8125
  swh_storage_request_count:1|c|#endpoint:origin_visit_update
#
U 127.0.0.1:58816 -> 127.0.0.1:8125
  swh_storage_request_duration_seconds:0.003449007635936141|ms|#endpoint:get_storage
(swh2)

Also tox is fine for non regression.

Diff Detail

Repository
rDSTO Storage manager
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Barf, wrong machine...

Add missing commit

(because diff'ed from the wrong machine)

  • swh.storage.api.server: Add metrics to storage endpoints

(for real this time)

ardumont added inline comments.
swh/storage/api/server.py
26

@douardda that's one of the reason why it did not work (as per our discussion)

49

I had to invert the order of decorator because the app.route decorator, as far as i understood it, does not use the functool.wraps so we lose information about the decorated function.

swh/storage/api/server.py
29

I have to check whether that's still useful or not...

Just remove the statsd.increment() and we should be good...

swh/storage/api/server.py
29

the increment of the counter is not needed, as the backend (be it graphite or prometheus) will keep track of the number of timed messages.

This revision is now accepted and ready to land.Mar 28 2019, 9:53 AM
swh/storage/api/server.py
29

Ack, thanks.

  • api.server: Remove unneeded stats.increment call
This revision was landed with ongoing or failed builds.Mar 28 2019, 10:27 AM
This revision was automatically updated to reflect the committed changes.