Skip to content

Commit 41e4235

Browse files
authored
[pkg/stanza] Partially enable revive linter (#10346)
* [pkg/stanza] Enable revive linter and fix issues, excluding operator packages * Enable revive on pkg/stanza/operator/helper and fix issues * Update usages of pkg/stanza
1 parent 5938052 commit 41e4235

19 files changed

+119
-108
lines changed

internal/stanza/converter.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,14 @@ func convertInto(ent *entry.Entry, dest plog.LogRecord) {
345345
insertToAttributeMap(ent.Attributes, dest.Attributes())
346346
insertToAttributeVal(ent.Body, dest.Body())
347347

348-
if ent.TraceId != nil {
348+
if ent.TraceID != nil {
349349
var buffer [16]byte
350-
copy(buffer[0:16], ent.TraceId)
350+
copy(buffer[0:16], ent.TraceID)
351351
dest.SetTraceID(pcommon.NewTraceID(buffer))
352352
}
353-
if ent.SpanId != nil {
353+
if ent.SpanID != nil {
354354
var buffer [8]byte
355-
copy(buffer[0:8], ent.SpanId)
355+
copy(buffer[0:8], ent.SpanID)
356356
dest.SetSpanID(pcommon.NewSpanID(buffer))
357357
}
358358
if ent.TraceFlags != nil {

internal/stanza/converter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,10 @@ func TestConvertSeverity(t *testing.T) {
798798

799799
func TestConvertTrace(t *testing.T) {
800800
record := convertAndDrill(&entry.Entry{
801-
TraceId: []byte{
801+
TraceID: []byte{
802802
0x48, 0x01, 0x40, 0xf3, 0xd7, 0x70, 0xa5, 0xae, 0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff,
803803
},
804-
SpanId: []byte{
804+
SpanID: []byte{
805805
0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff,
806806
},
807807
TraceFlags: []byte{

internal/stanza/frompdataconverter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ func convertFrom(src plog.LogRecord, ent *entry.Entry) {
210210

211211
if !src.TraceID().IsEmpty() {
212212
buffer := src.TraceID().Bytes()
213-
ent.TraceId = buffer[:]
213+
ent.TraceID = buffer[:]
214214
}
215215
if !src.SpanID().IsEmpty() {
216216
buffer := src.SpanID().Bytes()
217-
ent.SpanId = buffer[:]
217+
ent.SpanID = buffer[:]
218218
}
219219
if src.Flags() != 0 {
220220
a := make([]byte, 4)

internal/stanza/frompdataconverter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ func TestConvertFrom(t *testing.T) {
213213
)
214214

215215
assert.Equal(t, entry.Error, e.Severity)
216-
assert.Equal(t, []byte{0x48, 0x01, 0x40, 0xf3, 0xd7, 0x70, 0xa5, 0xae, 0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff}, e.TraceId)
217-
assert.Equal(t, []byte{0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff}, e.SpanId)
216+
assert.Equal(t, []byte{0x48, 0x01, 0x40, 0xf3, 0xd7, 0x70, 0xa5, 0xae, 0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff}, e.TraceID)
217+
assert.Equal(t, []byte{0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff}, e.SpanID)
218218
assert.Equal(t, uint8(0x01), e.TraceFlags[0])
219219
}
220220
}

pkg/stanza/.golangci.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,16 @@ issues:
129129
- gosec
130130
- path: .
131131
linters:
132-
- revive
133132
- govet
133+
- path: operator/input
134+
linters:
135+
- revive
136+
- path: operator/output
137+
linters:
138+
- revive
139+
- path: operator/parser
140+
linters:
141+
- revive
142+
- path: operator/transformer
143+
linters:
144+
- revive

pkg/stanza/entry/entry.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ type Entry struct {
2929
Attributes map[string]interface{} `json:"attributes,omitempty" yaml:"attributes,omitempty"`
3030
Resource map[string]interface{} `json:"resource,omitempty" yaml:"resource,omitempty"`
3131
SeverityText string `json:"severity_text,omitempty" yaml:"severity_text,omitempty"`
32-
SpanId []byte `json:"span_id,omitempty" yaml:"span_id,omitempty"`
33-
TraceId []byte `json:"trace_id,omitempty" yaml:"trace_id,omitempty"`
32+
SpanID []byte `json:"span_id,omitempty" yaml:"span_id,omitempty"`
33+
TraceID []byte `json:"trace_id,omitempty" yaml:"trace_id,omitempty"`
3434
TraceFlags []byte `json:"trace_flags,omitempty" yaml:"trace_flags,omitempty"`
3535
Severity Severity `json:"severity" yaml:"severity"`
3636
ScopeName string `json:"scope_name" yaml:"scope_name"`
@@ -183,8 +183,8 @@ func (entry *Entry) Copy() *Entry {
183183
Attributes: copyInterfaceMap(entry.Attributes),
184184
Resource: copyInterfaceMap(entry.Resource),
185185
Body: copyValue(entry.Body),
186-
TraceId: copyByteArray(entry.TraceId),
187-
SpanId: copyByteArray(entry.SpanId),
186+
TraceID: copyByteArray(entry.TraceID),
187+
SpanID: copyByteArray(entry.SpanID),
188188
TraceFlags: copyByteArray(entry.TraceFlags),
189189
ScopeName: entry.ScopeName,
190190
}

pkg/stanza/entry/entry_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ func TestCopy(t *testing.T) {
143143
entry.Body = "test"
144144
entry.Attributes = map[string]interface{}{"label": "value"}
145145
entry.Resource = map[string]interface{}{"resource": "value"}
146-
entry.TraceId = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}
147-
entry.SpanId = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}
146+
entry.TraceID = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}
147+
entry.SpanID = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}
148148
entry.TraceFlags = []byte{0x01}
149149
entry.ScopeName = "my.logger"
150150
copy := entry.Copy()
@@ -155,8 +155,8 @@ func TestCopy(t *testing.T) {
155155
entry.Body = "new"
156156
entry.Attributes = map[string]interface{}{"label": "new value"}
157157
entry.Resource = map[string]interface{}{"resource": "new value"}
158-
entry.TraceId[0] = 0xff
159-
entry.SpanId[0] = 0xff
158+
entry.TraceID[0] = 0xff
159+
entry.SpanID[0] = 0xff
160160
entry.TraceFlags[0] = 0xff
161161
entry.ScopeName = "foo"
162162

@@ -167,8 +167,8 @@ func TestCopy(t *testing.T) {
167167
require.Equal(t, map[string]interface{}{"label": "value"}, copy.Attributes)
168168
require.Equal(t, map[string]interface{}{"resource": "value"}, copy.Resource)
169169
require.Equal(t, "test", copy.Body)
170-
require.Equal(t, []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, copy.TraceId)
171-
require.Equal(t, []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, copy.SpanId)
170+
require.Equal(t, []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, copy.TraceID)
171+
require.Equal(t, []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, copy.SpanID)
172172
require.Equal(t, []byte{0x01}, copy.TraceFlags)
173173
require.Equal(t, "my.logger", copy.ScopeName)
174174
}
@@ -185,8 +185,8 @@ func TestCopyNil(t *testing.T) {
185185
entry.Body = "new"
186186
entry.Attributes = map[string]interface{}{"label": "new value"}
187187
entry.Resource = map[string]interface{}{"resource": "new value"}
188-
entry.TraceId = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}
189-
entry.SpanId = []byte{0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x01, 0x02, 0x03}
188+
entry.TraceID = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}
189+
entry.SpanID = []byte{0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x01, 0x02, 0x03}
190190
entry.TraceFlags = []byte{0x01}
191191
entry.ScopeName = "foo"
192192

@@ -197,8 +197,8 @@ func TestCopyNil(t *testing.T) {
197197
require.Equal(t, map[string]interface{}{}, copy.Attributes)
198198
require.Equal(t, map[string]interface{}{}, copy.Resource)
199199
require.Equal(t, nil, copy.Body)
200-
require.Equal(t, []byte{}, copy.TraceId)
201-
require.Equal(t, []byte{}, copy.SpanId)
200+
require.Equal(t, []byte{}, copy.TraceID)
201+
require.Equal(t, []byte{}, copy.SpanID)
202202
require.Equal(t, []byte{}, copy.TraceFlags)
203203
require.Equal(t, "", copy.ScopeName)
204204
}

pkg/stanza/operator/helper/ip_resolver.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type IPResolver struct {
3939
}
4040

4141
// Create new resolver
42-
func NewIpResolver() *IPResolver {
42+
func NewIPResolver() *IPResolver {
4343
r := &IPResolver{
4444
cache: make(map[string]cacheEntry),
4545
stopped: false,
@@ -94,7 +94,7 @@ func (r *IPResolver) invalidateCache() {
9494
// GetHostFromIp returns hostname for given ip
9595
// It is taken from cache if exists,
9696
// otherwise lookup is performed and result is put into cache
97-
func (r *IPResolver) GetHostFromIp(ip string) (host string) {
97+
func (r *IPResolver) GetHostFromIP(ip string) (host string) {
9898
r.mutex.RLock()
9999
entry, ok := r.cache[ip]
100100
if ok {
@@ -104,7 +104,7 @@ func (r *IPResolver) GetHostFromIp(ip string) (host string) {
104104
}
105105
r.mutex.RUnlock()
106106

107-
host = r.lookupIpAddr(ip)
107+
host = r.lookupIPAddr(ip)
108108

109109
r.mutex.Lock()
110110
r.cache[ip] = cacheEntry{
@@ -116,8 +116,8 @@ func (r *IPResolver) GetHostFromIp(ip string) (host string) {
116116
return host
117117
}
118118

119-
// lookupIpAddr resturns hostname based on ip address
120-
func (r *IPResolver) lookupIpAddr(ip string) (host string) {
119+
// lookupIPAddr resturns hostname based on ip address
120+
func (r *IPResolver) lookupIPAddr(ip string) (host string) {
121121
res, err := net.LookupAddr(ip)
122122
if err != nil || len(res) == 0 {
123123
return ip

pkg/stanza/operator/helper/ip_resolver_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ import (
2424
)
2525

2626
func TestIPResolverCacheLookup(t *testing.T) {
27-
resolver := NewIpResolver()
27+
resolver := NewIPResolver()
2828
resolver.cache["127.0.0.1"] = cacheEntry{
2929
hostname: "definitely invalid hostname",
3030
expireTime: time.Now().Add(time.Hour),
3131
}
3232

33-
require.Equal(t, "definitely invalid hostname", resolver.GetHostFromIp("127.0.0.1"))
33+
require.Equal(t, "definitely invalid hostname", resolver.GetHostFromIP("127.0.0.1"))
3434
}
3535

3636
func TestIPResolverCacheInvalidation(t *testing.T) {
37-
resolver := NewIpResolver()
37+
resolver := NewIPResolver()
3838

3939
resolver.cache["127.0.0.1"] = cacheEntry{
4040
hostname: "definitely invalid hostname",
@@ -44,24 +44,24 @@ func TestIPResolverCacheInvalidation(t *testing.T) {
4444
resolver.Stop()
4545
resolver.invalidateCache()
4646

47-
hostname := resolver.lookupIpAddr("127.0.0.1")
48-
require.Equal(t, hostname, resolver.GetHostFromIp("127.0.0.1"))
47+
hostname := resolver.lookupIPAddr("127.0.0.1")
48+
require.Equal(t, hostname, resolver.GetHostFromIP("127.0.0.1"))
4949
}
5050

5151
func TestIPResolver100Hits(t *testing.T) {
52-
resolver := NewIpResolver()
52+
resolver := NewIPResolver()
5353
resolver.cache["127.0.0.1"] = cacheEntry{
5454
hostname: "definitely invalid hostname",
5555
expireTime: time.Now().Add(time.Hour),
5656
}
5757

5858
for i := 0; i < 100; i++ {
59-
require.Equal(t, "definitely invalid hostname", resolver.GetHostFromIp("127.0.0.1"))
59+
require.Equal(t, "definitely invalid hostname", resolver.GetHostFromIP("127.0.0.1"))
6060
}
6161
}
6262

6363
func TestIPResolverWithMultipleStops(t *testing.T) {
64-
resolver := NewIpResolver()
64+
resolver := NewIPResolver()
6565

6666
resolver.Stop()
6767
resolver.Stop()

pkg/stanza/operator/helper/parser_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ func TestParserConfigBuildValid(t *testing.T) {
6767
ParseFrom: &sevField,
6868
}
6969

70-
traceIdField := entry.NewBodyField("trace_id")
71-
spanIdField := entry.NewBodyField("span_id")
70+
traceIDField := entry.NewBodyField("trace_id")
71+
spanIDField := entry.NewBodyField("span_id")
7272
traceFlagsField := entry.NewBodyField("trace_flags")
7373
cfg.TraceParser = &TraceParser{
74-
TraceId: &TraceIdConfig{
75-
ParseFrom: &traceIdField,
74+
TraceID: &TraceIDConfig{
75+
ParseFrom: &traceIDField,
7676
},
77-
SpanId: &SpanIdConfig{
78-
ParseFrom: &spanIdField,
77+
SpanID: &SpanIDConfig{
78+
ParseFrom: &spanIDField,
7979
},
8080
TraceFlags: &TraceFlagsConfig{
8181
ParseFrom: &traceFlagsField,

pkg/stanza/operator/helper/trace.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ import (
2424

2525
// NewTraceParser creates a new trace parser with default values
2626
func NewTraceParser() TraceParser {
27-
traceId := entry.NewBodyField("trace_id")
28-
spanId := entry.NewBodyField("span_id")
27+
traceID := entry.NewBodyField("trace_id")
28+
spanID := entry.NewBodyField("span_id")
2929
traceFlags := entry.NewBodyField("trace_flags")
3030
return TraceParser{
31-
TraceId: &TraceIdConfig{
32-
ParseFrom: &traceId,
31+
TraceID: &TraceIDConfig{
32+
ParseFrom: &traceID,
3333
},
34-
SpanId: &SpanIdConfig{
35-
ParseFrom: &spanId,
34+
SpanID: &SpanIDConfig{
35+
ParseFrom: &spanID,
3636
},
3737
TraceFlags: &TraceFlagsConfig{
3838
ParseFrom: &traceFlags,
@@ -42,16 +42,16 @@ func NewTraceParser() TraceParser {
4242

4343
// TraceParser is a helper that parses trace spans (and flags) onto an entry.
4444
type TraceParser struct {
45-
TraceId *TraceIdConfig `mapstructure:"trace_id,omitempty" json:"trace_id,omitempty" yaml:"trace_id,omitempty"`
46-
SpanId *SpanIdConfig `mapstructure:"span_id,omitempty" json:"span_id,omitempty" yaml:"span_id,omitempty"`
45+
TraceID *TraceIDConfig `mapstructure:"trace_id,omitempty" json:"trace_id,omitempty" yaml:"trace_id,omitempty"`
46+
SpanID *SpanIDConfig `mapstructure:"span_id,omitempty" json:"span_id,omitempty" yaml:"span_id,omitempty"`
4747
TraceFlags *TraceFlagsConfig `mapstructure:"trace_flags,omitempty" json:"trace_flags,omitempty" yaml:"trace_flags,omitempty"`
4848
}
4949

50-
type TraceIdConfig struct {
50+
type TraceIDConfig struct {
5151
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty" json:"parse_from,omitempty" yaml:"parse_from,omitempty"`
5252
}
5353

54-
type SpanIdConfig struct {
54+
type SpanIDConfig struct {
5555
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty" json:"parse_from,omitempty" yaml:"parse_from,omitempty"`
5656
}
5757

@@ -61,19 +61,19 @@ type TraceFlagsConfig struct {
6161

6262
// Validate validates a TraceParser, and reconfigures it if necessary
6363
func (t *TraceParser) Validate() error {
64-
if t.TraceId == nil {
65-
t.TraceId = &TraceIdConfig{}
64+
if t.TraceID == nil {
65+
t.TraceID = &TraceIDConfig{}
6666
}
67-
if t.TraceId.ParseFrom == nil {
67+
if t.TraceID.ParseFrom == nil {
6868
field := entry.NewBodyField("trace_id")
69-
t.TraceId.ParseFrom = &field
69+
t.TraceID.ParseFrom = &field
7070
}
71-
if t.SpanId == nil {
72-
t.SpanId = &SpanIdConfig{}
71+
if t.SpanID == nil {
72+
t.SpanID = &SpanIDConfig{}
7373
}
74-
if t.SpanId.ParseFrom == nil {
74+
if t.SpanID.ParseFrom == nil {
7575
field := entry.NewBodyField("span_id")
76-
t.SpanId.ParseFrom = &field
76+
t.SpanID.ParseFrom = &field
7777
}
7878
if t.TraceFlags == nil {
7979
t.TraceFlags = &TraceFlagsConfig{}
@@ -101,17 +101,17 @@ func parseHexField(entry *entry.Entry, field *entry.Field) ([]byte, error) {
101101

102102
// Parse will parse a trace (trace_id, span_id and flags) from a field and attach it to the entry
103103
func (t *TraceParser) Parse(entry *entry.Entry) error {
104-
var errTraceId, errSpanId, errTraceFlags error
105-
entry.TraceId, errTraceId = parseHexField(entry, t.TraceId.ParseFrom)
106-
entry.SpanId, errSpanId = parseHexField(entry, t.SpanId.ParseFrom)
104+
var errTraceID, errSpanID, errTraceFlags error
105+
entry.TraceID, errTraceID = parseHexField(entry, t.TraceID.ParseFrom)
106+
entry.SpanID, errSpanID = parseHexField(entry, t.SpanID.ParseFrom)
107107
entry.TraceFlags, errTraceFlags = parseHexField(entry, t.TraceFlags.ParseFrom)
108-
if errTraceId != nil || errTraceFlags != nil || errSpanId != nil {
108+
if errTraceID != nil || errTraceFlags != nil || errSpanID != nil {
109109
err := errors.NewError("Error decoding traces for logs", "")
110-
if errTraceId != nil {
111-
_ = err.WithDetails("trace_id", errTraceId.Error())
110+
if errTraceID != nil {
111+
_ = err.WithDetails("trace_id", errTraceID.Error())
112112
}
113-
if errSpanId != nil {
114-
_ = err.WithDetails("span_id", errSpanId.Error())
113+
if errSpanID != nil {
114+
_ = err.WithDetails("span_id", errSpanID.Error())
115115
}
116116
if errTraceFlags != nil {
117117
_ = err.WithDetails("trace_flags", errTraceFlags.Error())

0 commit comments

Comments
 (0)