Skip to content

Commit b65094b

Browse files
Warren Fernandeswfernandes
authored andcommitted
Fixes formatting and adds syslog message test for tags
[#158344216]
1 parent 4666ae1 commit b65094b

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

rpc/loggregator_v2/syslog.go

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,23 @@ func (m *Envelope) Syslog(opts ...SyslogOption) ([][]byte, error) {
8181
messages := make([][]byte, 0, len(metrics))
8282
for name, g := range metrics {
8383
msg := m.basicSyslogMessage(c, priority)
84-
msg.StructuredData = append(msg.StructuredData,
85-
rfc5424.StructuredData{
86-
ID: gaugeStructuredDataID,
87-
Parameters: []rfc5424.SDParam{
88-
{
89-
Name: "name",
90-
Value: name,
91-
},
92-
{
93-
Name: "value",
94-
Value: strconv.FormatFloat(g.GetValue(), 'g', -1, 64),
95-
},
96-
{
97-
Name: "unit",
98-
Value: g.GetUnit(),
99-
},
84+
msg.StructuredData = append(msg.StructuredData, rfc5424.StructuredData{
85+
ID: gaugeStructuredDataID,
86+
Parameters: []rfc5424.SDParam{
87+
{
88+
Name: "name",
89+
Value: name,
90+
},
91+
{
92+
Name: "value",
93+
Value: strconv.FormatFloat(g.GetValue(), 'g', -1, 64),
94+
},
95+
{
96+
Name: "unit",
97+
Value: g.GetUnit(),
10098
},
10199
},
100+
},
102101
)
103102
d, err := msg.MarshalBinary()
104103
if err != nil {
@@ -109,24 +108,23 @@ func (m *Envelope) Syslog(opts ...SyslogOption) ([][]byte, error) {
109108
return messages, nil
110109
case *Envelope_Counter:
111110
msg := m.basicSyslogMessage(c, priority)
112-
msg.StructuredData = append(msg.StructuredData,
113-
rfc5424.StructuredData{
114-
ID: counterStructuredDataID,
115-
Parameters: []rfc5424.SDParam{
116-
{
117-
Name: "name",
118-
Value: m.GetCounter().GetName(),
119-
},
120-
{
121-
Name: "total",
122-
Value: fmt.Sprint(m.GetCounter().GetTotal()),
123-
},
124-
{
125-
Name: "delta",
126-
Value: fmt.Sprint(m.GetCounter().GetDelta()),
127-
},
111+
msg.StructuredData = append(msg.StructuredData, rfc5424.StructuredData{
112+
ID: counterStructuredDataID,
113+
Parameters: []rfc5424.SDParam{
114+
{
115+
Name: "name",
116+
Value: m.GetCounter().GetName(),
117+
},
118+
{
119+
Name: "total",
120+
Value: fmt.Sprint(m.GetCounter().GetTotal()),
121+
},
122+
{
123+
Name: "delta",
124+
Value: fmt.Sprint(m.GetCounter().GetDelta()),
128125
},
129126
},
127+
},
130128
)
131129
d, err := msg.MarshalBinary()
132130
if err != nil {
@@ -147,24 +145,23 @@ func (m *Envelope) Syslog(opts ...SyslogOption) ([][]byte, error) {
147145
return [][]byte{d}, nil
148146
case *Envelope_Timer:
149147
msg := m.basicSyslogMessage(c, priority)
150-
msg.StructuredData = append(msg.StructuredData,
151-
rfc5424.StructuredData{
152-
ID: timerStructuredDataID,
153-
Parameters: []rfc5424.SDParam{
154-
{
155-
Name: "name",
156-
Value: m.GetTimer().GetName(),
157-
},
158-
{
159-
Name: "start",
160-
Value: fmt.Sprint(m.GetTimer().GetStart()),
161-
},
162-
{
163-
Name: "stop",
164-
Value: fmt.Sprint(m.GetTimer().GetStop()),
165-
},
148+
msg.StructuredData = append(msg.StructuredData, rfc5424.StructuredData{
149+
ID: timerStructuredDataID,
150+
Parameters: []rfc5424.SDParam{
151+
{
152+
Name: "name",
153+
Value: m.GetTimer().GetName(),
154+
},
155+
{
156+
Name: "start",
157+
Value: fmt.Sprint(m.GetTimer().GetStart()),
158+
},
159+
{
160+
Name: "stop",
161+
Value: fmt.Sprint(m.GetTimer().GetStop()),
166162
},
167163
},
164+
},
168165
)
169166
d, err := msg.MarshalBinary()
170167
if err != nil {
@@ -200,12 +197,12 @@ func (m *Envelope) basicSyslogMessage(
200197
for k, v := range tags {
201198
params = append(params, rfc5424.SDParam{Name: k, Value: v})
202199
}
203-
msg.StructuredData = append(msg.StructuredData,
204-
rfc5424.StructuredData{
200+
msg.StructuredData = []rfc5424.StructuredData{
201+
{
205202
ID: tagsStructuredDataID,
206203
Parameters: params,
207204
},
208-
)
205+
}
209206
}
210207

211208
return msg

rpc/loggregator_v2/syslog_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,18 @@ var _ = Describe("Syslog", func() {
231231
env.SourceId = "some-source-id"
232232
env.InstanceId = "some-instance-id"
233233
env.Timestamp = int64(time.Hour)
234+
env.Tags = map[string]string{
235+
"namespace": "test-ns",
236+
}
234237

235238
d, err := env.Syslog(
236239
loggregator_v2.WithSyslogHostname("some-hostname"),
237240
)
238241

239242
Expect(err).ToNot(HaveOccurred())
240243
Expect(d).To(ConsistOf(
241-
[]byte(`<14>1 1970-01-01T01:00:00+00:00 some-hostname some-source-id some-instance-id - [gauge@47450 name="cpu" value="0.23" unit="percentage"] `+"\n"),
242-
[]byte(`<14>1 1970-01-01T01:00:00+00:00 some-hostname some-source-id some-instance-id - [gauge@47450 name="memory" value="5423" unit="bytes"] `+"\n"),
244+
[]byte(`<14>1 1970-01-01T01:00:00+00:00 some-hostname some-source-id some-instance-id - [tags@47450 namespace="test-ns"][gauge@47450 name="cpu" value="0.23" unit="percentage"] `+"\n"),
245+
[]byte(`<14>1 1970-01-01T01:00:00+00:00 some-hostname some-source-id some-instance-id - [tags@47450 namespace="test-ns"][gauge@47450 name="memory" value="5423" unit="bytes"] `+"\n"),
243246
))
244247
})
245248

0 commit comments

Comments
 (0)