Merge ~ilasc/turnip:add-statsd-env-label into turnip:master

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 78c71243abc12dd68b3ffe085277456491e3c48d
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ilasc/turnip:add-statsd-env-label
Merge into: turnip:master
Diff against target: 111 lines (+32/-16)
5 files modified
charm/turnip-pack-backend/config.yaml (+5/-1)
charm/turnip-pack-backend/templates/turnip-pack-backend.service.j2 (+1/-0)
config.yaml (+2/-1)
turnip/pack/git.py (+19/-12)
turnip/pack/tests/test_functional.py (+5/-2)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+393116@code.launchpad.net

Commit message

Add environment label for Statsd metrics

Description of the change

This branch changes the prefix from 'turnip_production_git'/'turnip_qastaging_git'/ 'turnip_test_git' to 'turnip' for all environments. This prefix together with the gauge name set to 'statsd' will give us the generic top label: 'turnip_statsd'.

Notes:
1: We already have an environment label in production, but not in QAS:
https://chat.canonical.com/canonical/pl/qgpj6kfuoifs7xqnin8pwqwfsa
https://chat.canonical.com/canonical/pl/4dagm948kb8btja3eenqk5kmny

For this reason I went with 'env' as the label name so it doesn't clash with the existent one in Production.

2: We need to pass in some name ('statsd') for the gauge so that the top label stays generic (currently in this branch: 'turnip_statsd' https://chat.canonical.com/canonical/pl/41jwxw9zu7nt8by4czr6qx61dh).
If we pass in only the prefix, the top label will not remain generic as the first gauge label (operation) gets attached to the prefix and results in as many top labels as there are git operations (git-receive-pack, git-upload-pack....): https://chat.canonical.com/canonical/pl/m3cpr1q98bfhxmso7w8anm4cqw

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Ioana Lasc (ilasc) wrote :

Thanks Colin!
Addressed comments and indeed I changed from "git" to "statsd" in the gauge name as with "git" the top label would have been "turnip_git".

I figured "turnip_statsd" would be more indicative of the metrics origin in the dashboards, but I can definitely go back to "git" & "turnip_git" if you think that's better ?

Revision history for this message
Colin Watson (cjwatson) wrote :

statsd is the interface via which we post the metrics, but that doesn't serve to distinguish one metric from another within turnip. Once we're emitting metrics from more than one spot (for example, I can imagine that we might want to emit a similar metric for cgit subprocesses, or for various API operations, etc.), the metric name needs to help us distinguish between those.

"git" is possibly slightly vaguer than I would have chosen, but it's reasonable enough since these metrics describe the resource consumption of a git subprocess.

Revision history for this message
Ioana Lasc (ilasc) wrote :

That makes sense Colin, thank you, moved to "git" form "statsd".

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/turnip-pack-backend/config.yaml b/charm/turnip-pack-backend/config.yaml
2index 489c6ec..c3a26c1 100644
3--- a/charm/turnip-pack-backend/config.yaml
4+++ b/charm/turnip-pack-backend/config.yaml
5@@ -21,5 +21,9 @@ options:
6 description: Port for Telegraf configured with the statsd input.
7 statsd_prefix:
8 type: string
9- default: turnip.test
10+ default: turnip
11 description: Prefix for statsd metrics.
12+ statsd_environment:
13+ type: string
14+ default: local
15+ description: 'env' label to set for statsd metrics.
16diff --git a/charm/turnip-pack-backend/templates/turnip-pack-backend.service.j2 b/charm/turnip-pack-backend/templates/turnip-pack-backend.service.j2
17index cc92150..29d4cc6 100644
18--- a/charm/turnip-pack-backend/templates/turnip-pack-backend.service.j2
19+++ b/charm/turnip-pack-backend/templates/turnip-pack-backend.service.j2
20@@ -19,6 +19,7 @@ Environment=VIRTINFO_TIMEOUT={{ virtinfo_timeout }}
21 Environment=STATSD_HOST={{ statsd_host }}
22 Environment=STATSD_PORT={{ statsd_port }}
23 Environment=STATSD_PREFIX={{ statsd_prefix }}
24+Environment=STATSD_ENVIRONMENT={{ statsd_environment }}
25 ExecStart={{ venv_dir }}/bin/twistd --nodaemon --pidfile= --logfile={{ base_dir }}/logs/turnip-pack-backend.log --python=packbackendserver.tac
26 ExecReload=/bin/kill -s HUP $MAINPID
27 LimitNOFILE=1048576
28diff --git a/config.yaml b/config.yaml
29index af7daa5..0273840 100644
30--- a/config.yaml
31+++ b/config.yaml
32@@ -23,4 +23,5 @@ main_site_root: https://launchpad.test/
33 celery_broker: pyamqp://guest@localhost//
34 statsd_host: 127.0.0.1
35 statsd_port: 8125
36-statsd_prefix: turnip.test
37+statsd_prefix: turnip
38+statsd_environment: local
39diff --git a/turnip/pack/git.py b/turnip/pack/git.py
40index 0d8292f..a38c4bb 100644
41--- a/turnip/pack/git.py
42+++ b/turnip/pack/git.py
43@@ -327,24 +327,31 @@ class GitProcessProtocol(protocol.ProcessProtocol, object):
44 # can't be used in statsd
45 repository = re.sub('[^0-9a-zA-Z]+', '-',
46 self.peer.raw_pathname)
47- gauge_name = ("git,operation={},repo={},metric=max_rss"
48- .format(
49- self.peer.command,
50- repository))
51+ environment = config.get("statsd_environment")
52+ gauge_name = (
53+ "git,operation={},repo={},env={},metric=max_rss"
54+ .format(
55+ self.peer.command,
56+ repository,
57+ environment))
58
59 self.statsd_client.gauge(gauge_name, resource_usage['max_rss'])
60
61- gauge_name = ("git,operation={},repo={},metric=system_time"
62- .format(
63- self.peer.command,
64- repository))
65+ gauge_name = (
66+ "git,operation={},repo={},env={},metric=system_time"
67+ .format(
68+ self.peer.command,
69+ repository,
70+ environment))
71 self.statsd_client.gauge(gauge_name,
72 resource_usage['system_time'])
73
74- gauge_name = ("git,operation={},repo={},metric=user_time"
75- .format(
76- self.peer.command,
77- repository))
78+ gauge_name = (
79+ "git,operation={},repo={},env={},metric=user_time"
80+ .format(
81+ self.peer.command,
82+ repository,
83+ environment))
84 self.statsd_client.gauge(gauge_name,
85 resource_usage['user_time'])
86
87diff --git a/turnip/pack/tests/test_functional.py b/turnip/pack/tests/test_functional.py
88index fb168e7..4e5cbf2 100644
89--- a/turnip/pack/tests/test_functional.py
90+++ b/turnip/pack/tests/test_functional.py
91@@ -106,6 +106,7 @@ class FunctionalTestMixin(WithScenarios):
92 self.virtinfo.ref_permissions = {
93 b'refs/heads/master': ['create', 'push']}
94 config.defaults['virtinfo_endpoint'] = self.virtinfo_url
95+ config.defaults['statsd_environment'] = 'local'
96
97 def startHookRPC(self):
98 self.hookrpc_handler = HookRPCHandler(self.virtinfo_url, 15)
99@@ -189,8 +190,10 @@ class FunctionalTestMixin(WithScenarios):
100 metrics = ['max_rss', 'system_time', 'user_time']
101 repository = re.sub('[^0-9a-zA-Z]+', '-', repo)
102 self.assertThat(self.statsd_client.vals, MatchesDict({
103- u'git,operation={},repo={},metric={}'.format(
104- command, repository, metric): Not(Is(None))
105+ u'git,operation={},repo={},env={},metric={}'
106+ .format(
107+ command, repository,
108+ config.get('statsd_environment'), metric): Not(Is(None))
109 for metric in metrics}))
110
111 @defer.inlineCallbacks

Subscribers

People subscribed via source and target branches