Skip to content

Commit

Permalink
Add intrange linter
Browse files Browse the repository at this point in the history
  • Loading branch information
rockdaboot committed Feb 18, 2025
1 parent a95514f commit d8dbd0f
Show file tree
Hide file tree
Showing 557 changed files with 2,119 additions and 2,119 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ linters:
- goimports
- gosec
- govet
- intrange
- misspell
- nolintlint
- predeclared
Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/pkg/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func run(c *Config, expF exporterFunc, logger *zap.Logger) error {
return err
}

for i := 0; i < c.WorkerCount; i++ {
for i := range c.WorkerCount {
wg.Add(1)
w := worker{
numLogs: c.NumLogs,
Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func run(c *Config, expF exporterFunc, logger *zap.Logger) error {
running := &atomic.Bool{}
running.Store(true)

for i := 0; i < c.WorkerCount; i++ {
for i := range c.WorkerCount {
wg.Add(1)
w := worker{
numMetrics: c.NumMetrics,
Expand Down
12 changes: 6 additions & 6 deletions cmd/telemetrygen/pkg/metrics/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestSumNoTelemetryAttrs(t *testing.T) {
require.Len(t, m.rms, qty)

rms := m.rms
for i := 0; i < qty; i++ {
for i := range qty {
ms := rms[i].ScopeMetrics[0].Metrics[0]
assert.Equal(t, "test", ms.Name)
// @note update when telemetrygen allow other metric types
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestGaugeNoTelemetryAttrs(t *testing.T) {
require.Len(t, m.rms, qty)

rms := m.rms
for i := 0; i < qty; i++ {
for i := range qty {
ms := rms[i].ScopeMetrics[0].Metrics[0]
assert.Equal(t, "test", ms.Name)
// @note update when telemetrygen allow other metric types
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestSumSingleTelemetryAttr(t *testing.T) {
require.Len(t, m.rms, qty)

rms := m.rms
for i := 0; i < qty; i++ {
for i := range qty {
ms := rms[i].ScopeMetrics[0].Metrics[0]
assert.Equal(t, "test", ms.Name)
// @note update when telemetrygen allow other metric types
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestGaugeSingleTelemetryAttr(t *testing.T) {
require.Len(t, m.rms, qty)

rms := m.rms
for i := 0; i < qty; i++ {
for i := range qty {
ms := rms[i].ScopeMetrics[0].Metrics[0]
assert.Equal(t, "test", ms.Name)
// @note update when telemetrygen allow other metric types
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestSumMultipleTelemetryAttr(t *testing.T) {

rms := m.rms
var actualValue attribute.Value
for i := 0; i < qty; i++ {
for i := range qty {
ms := rms[i].ScopeMetrics[0].Metrics[0]
// @note update when telemetrygen allow other metric types
attr := ms.Data.(metricdata.Sum[int64]).DataPoints[0].Attributes
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestGaugeMultipleTelemetryAttr(t *testing.T) {

rms := m.rms
var actualValue attribute.Value
for i := 0; i < qty; i++ {
for i := range qty {
ms := rms[i].ScopeMetrics[0].Metrics[0]
// @note update when telemetrygen allow other metric types
attr := ms.Data.(metricdata.Gauge[int64]).DataPoints[0].Attributes
Expand Down
2 changes: 1 addition & 1 deletion cmd/telemetrygen/pkg/traces/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func run(c *Config, logger *zap.Logger) error {

telemetryAttributes := c.GetTelemetryAttributes()

for i := 0; i < c.WorkerCount; i++ {
for i := range c.WorkerCount {
wg.Add(1)
w := worker{
numTraces: c.NumTraces,
Expand Down
4 changes: 2 additions & 2 deletions cmd/telemetrygen/pkg/traces/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (w worker) simulateTraces(telemetryAttributes []attribute.KeyValue) {
trace.WithTimestamp(spanStart),
)
sp.SetAttributes(telemetryAttributes...)
for j := 0; j < w.loadSize; j++ {
for j := range w.loadSize {
sp.SetAttributes(attribute.String(fmt.Sprintf("load-%v", j), string(make([]byte, charactersPerMB))))
}

Expand All @@ -77,7 +77,7 @@ func (w worker) simulateTraces(telemetryAttributes []attribute.KeyValue) {
}
var endTimestamp trace.SpanEventOption

for j := 0; j < w.numChildSpans; j++ {
for j := range w.numChildSpans {
if err := limiter.Wait(context.Background()); err != nil {
w.logger.Fatal("limiter waited failed, retry", zap.Error(err))
}
Expand Down
30 changes: 15 additions & 15 deletions connector/countconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ func (c *count) ConsumeTraces(ctx context.Context, td ptrace.Traces) error {
var multiError error
countMetrics := pmetric.NewMetrics()
countMetrics.ResourceMetrics().EnsureCapacity(td.ResourceSpans().Len())
for i := 0; i < td.ResourceSpans().Len(); i++ {
for i := range td.ResourceSpans().Len() {
resourceSpan := td.ResourceSpans().At(i)
spansCounter := newCounter[ottlspan.TransformContext](c.spansMetricDefs)
spanEventsCounter := newCounter[ottlspanevent.TransformContext](c.spanEventsMetricDefs)

for j := 0; j < resourceSpan.ScopeSpans().Len(); j++ {
for j := range resourceSpan.ScopeSpans().Len() {
scopeSpan := resourceSpan.ScopeSpans().At(j)

for k := 0; k < scopeSpan.Spans().Len(); k++ {
for k := range scopeSpan.Spans().Len() {
span := scopeSpan.Spans().At(k)
sCtx := ottlspan.NewTransformContext(span, scopeSpan.Scope(), resourceSpan.Resource(), scopeSpan, resourceSpan)
multiError = errors.Join(multiError, spansCounter.update(ctx, span.Attributes(), sCtx))

for l := 0; l < span.Events().Len(); l++ {
for l := range span.Events().Len() {
event := span.Events().At(l)
eCtx := ottlspanevent.NewTransformContext(event, span, scopeSpan.Scope(), resourceSpan.Resource(), scopeSpan, resourceSpan)
multiError = errors.Join(multiError, spanEventsCounter.update(ctx, event.Attributes(), eCtx))
Expand Down Expand Up @@ -90,15 +90,15 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {
var multiError error
countMetrics := pmetric.NewMetrics()
countMetrics.ResourceMetrics().EnsureCapacity(md.ResourceMetrics().Len())
for i := 0; i < md.ResourceMetrics().Len(); i++ {
for i := range md.ResourceMetrics().Len() {
resourceMetric := md.ResourceMetrics().At(i)
metricsCounter := newCounter[ottlmetric.TransformContext](c.metricsMetricDefs)
dataPointsCounter := newCounter[ottldatapoint.TransformContext](c.dataPointsMetricDefs)

for j := 0; j < resourceMetric.ScopeMetrics().Len(); j++ {
for j := range resourceMetric.ScopeMetrics().Len() {
scopeMetrics := resourceMetric.ScopeMetrics().At(j)

for k := 0; k < scopeMetrics.Metrics().Len(); k++ {
for k := range scopeMetrics.Metrics().Len() {
metric := scopeMetrics.Metrics().At(k)
mCtx := ottlmetric.NewTransformContext(metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, metricsCounter.update(ctx, pcommon.NewMap(), mCtx))
Expand All @@ -107,31 +107,31 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {
switch metric.Type() {
case pmetric.MetricTypeGauge:
dps := metric.Gauge().DataPoints()
for i := 0; i < dps.Len(); i++ {
for i := range dps.Len() {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeSum:
dps := metric.Sum().DataPoints()
for i := 0; i < dps.Len(); i++ {
for i := range dps.Len() {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeSummary:
dps := metric.Summary().DataPoints()
for i := 0; i < dps.Len(); i++ {
for i := range dps.Len() {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeHistogram:
dps := metric.Histogram().DataPoints()
for i := 0; i < dps.Len(); i++ {
for i := range dps.Len() {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeExponentialHistogram:
dps := metric.ExponentialHistogram().DataPoints()
for i := 0; i < dps.Len(); i++ {
for i := range dps.Len() {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
Expand Down Expand Up @@ -165,14 +165,14 @@ func (c *count) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
var multiError error
countMetrics := pmetric.NewMetrics()
countMetrics.ResourceMetrics().EnsureCapacity(ld.ResourceLogs().Len())
for i := 0; i < ld.ResourceLogs().Len(); i++ {
for i := range ld.ResourceLogs().Len() {
resourceLog := ld.ResourceLogs().At(i)
counter := newCounter[ottllog.TransformContext](c.logsMetricDefs)

for j := 0; j < resourceLog.ScopeLogs().Len(); j++ {
for j := range resourceLog.ScopeLogs().Len() {
scopeLogs := resourceLog.ScopeLogs().At(j)

for k := 0; k < scopeLogs.LogRecords().Len(); k++ {
for k := range scopeLogs.LogRecords().Len() {
logRecord := scopeLogs.LogRecords().At(k)

lCtx := ottllog.NewTransformContext(logRecord, scopeLogs.Scope(), resourceLog.Resource(), scopeLogs, resourceLog)
Expand Down
2 changes: 1 addition & 1 deletion connector/datadogconnector/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func benchmarkPeerTags(b *testing.B) {

b.ResetTimer()

for n := 0; n < b.N; n++ {
for range b.N {
err = tconn.ConsumeTraces(context.Background(), genTrace())
assert.NoError(b, err)
for {
Expand Down
2 changes: 1 addition & 1 deletion connector/datadogconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (c *traceToMetricConnector) addToCache(containerID string, key string) {
}

func (c *traceToMetricConnector) populateContainerTagsCache(traces ptrace.Traces) {
for i := 0; i < traces.ResourceSpans().Len(); i++ {
for i := range traces.ResourceSpans().Len() {
rs := traces.ResourceSpans().At(i)
attrs := rs.Resource().Attributes()

Expand Down
8 changes: 4 additions & 4 deletions connector/exceptionsconnector/connector_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *logsConnector) Capabilities() consumer.Capabilities {
// It aggregates the trace data to generate logs.
func (c *logsConnector) ConsumeTraces(ctx context.Context, traces ptrace.Traces) error {
ld := plog.NewLogs()
for i := 0; i < traces.ResourceSpans().Len(); i++ {
for i := range traces.ResourceSpans().Len() {
rspans := traces.ResourceSpans().At(i)
resourceAttr := rspans.Resource().Attributes()
serviceAttr, ok := resourceAttr.Get(conventions.AttributeServiceName)
Expand All @@ -59,14 +59,14 @@ func (c *logsConnector) ConsumeTraces(ctx context.Context, traces ptrace.Traces)
}
serviceName := serviceAttr.Str()
ilsSlice := rspans.ScopeSpans()
for j := 0; j < ilsSlice.Len(); j++ {
for j := range ilsSlice.Len() {
sl := c.newScopeLogs(ld)
ils := ilsSlice.At(j)
ils.Scope().CopyTo(sl.Scope())
spans := ils.Spans()
for k := 0; k < spans.Len(); k++ {
for k := range spans.Len() {
span := spans.At(k)
for l := 0; l < span.Events().Len(); l++ {
for l := range span.Events().Len() {
event := span.Events().At(l)
if event.Name() == eventNameExc {
c.attrToLogRecord(sl, serviceName, span, event, resourceAttr)
Expand Down
10 changes: 5 additions & 5 deletions connector/exceptionsconnector/connector_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *metricsConnector) Capabilities() consumer.Capabilities {
// ConsumeTraces implements the consumer.Traces interface.
// It aggregates the trace data to generate metrics.
func (c *metricsConnector) ConsumeTraces(ctx context.Context, traces ptrace.Traces) error {
for i := 0; i < traces.ResourceSpans().Len(); i++ {
for i := range traces.ResourceSpans().Len() {
rspans := traces.ResourceSpans().At(i)
resourceAttr := rspans.Resource().Attributes()
serviceAttr, ok := resourceAttr.Get(conventions.AttributeServiceName)
Expand All @@ -82,12 +82,12 @@ func (c *metricsConnector) ConsumeTraces(ctx context.Context, traces ptrace.Trac
}
serviceName := serviceAttr.Str()
ilsSlice := rspans.ScopeSpans()
for j := 0; j < ilsSlice.Len(); j++ {
for j := range ilsSlice.Len() {
ils := ilsSlice.At(j)
spans := ils.Spans()
for k := 0; k < spans.Len(); k++ {
for k := range spans.Len() {
span := spans.At(k)
for l := 0; l < span.Events().Len(); l++ {
for l := range span.Events().Len() {
event := span.Events().At(l)
if event.Name() == eventNameExc {
eventAttrs := event.Attributes()
Expand Down Expand Up @@ -140,7 +140,7 @@ func (c *metricsConnector) collectExceptions(ilm pmetric.ScopeMetrics) error {
dp.SetStartTimestamp(c.startTimestamp)
dp.SetTimestamp(timestamp)
dp.SetIntValue(int64(exc.count))
for i := 0; i < exc.exemplars.Len(); i++ {
for i := range exc.exemplars.Len() {
exc.exemplars.At(i).SetTimestamp(timestamp)
}
dp.Exemplars().EnsureCapacity(exc.exemplars.Len())
Expand Down
4 changes: 2 additions & 2 deletions connector/exceptionsconnector/connector_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func BenchmarkConnectorConsumeTraces(b *testing.B) {

// Test
ctx := metadata.NewIncomingContext(context.Background(), nil)
for n := 0; n < b.N; n++ {
for range b.N {
assert.NoError(b, conn.ConsumeTraces(ctx, traces))
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func verifyConsumeMetricsInput(tb testing.TB, input pmetric.Metrics, numCumulati
assert.True(tb, m.At(0).Sum().IsMonotonic())
callsDps := m.At(0).Sum().DataPoints()
require.Equal(tb, 3, callsDps.Len())
for dpi := 0; dpi < 3; dpi++ {
for dpi := range 3 {
dp := callsDps.At(dpi)
assert.Equal(tb, int64(numCumulativeConsumptions), dp.IntValue(), "There should only be one metric per Service/kind combination")
assert.NotZero(tb, dp.StartTimestamp(), "StartTimestamp should be set")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (p *PipelineSelector) retryHighPriorityPipelines(ctx context.Context, retry

defer ticker.Stop()

for i := 0; i < len(p.pipelineRetries); i++ {
for i := range len(p.pipelineRetries) {
if p.exceededMaxRetries(i) {
continue
}
Expand All @@ -109,7 +109,7 @@ func (p *PipelineSelector) retryHighPriorityPipelines(ctx context.Context, retry

// checkContinueRetry checks if retry should be suspended if all higher priority levels have exceeded their max retries
func (p *PipelineSelector) checkContinueRetry(index int) bool {
for i := 0; i < index; i++ {
for i := range index {
if p.constants.MaxRetries == 0 || p.loadRetryCount(i) < p.constants.MaxRetries {
return true
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (p *PipelineSelector) reportStable(idx int) {
func NewPipelineSelector(lenPriority int, consts PSConstants) *PipelineSelector {
chans := make([]chan bool, lenPriority)

for i := 0; i < lenPriority; i++ {
for i := range lenPriority {
chans[i] = make(chan bool)
}

Expand Down
2 changes: 1 addition & 1 deletion connector/grafanacloudconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *connectorImp) Capabilities() consumer.Capabilities {

// ConsumeTraces implements connector.Traces.
func (c *connectorImp) ConsumeTraces(_ context.Context, td ptrace.Traces) error {
for i := 0; i < td.ResourceSpans().Len(); i++ {
for i := range td.ResourceSpans().Len() {
resourceSpan := td.ResourceSpans().At(i)
attrs := resourceSpan.Resource().Attributes()
mapping := attrs.AsRaw()
Expand Down
2 changes: 1 addition & 1 deletion connector/grafanacloudconnector/host_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestHostMetrics(t *testing.T) {
rm := metrics.ResourceMetrics()
metric := rm.At(0).ScopeMetrics().At(0).Metrics().At(0)
assert.Equal(t, hostInfoMetric, metric.Name())
for i := 0; i < count; i++ {
for i := range count {
dp := metric.Gauge().DataPoints().At(i)
val, ok := dp.Attributes().Get(hostIdentifierAttr)
assert.Assert(t, ok)
Expand Down
2 changes: 1 addition & 1 deletion connector/otlpjsonconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func BenchmarkConsumeLogs(b *testing.B) {
testTraces, _ := golden.ReadLogs(filepath.Join("testdata", "logsToTraces", inputTraces))
testMetrics, _ := golden.ReadLogs(filepath.Join("testdata", "logsToMetrics", inputMetrics))

for i := 0; i < b.N; i++ {
for range b.N {
assert.NoError(b, logscon.ConsumeLogs(context.Background(), testLogs))
assert.NoError(b, traceconn.ConsumeLogs(context.Background(), testTraces))
assert.NoError(b, metricconn.ConsumeLogs(context.Background(), testMetrics))
Expand Down
6 changes: 3 additions & 3 deletions connector/otlpjsonconnector/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (c *connectorLogs) Capabilities() consumer.Capabilities {
func (c *connectorLogs) ConsumeLogs(ctx context.Context, pl plog.Logs) error {
// loop through the levels of logs
logsUnmarshaler := &plog.JSONUnmarshaler{}
for i := 0; i < pl.ResourceLogs().Len(); i++ {
for i := range pl.ResourceLogs().Len() {
li := pl.ResourceLogs().At(i)
for j := 0; j < li.ScopeLogs().Len(); j++ {
for j := range li.ScopeLogs().Len() {
logRecord := li.ScopeLogs().At(j)
for k := 0; k < logRecord.LogRecords().Len(); k++ {
for k := range logRecord.LogRecords().Len() {
lRecord := logRecord.LogRecords().At(k)
token := lRecord.Body()

Expand Down
6 changes: 3 additions & 3 deletions connector/otlpjsonconnector/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func (c *connectorMetrics) Capabilities() consumer.Capabilities {
func (c *connectorMetrics) ConsumeLogs(ctx context.Context, pl plog.Logs) error {
// loop through the levels of logs
metricsUnmarshaler := &pmetric.JSONUnmarshaler{}
for i := 0; i < pl.ResourceLogs().Len(); i++ {
for i := range pl.ResourceLogs().Len() {
li := pl.ResourceLogs().At(i)
for j := 0; j < li.ScopeLogs().Len(); j++ {
for j := range li.ScopeLogs().Len() {
logRecord := li.ScopeLogs().At(j)
for k := 0; k < logRecord.LogRecords().Len(); k++ {
for k := range logRecord.LogRecords().Len() {
lRecord := logRecord.LogRecords().At(k)
token := lRecord.Body()

Expand Down
Loading

0 comments on commit d8dbd0f

Please sign in to comment.