Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: common/tsmon/versions/versions.go

Issue 2870293002: Introduce luci-go components version metric. (Closed)
Patch Set: luci-go/appengine is actually not imported by anything >_< Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/tsmon/standardmetrics.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 // Package versions allows processes to report string-valued metrics with
6 // versions of various libraries they link with.
7 //
8 // The metric is named 'luci/components/version', and it has single field
9 // 'component' that defines the logical name of the component whose version is
10 // reported by the metric value.
11 //
12 // Having such metrics allows to easily detect processes that use stale code in
13 // production.
14 //
15 // Various go packages can register their versions during 'init' time, and all
16 // registered version will be flushed to monitoring whenever 'Report' is called.
17 package versions
18
19 import (
20 "sync"
21
22 "github.com/luci/luci-go/common/tsmon/field"
23 "github.com/luci/luci-go/common/tsmon/metric"
24
25 "golang.org/x/net/context"
26 )
27
28 var registry struct {
29 m sync.RWMutex
30 r map[string]string
31 }
32
33 var (
34 versionMetric = metric.NewString(
35 "luci/components/version",
36 "Versions of LUCI components linked into the process.",
37 nil,
38 field.String("component"),
39 )
40 )
41
42 // Register tells the library to start reporting a version for given component.
43 //
44 // This should usually called during 'init' time.
45 //
46 // The component name will be used as a value of 'component' metric field, and
47 // the given version will become the actual reported metric value. It is a good
48 // idea to use a fully qualified go package name as 'component'.
49 func Register(component, version string) {
50 registry.m.Lock()
51 defer registry.m.Unlock()
52 if registry.r == nil {
53 registry.r = make(map[string]string, 1)
54 }
55 registry.r[component] = version
56 }
57
58 // Report populates 'luci/components/version' metric with versions of all
59 // registered components.
60 func Report(c context.Context) {
61 registry.m.RLock()
62 defer registry.m.RUnlock()
63 for component := range registry.r {
64 versionMetric.Set(c, registry.r[component], component)
65 }
66 }
OLDNEW
« no previous file with comments | « appengine/tsmon/standardmetrics.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698