Skip to content

Commit 561416d

Browse files
author
Roberto Sora
committed
Implement ugly telemetry POC
1 parent d7229fe commit 561416d

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

cli/daemon/daemon.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,27 @@ var daemonize bool
6262

6363
func runDaemonCommand(cmd *cobra.Command, args []string) {
6464

65-
logrus.Infof("configure telemetry")
66-
6765
// Configure telemetry engine
6866
ph := prometheus.DefaultHandler
6967

7068
// Register the client so it receives metrics from the default engine.
71-
stats.Register(ph)
69+
engine := stats.WithPrefix("daemon")
70+
engine.Register(ph)
7271

7372
// Flush the default stats engine on return to ensure all buffered
7473
// metrics are sent to the server.
7574
defer stats.Flush()
76-
http.Handle("/metrics", ph)
77-
go http.ListenAndServe(":2112", nil)
78-
logrus.Infof("Prometheus telemetry is available on /metrics, TCP port 2112")
79-
// Set a tag on a counter increment.
80-
stats.Incr("user.login", stats.Tag{"user", "luke"})
8175

76+
// move everything inside commands and search for setting up a common prefix for all metrics sent!
77+
logrus.Infof("Setting up Prometheus telemetry on /metrics, TCP port 2112")
78+
go func() {
79+
http.Handle("/metrics", ph)
80+
logrus.Error(http.ListenAndServe(":2112", nil))
81+
}()
82+
83+
engine.Incr("board.yes", stats.Tag{"success", "false"})
84+
stats.Flush()
85+
engine.Flush()
8286
port := viper.GetString("daemon.port")
8387
s := grpc.NewServer()
8488

commands/daemon/daemon.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/arduino/arduino-cli/commands/lib"
3030
"github.com/arduino/arduino-cli/commands/upload"
3131
rpc "github.com/arduino/arduino-cli/rpc/commands"
32+
"github.com/segmentio/stats/v4"
3233
)
3334

3435
// ArduinoCoreServerImpl FIXMEDOC
@@ -46,9 +47,12 @@ func (s *ArduinoCoreServerImpl) BoardDetails(ctx context.Context, req *rpc.Board
4647
func (s *ArduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp, error) {
4748
ports, err := board.List(req.GetInstance().GetId())
4849
if err != nil {
50+
// helper function from grpc req to tags
51+
stats.Incr("board.list", stats.Tag{"success", "false"})
4952
return nil, err
5053
}
5154

55+
stats.Incr("board.list", stats.Tag{"success", "true"})
5256
return &rpc.BoardListResp{
5357
Ports: ports,
5458
}, nil

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583
3232
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
3333
github.com/schollz/closestmatch v2.1.0+incompatible
34+
github.com/segmentio/stats/v4 v4.5.3
3435
github.com/sirupsen/logrus v1.4.2
3536
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect
3637
github.com/spf13/cobra v0.0.5

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE
8585
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
8686
github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o=
8787
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
88+
github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851/go.mod h1:EsbsAEUEs15qC1cosAwxgCWV0Qhd8TmkxnA9Kw1Vhl4=
89+
github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
90+
github.com/mdlayher/taskstats v0.0.0-20190313225729-7cbba52ee072/go.mod h1:sGdS7A6CAETR53zkdjGkgoFlh1vSm7MtX+i8XfEsTMA=
8891
github.com/miekg/dns v1.0.5 h1:MQBGf2JEJDu0rg9WOpQZzeO+zW8UKwgkvP3R1dUU1Yw=
8992
github.com/miekg/dns v1.0.5/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
9093
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
@@ -108,6 +111,12 @@ github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNue
108111
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
109112
github.com/schollz/closestmatch v2.1.0+incompatible h1:Uel2GXEpJqOWBrlyI+oY9LTiyyjYS17cCYRqP13/SHk=
110113
github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g=
114+
github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e h1:uO75wNGioszjmIzcY/tvdDYKRLVvzggtAmmJkn9j4GQ=
115+
github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e/go.mod h1:tm/wZFQ8e24NYaBGIlnO2WGCAi67re4HHuOm0sftE/M=
116+
github.com/segmentio/objconv v1.0.1/go.mod h1:auayaH5k3137Cl4SoXTgrzQcuQDmvuVtZgS0fb1Ahys=
117+
github.com/segmentio/stats v4.1.0+incompatible h1:Sz7ypAORgiXoR8x8VNIOKYoVpJUIeHGt/2UDMjjRFuo=
118+
github.com/segmentio/stats/v4 v4.5.3 h1:Y/DSUWZ4c8ICgqJ9rQohzKvGqGWbLPWad5zmxVoKN+Y=
119+
github.com/segmentio/stats/v4 v4.5.3/go.mod h1:LsaahUJR7iiSs8mnkvQvdQ/RLHAS5adGLxuntg0ydGo=
111120
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
112121
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
113122
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
@@ -168,6 +177,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
168177
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
169178
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
170179
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
180+
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
171181
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
172182
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
173183
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
)
2424

2525
func main() {
26+
2627
if err := cli.ArduinoCli.Execute(); err != nil {
2728
os.Exit(errorcodes.ErrGeneric)
2829
}

telemetry/telemetry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package telemetry

0 commit comments

Comments
 (0)