This repository has been archived by the owner on Jan 8, 2022. It is now read-only.
forked from signalfx/golib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
event.go
84 lines (68 loc) · 2.83 KB
/
event.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
package event
import (
"fmt"
"time"
"github.com/signalfx/com_signalfx_metrics_protobuf"
)
// Category define how to display the Category. Category enumerations need to be in sync with com_signalfx_metrics_protobuf
type Category int32
const (
// USERDEFINED - Created by user via UI or API, e.g. a deployment event
USERDEFINED Category = 1000000
// ALERT - Output by anomaly detectors
ALERT Category = 100000
// AUDIT - Audit trail events
AUDIT Category = 200000
// JOB - Generated by analytics server
JOB Category = 300000
// COLLECTD - (deprecated in favor of agent) Event originated within collectd
COLLECTD Category = 400000
// SERVICEDISCOVERY - Service discovery event
SERVICEDISCOVERY Category = 500000
// EXCEPTION - Created by exception appenders to denote exceptional events
EXCEPTION Category = 700000
// AGENT - Event originated within an agent
AGENT Category = 2000000
)
// An Event is a noteworthy occurrence of something
type Event struct {
// EventType encodes where the event came from and some of the meaning
EventType string
// Category of the event created
Category Category
// Dimensions of what is being measured. They are intrinsic. Contributes to the identity of
// the metric. If this changes, we get a new metric identifier
Dimensions map[string]string
// Properties is information that's not particularly important to the event, but may be
// important to the pipeline that uses the event. They are extrinsic. It provides additional
// information about the metric. changes in this set doesn't change the metric identity
Properties map[string]interface{}
Timestamp time.Time
}
func (e *Event) String() string {
return fmt.Sprintf("E[%s\t%v\t%s\t%s\t%s]", e.EventType, e.Category, e.Dimensions, e.Properties, e.Timestamp.String())
}
// New creates a new event with empty meta data
func New(eventType string, category Category, dimensions map[string]string, timestamp time.Time) *Event {
return NewWithProperties(eventType, category, dimensions, map[string]interface{}{}, timestamp)
}
// ToProtoEC - Converts a protbuf EventCategory to type event.Category
func ToProtoEC(ec com_signalfx_metrics_protobuf.EventCategory) Category {
var response = USERDEFINED
// Check if the event.Category does not have a corresponding com_signalfx_metrics_protobuf.EventCategory
if _, ok := com_signalfx_metrics_protobuf.EventCategory_name[int32(ec)]; ok {
response = Category(int32(ec))
}
// Return the com_signalfx_metrics_protobuf.EventCategory
return response
}
// NewWithProperties creates a new event with passed metadata
func NewWithProperties(eventType string, category Category, dimensions map[string]string, properties map[string]interface{}, timestamp time.Time) *Event {
return &Event{
EventType: eventType,
Category: category,
Dimensions: dimensions,
Properties: properties,
Timestamp: timestamp,
}
}