forked from rakutentech/kafka-firehose-nozzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_test.go
113 lines (99 loc) · 2.96 KB
/
helper_test.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"encoding/binary"
"encoding/hex"
"strings"
"github.com/cloudfoundry/sonde-go/events"
"github.com/gogo/protobuf/proto"
)
const (
// testAppId is GUID for test application
testAppId = "3356a5c7-e86c-442a-b14f-ce5cc4f80ed1"
)
func str2uuid(s string) *events.UUID {
s = strings.Replace(s, "-", "", 4)
buf, _ := hex.DecodeString(s)
return &events.UUID{
Low: proto.Uint64(binary.LittleEndian.Uint64(buf[0:8])),
High: proto.Uint64(binary.LittleEndian.Uint64(buf[8:16])),
}
}
func logMessage(message, appId string, timestamp int64) *events.Envelope {
logMessage := &events.LogMessage{
Message: []byte(message),
MessageType: events.LogMessage_OUT.Enum(),
AppId: proto.String(appId),
SourceType: proto.String("DEA"),
Timestamp: proto.Int64(timestamp),
}
return &events.Envelope{
LogMessage: logMessage,
EventType: events.Envelope_LogMessage.Enum(),
Origin: proto.String("fake-origin-1"),
Timestamp: proto.Int64(timestamp),
}
}
func valueMetric(timestamp int64) *events.Envelope {
valueMetric := &events.ValueMetric{
Name: proto.String("df"),
Value: proto.Float64(0.99),
}
return &events.Envelope{
ValueMetric: valueMetric,
EventType: events.Envelope_ValueMetric.Enum(),
Origin: proto.String("fake-origin-2"),
Timestamp: proto.Int64(timestamp),
}
}
func containerMetric(appId string, timestamp int64) *events.Envelope {
return &events.Envelope{
EventType: events.Envelope_ContainerMetric.Enum(),
Origin: proto.String("fake-origin-3"),
Timestamp: proto.Int64(timestamp),
ContainerMetric: &events.ContainerMetric{
ApplicationId: proto.String(appId),
InstanceIndex: proto.Int32(0),
},
}
}
func httpStartStop(appId string, timestamp int64) *events.Envelope {
return &events.Envelope{
EventType: events.Envelope_HttpStartStop.Enum(),
Origin: proto.String("fake-origin-6"),
Timestamp: proto.Int64(timestamp),
HttpStartStop: &events.HttpStartStop{
ApplicationId: str2uuid(appId),
},
}
}
func counterEvent(timestamp int64) *events.Envelope {
return &events.Envelope{
EventType: events.Envelope_CounterEvent.Enum(),
Origin: proto.String("fake-origin-7"),
Timestamp: proto.Int64(timestamp),
CounterEvent: &events.CounterEvent{
Name: proto.String("test-event"),
},
}
}
func errorMsg(timestamp int64) *events.Envelope {
return &events.Envelope{
EventType: events.Envelope_Error.Enum(),
Origin: proto.String("fake-origin-8"),
Timestamp: proto.Int64(timestamp),
Error: &events.Error{
Message: proto.String("test-error"),
},
}
}
func unknown(timestamp int64) *events.Envelope {
return &events.Envelope{
EventType: (*events.Envelope_EventType)(proto.Int32(-1)),
Origin: proto.String("fake-origin-9"),
Timestamp: proto.Int64(timestamp),
}
}
type Int32Slice []int32
func (p Int32Slice) Len() int { return len(p) }
func (p Int32Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p Int32Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }