Skip to content

Commit

Permalink
[chore]: reenable default revive rules
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Dec 30, 2024
1 parent 7ec077e commit 32fe348
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 69 deletions.
43 changes: 43 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,50 @@ linters-settings:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
rules:
# Blank import should be only in a main or test package, or have a comment justifying it.
- name: blank-imports
# context.Context() should be the first parameter of a function when provided as argument.
- name: context-as-argument
# Basic types should not be used as a key in `context.WithValue`
- name: context-keys-type
# Importing with `.` makes the programs much harder to understand
- name: dot-imports
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
- name: empty-block
# for better readability, variables of type `error` must be named with the prefix `err`.
- name: error-naming
# for better readability, the errors should be last in the list of returned values by a function.
- name: error-return
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
- name: error-strings
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
- name: errorf
# incrementing an integer variable by 1 is recommended to be done using the `++` operator
- name: increment-decrement
# highlights redundant else-blocks that can be eliminated from the code
- name: indent-error-flow
# This rule suggests a shorter way of writing ranges that do not use the second value.
- name: range
# receiver names in a method should reflect the struct name (p for Person, for example)
- name: receiver-naming
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
- name: redefines-builtin-id
# redundant else-blocks that can be eliminated from the code.
- name: superfluous-else
# prevent confusing name for variables when using `time` package
- name: time-naming
# warns when an exported function or method returns a value of an un-exported type.
- name: unexported-return
# spots and proposes to remove unreachable code. also helps to spot errors
- name: unreachable-code
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
- name: unused-parameter
# Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any.
- name: use-any
# report when a variable declaration can be simplified
- name: var-declaration
# warns when initialism, variable or package naming conventions are not followed.
- name: var-naming

goimports:
# put imports beginning with prefix after 3rd-party packages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func ToTDigest(dp pmetric.ExponentialHistogramDataPoint) (counts []int64, values
func safeUint64ToInt64(v uint64) int64 {
if v > math.MaxInt64 {
return math.MaxInt64
} else {
return int64(v) // nolint:goset // overflow checked
}
return int64(v) // nolint:goset // overflow checked
}
3 changes: 1 addition & 2 deletions exporter/elasticsearchexporter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,6 @@ func mergeGeolocation(attributes pcommon.Map) {
func safeUint64ToInt64(v uint64) int64 {
if v > math.MaxInt64 {
return math.MaxInt64
} else {
return int64(v) // nolint:goset // overflow checked
}
return int64(v) // nolint:goset // overflow checked
}
6 changes: 3 additions & 3 deletions pkg/ottl/context_inferrer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
)

