-
Notifications
You must be signed in to change notification settings - Fork 46
/
json_writer_sink.go
90 lines (73 loc) · 1.73 KB
/
json_writer_sink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package health
import (
"encoding/json"
"fmt"
"io"
)
type JsonWriterSink struct {
io.Writer
}
func (j *JsonWriterSink) EmitEvent(job string, event string, kvs map[string]string) {
b, err := json.Marshal(struct {
Job string
Event string
Timestamp string
Kvs map[string]string
}{job, event, timestamp(), kvs})
if err != nil {
return
}
j.Write(b)
}
func (j *JsonWriterSink) EmitEventErr(job string, event string, err error, kvs map[string]string) {
b, err := json.Marshal(struct {
Job string
Event string
Timestamp string
Err string
Kvs map[string]string
}{job, event, timestamp(), fmt.Sprint(err), kvs})
if err != nil {
return
}
j.Write(b)
}
func (j *JsonWriterSink) EmitTiming(job string, event string, nanoseconds int64, kvs map[string]string) {
b, err := json.Marshal(struct {
Job string
Event string
Timestamp string
Nanoseconds int64
Kvs map[string]string
}{job, event, timestamp(), nanoseconds, kvs})
if err != nil {
return
}
j.Write(b)
}
func (j *JsonWriterSink) EmitGauge(job string, event string, value float64, kvs map[string]string) {
b, err := json.Marshal(struct {
Job string
Event string
Timestamp string
Value float64
Kvs map[string]string
}{job, event, timestamp(), value, kvs})
if err != nil {
return
}
j.Write(b)
}
func (j *JsonWriterSink) EmitComplete(job string, status CompletionStatus, nanoseconds int64, kvs map[string]string) {
b, err := json.Marshal(struct {
Job string
Status string
Timestamp string
Nanoseconds int64
Kvs map[string]string
}{job, status.String(), timestamp(), nanoseconds, kvs})
if err != nil {
return
}
j.Write(b)
}