var defaultDummyPriorityContextInferrerCandidate = &priorityContextInferrerCandidate{
hasFunctionName: func(name string) bool {
hasFunctionName: func(_ string) bool {
return true
},
hasEnumSymbol: func(enum *EnumSymbol) bool {
hasEnumSymbol: func(_ *EnumSymbol) bool {
return true
},
getLowerContexts: func(context string) []string {
getLowerContexts: func(_ string) []string {
return nil
},
}
Expand Down
30 changes: 15 additions & 15 deletions receiver/libhoneyreceiver/encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (

const (
PbContentType = "application/x-protobuf"
JsonContentType = "application/json"
JSONContentType = "application/json"
MsgpackContentType = "application/x-msgpack"
)

var (
JsEncoder = &JsonEncoder{}
JsonPbMarshaler = &jsonpb.Marshaler{}
JsEncoder = &JSONEncoder{}
JSONPbMarshaler = &jsonpb.Marshaler{}
MpEncoder = &msgpackEncoder{}
)

Expand All @@ -39,46 +39,46 @@ type Encoder interface {
ContentType() string
}

type JsonEncoder struct{}
type JSONEncoder struct{}

func (JsonEncoder) UnmarshalTracesRequest(buf []byte) (ptraceotlp.ExportRequest, error) {
func (JSONEncoder) UnmarshalTracesRequest(buf []byte) (ptraceotlp.ExportRequest, error) {
req := ptraceotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (JsonEncoder) UnmarshalMetricsRequest(buf []byte) (pmetricotlp.ExportRequest, error) {
func (JSONEncoder) UnmarshalMetricsRequest(buf []byte) (pmetricotlp.ExportRequest, error) {
req := pmetricotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (JsonEncoder) UnmarshalLogsRequest(buf []byte) (plogotlp.ExportRequest, error) {
func (JSONEncoder) UnmarshalLogsRequest(buf []byte) (plogotlp.ExportRequest, error) {
req := plogotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (JsonEncoder) MarshalTracesResponse(resp ptraceotlp.ExportResponse) ([]byte, error) {
func (JSONEncoder) MarshalTracesResponse(resp ptraceotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (JsonEncoder) MarshalMetricsResponse(resp pmetricotlp.ExportResponse) ([]byte, error) {
func (JSONEncoder) MarshalMetricsResponse(resp pmetricotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (JsonEncoder) MarshalLogsResponse(resp plogotlp.ExportResponse) ([]byte, error) {
func (JSONEncoder) MarshalLogsResponse(resp plogotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (JsonEncoder) MarshalStatus(resp *spb.Status) ([]byte, error) {
func (JSONEncoder) MarshalStatus(resp *spb.Status) ([]byte, error) {
buf := new(bytes.Buffer)
err := JsonPbMarshaler.Marshal(buf, resp)
err := JSONPbMarshaler.Marshal(buf, resp)
return buf.Bytes(), err
}

func (JsonEncoder) ContentType() string {
return JsonContentType
func (JSONEncoder) ContentType() string {
return JSONContentType
}

// messagepack responses seem to work in JSON so leaving this alone for now.
Expand Down Expand Up @@ -116,7 +116,7 @@ func (msgpackEncoder) MarshalLogsResponse(resp plogotlp.ExportResponse) ([]byte,

func (msgpackEncoder) MarshalStatus(resp *spb.Status) ([]byte, error) {
buf := new(bytes.Buffer)
err := JsonPbMarshaler.Marshal(buf, resp)
err := JSONPbMarshaler.Marshal(buf, resp)
return buf.Bytes(), err
}

Expand Down
26 changes: 13 additions & 13 deletions receiver/libhoneyreceiver/internal/libhoneyevent/libhoneyevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func traceIDFrom(s string) trc.TraceID {
return tid
}

func generateAnId(length int) []byte {
func generateAnID(length int) []byte {
token := make([]byte, length)
_, err := rand.Read(token)
if err != nil {
Expand Down Expand Up @@ -276,23 +276,23 @@ func (l *LibhoneyEvent) GetParentID(fieldName string) (trc.SpanID, error) {

// ToPTraceSpan converts a LibhoneyEvent to a Pdata Span
func (l *LibhoneyEvent) ToPTraceSpan(newSpan *ptrace.Span, alreadyUsedFields *[]string, cfg FieldMapConfig, logger zap.Logger) error {
time_ns := l.MsgPackTimestamp.UnixNano()
logger.Debug("processing trace with", zap.Int64("timestamp", time_ns))
timeNs := l.MsgPackTimestamp.UnixNano()
logger.Debug("processing trace with", zap.Int64("timestamp", timeNs))

var parent_id trc.SpanID
var parentID trc.SpanID
if pid, ok := l.Data[cfg.Attributes.ParentID]; ok {
parent_id = spanIDFrom(pid.(string))
newSpan.SetParentSpanID(pcommon.SpanID(parent_id))
parentID = spanIDFrom(pid.(string))
newSpan.SetParentSpanID(pcommon.SpanID(parentID))
}

duration_ms := 0.0
durationMs := 0.0
for _, df := range cfg.Attributes.DurationFields {
if duration, okay := l.Data[df]; okay {
duration_ms = duration.(float64)
durationMs = duration.(float64)
break
}
}
end_timestamp := time_ns + (int64(duration_ms) * 1000000)
endTimestamp := timeNs + (int64(durationMs) * 1000000)

if tid, ok := l.Data[cfg.Attributes.TraceID]; ok {
tid := strings.ReplaceAll(tid.(string), "-", "")
Expand All @@ -306,7 +306,7 @@ func (l *LibhoneyEvent) ToPTraceSpan(newSpan *ptrace.Span, alreadyUsedFields *[]
newSpan.SetTraceID(pcommon.TraceID(traceIDFrom(tid)))
}
} else {
newSpan.SetTraceID(pcommon.TraceID(generateAnId(32)))
newSpan.SetTraceID(pcommon.TraceID(generateAnID(32)))
}

if sid, ok := l.Data[cfg.Attributes.SpanID]; ok {
Expand All @@ -323,11 +323,11 @@ func (l *LibhoneyEvent) ToPTraceSpan(newSpan *ptrace.Span, alreadyUsedFields *[]
newSpan.SetSpanID(pcommon.SpanID(spanIDFrom(sid)))
}
} else {
newSpan.SetSpanID(pcommon.SpanID(generateAnId(16)))
newSpan.SetSpanID(pcommon.SpanID(generateAnID(16)))
}

newSpan.SetStartTimestamp(pcommon.Timestamp(time_ns))
newSpan.SetEndTimestamp(pcommon.Timestamp(end_timestamp))
newSpan.SetStartTimestamp(pcommon.Timestamp(timeNs))
newSpan.SetEndTimestamp(pcommon.Timestamp(endTimestamp))

if spanName, ok := l.Data[cfg.Attributes.Name]; ok {
newSpan.SetName(spanName.(string))
Expand Down
12 changes: 6 additions & 6 deletions receiver/libhoneyreceiver/internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ToPdata(dataset string, lhes []libhoneyevent.LibhoneyEvent, cfg libhoneyeve
alreadyUsedFields = append(alreadyUsedFields, cfg.Attributes.DurationFields...)

for _, lhe := range lhes {
parent_id, err := lhe.GetParentID(cfg.Attributes.ParentID)
parentID, err := lhe.GetParentID(cfg.Attributes.ParentID)
if err != nil {
logger.Warn("parent id not found")
}
Expand All @@ -83,23 +83,23 @@ func ToPdata(dataset string, lhes []libhoneyevent.LibhoneyEvent, cfg libhoneyeve
logger.Warn("log could not be converted from libhoney to plog", zap.String("span.object", lhe.DebugString()))
}
case "span_event":
spanEvents[parent_id] = append(spanEvents[parent_id], lhe)
spanEvents[parentID] = append(spanEvents[parentID], lhe)
case "span_link":
spanLinks[parent_id] = append(spanLinks[parent_id], lhe)
spanLinks[parentID] = append(spanLinks[parentID], lhe)
}
}

start := time.Now()
for _, ss := range foundScopes.Scope {
for i := 0; i < ss.ScopeSpans.Len(); i++ {
sp := ss.ScopeSpans.At(i)
spId := trc.SpanID(sp.SpanID())
spID := trc.SpanID(sp.SpanID())

if speArr, ok := spanEvents[spId]; ok {
if speArr, ok := spanEvents[spID]; ok {
addSpanEventsToSpan(sp, speArr, alreadyUsedFields, &logger)
}

if splArr, ok := spanLinks[spId]; ok {
if splArr, ok := spanLinks[spID]; ok {
addSpanLinksToSpan(sp, splArr, alreadyUsedFields, &logger)
}
}
Expand Down
56 changes: 28 additions & 28 deletions receiver/postgresqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ func (c *postgreSQLClient) getBGWriterStats(ctx context.Context) (*bgStat, error
buffersAllocated: bufferAllocated,
maxWritten: maxWritten,
}, nil
} else {
query := `SELECT
}
query := `SELECT
cp.num_requested AS checkpoint_req,
cp.num_timed AS checkpoint_scheduled,
cp.write_time AS checkpoint_duration_write,
Expand All @@ -523,34 +523,34 @@ func (c *postgreSQLClient) getBGWriterStats(ctx context.Context) (*bgStat, error
bg.maxwritten_clean AS maxwritten_count
FROM pg_stat_bgwriter bg, pg_stat_checkpointer cp;`

row := c.client.QueryRowContext(ctx, query)

if err = row.Scan(
&checkpointsReq,
&checkpointsScheduled,
&checkpointWriteTime,
&checkpointSyncTime,
&bufferCheckpoints,
&bgWrites,
&bufferAllocated,
&maxWritten,
); err != nil {
return nil, err
}
row := c.client.QueryRowContext(ctx, query)

return &bgStat{
checkpointsReq: checkpointsReq,
checkpointsScheduled: checkpointsScheduled,
checkpointWriteTime: checkpointWriteTime,
checkpointSyncTime: checkpointSyncTime,
bgWrites: bgWrites,
bufferBackendWrites: -1, // Not found in pg17+ tables
bufferFsyncWrites: -1, // Not found in pg17+ tables
bufferCheckpoints: bufferCheckpoints,
buffersAllocated: bufferAllocated,
maxWritten: maxWritten,
}, nil
if err = row.Scan(
&checkpointsReq,
&checkpointsScheduled,
&checkpointWriteTime,
&checkpointSyncTime,
&bufferCheckpoints,
&bgWrites,
&bufferAllocated,
&maxWritten,
); err != nil {
return nil, err
}

return &bgStat{
checkpointsReq: checkpointsReq,
checkpointsScheduled: checkpointsScheduled,
checkpointWriteTime: checkpointWriteTime,
checkpointSyncTime: checkpointSyncTime,
bgWrites: bgWrites,
bufferBackendWrites: -1, // Not found in pg17+ tables
bufferFsyncWrites: -1, // Not found in pg17+ tables
bufferCheckpoints: bufferCheckpoints,
buffersAllocated: bufferAllocated,
maxWritten: maxWritten,
}, nil

}

func (c *postgreSQLClient) getMaxConnections(ctx context.Context) (int64, error) {
Expand Down

0 comments on commit 32fe348

Please sign in to comment.