Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions aggregate/aggr_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aggregate
import (
"encoding/json"
"fmt"
"maps"
"sort"
"strings"
"time"
Expand All @@ -23,7 +24,7 @@ type AggregatorConfigure struct {
calcs map[uint64]Calculator
}

func (ac *AggregatorConfigure) UnmarshalTOML(data interface{}) error {
func (ac *AggregatorConfigure) UnmarshalTOML(data any) error {
type rawAggregatorConfigure struct {
DefaultWindow any `json:"default_window"`
AggregateRules []*AggregateRule `json:"aggregate_rules"`
Expand Down Expand Up @@ -143,9 +144,7 @@ func (cfg *AggregationAlgoConfig) ToAggregationAlgo() *AggregationAlgo {

if len(cfg.AddTags) > 0 {
algo.AddTags = make(map[string]string, len(cfg.AddTags))
for k, v := range cfg.AddTags {
algo.AddTags[k] = v
}
maps.Copy(algo.AddTags, cfg.AddTags)
}

switch {
Expand Down
2 changes: 1 addition & 1 deletion aggregate/aggr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func otelHistograms(n int) []*point.Point {
pts := make([]*point.Point, 0)
for i := 0; i < n; i++ {
for i := range n {
var kvs point.KVs
kvs = kvs.AddTag("service", "tmall").
AddTag("agent_version", "1.30").
Expand Down
2 changes: 1 addition & 1 deletion aggregate/algo_count_distinct.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *algoCountDistinct) count() int64 {
if word == ^uint64(0) {
continue
}
for bit := 0; bit < 64; bit++ {
for bit := range 64 {
if word&(uint64(1)<<bit) == 0 {
zeroBits++
}
Expand Down
2 changes: 1 addition & 1 deletion aggregate/business_coverage_more_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type brokenAggregationOptions struct{}

func (*brokenAggregationOptions) isAggregationAlgo_Options() {}
func (*brokenAggregationOptions) Equal(interface{}) bool { return false }
func (*brokenAggregationOptions) Equal(any) bool { return false }
func (*brokenAggregationOptions) MarshalTo([]byte) (int, error) {
return 0, errors.New("broken options")
}
Expand Down
5 changes: 2 additions & 3 deletions aggregate/derived_metric_collector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aggregate

import (
"maps"
"sort"
"strconv"
"sync"
Expand Down Expand Up @@ -286,9 +287,7 @@ func cloneTags(tags map[string]string) map[string]string {
}

res := make(map[string]string, len(tags))
for key, value := range tags {
res[key] = value
}
maps.Copy(res, tags)
return res
}

Expand Down
66 changes: 33 additions & 33 deletions aggregate/tail-sampling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestPickTrace(t *testing.T) {
now := time.Now()
pt1 := point.NewPoint("ddtrace", point.NewKVs(map[string]interface{}{
pt1 := point.NewPoint("ddtrace", point.NewKVs(map[string]any{
"http.server.requests_bucket": float64(10),
"resource": "/resource",
"trace_id": "1000000000",
Expand All @@ -24,7 +24,7 @@ func TestPickTrace(t *testing.T) {
}), point.CommonLoggingOptions()...)
pt1.SetTime(now)

pt2 := point.NewPoint("ddtrace", point.NewKVs(map[string]interface{}{
pt2 := point.NewPoint("ddtrace", point.NewKVs(map[string]any{
"http.server.requests_bucket": float64(10),
"resource": "/client",
"trace_id": "2000000000",
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestSamplingPipeline_DoAction1(t *testing.T) {
err := pip.Apply()
assert.NoError(t, err)
now := time.Now()
pt1 := point.NewPoint("ddtrace", point.NewKVs(map[string]interface{}{
pt1 := point.NewPoint("ddtrace", point.NewKVs(map[string]any{
"http.server.requests_bucket": float64(10),
"resource": "/resource",
"trace_id": "1000000000",
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestSamplingPipeline_DoAction(t *testing.T) {
func MockTrace() []byte {
var payload []byte
now := time.Now()
pt1 := point.NewPoint("ddtrace", point.NewKVs(map[string]interface{}{
pt1 := point.NewPoint("ddtrace", point.NewKVs(map[string]any{
"http.server.requests_bucket": float64(10),
"resource": "/resource",
"trace_id": "1000000000",
Expand All @@ -282,7 +282,7 @@ func MockTrace() []byte {
}), point.CommonLoggingOptions()...)
pt1.SetTime(now)

pt2 := point.NewPoint("ddtrace", point.NewKVs(map[string]interface{}{
pt2 := point.NewPoint("ddtrace", point.NewKVs(map[string]any{
"http.server.requests_bucket": float64(10),
"resource": "/client",
"trace_id": "1000000000",
Expand All @@ -292,7 +292,7 @@ func MockTrace() []byte {
}), point.CommonLoggingOptions()...)
pt2.SetTime(now)

pt3 := point.NewPoint("ddtrace", point.NewKVs(map[string]interface{}{
pt3 := point.NewPoint("ddtrace", point.NewKVs(map[string]any{
"http.server.requests_bucket": float64(10),
"resource": "select",
"trace_id": "1000000000",
Expand All @@ -304,7 +304,7 @@ func MockTrace() []byte {
}), point.CommonLoggingOptions()...)
pt3.SetTime(now)

pt4 := point.NewPoint("ddtrace", point.NewKVs(map[string]interface{}{
pt4 := point.NewPoint("ddtrace", point.NewKVs(map[string]any{
"http.server.requests_bucket": float64(10),
"resource": "mysql",
"trace_id": "1000000000",
Expand All @@ -316,7 +316,7 @@ func MockTrace() []byte {
}), point.CommonLoggingOptions()...)
pt4.SetTime(now)

pt5 := point.NewPoint("ddtrace", point.NewKVs(map[string]interface{}{
pt5 := point.NewPoint("ddtrace", point.NewKVs(map[string]any{
"http.server.requests_bucket": float64(10),
"resource": "GET /tmall/123",
"trace_id": "1000000000",
Expand All @@ -337,8 +337,8 @@ func MockTrace() []byte {
func TestEvaluatePipelinesTraceWideOrder(t *testing.T) {
t.Run("earlier pipeline wins even when a later span matches it", func(t *testing.T) {
packet := makeTracePacket(t,
map[string]interface{}{"resource": "/keep-first", "trace_id": "trace-wide", "span_id": "span-1", "start_time": time.Now().Unix(), "duration": int64(1)},
map[string]interface{}{"resource": "/drop-later", "trace_id": "trace-wide", "span_id": "span-2", "start_time": time.Now().Unix(), "duration": int64(1)},
map[string]any{"resource": "/keep-first", "trace_id": "trace-wide", "span_id": "span-1", "start_time": time.Now().Unix(), "duration": int64(1)},
map[string]any{"resource": "/drop-later", "trace_id": "trace-wide", "span_id": "span-2", "start_time": time.Now().Unix(), "duration": int64(1)},
)

pipelines := []*SamplingPipeline{
Expand All @@ -356,8 +356,8 @@ func TestEvaluatePipelinesTraceWideOrder(t *testing.T) {

t.Run("keep and drop conflicts follow pipeline order", func(t *testing.T) {
packet := makeTracePacket(t,
map[string]interface{}{"resource": "/normal", "trace_id": "trace-conflict", "span_id": "span-1", "status": "error", "start_time": time.Now().Unix(), "duration": int64(1)},
map[string]interface{}{"resource": "/drop-me", "trace_id": "trace-conflict", "span_id": "span-2", "start_time": time.Now().Unix(), "duration": int64(1)},
map[string]any{"resource": "/normal", "trace_id": "trace-conflict", "span_id": "span-1", "status": "error", "start_time": time.Now().Unix(), "duration": int64(1)},
map[string]any{"resource": "/drop-me", "trace_id": "trace-conflict", "span_id": "span-2", "start_time": time.Now().Unix(), "duration": int64(1)},
)

pipelines := []*SamplingPipeline{
Expand All @@ -374,7 +374,7 @@ func TestEvaluatePipelinesTraceWideOrder(t *testing.T) {
})
}

func makeTracePacket(t *testing.T, spanFields ...map[string]interface{}) *DataPacket {
func makeTracePacket(t *testing.T, spanFields ...map[string]any) *DataPacket {
t.Helper()

var payload []byte
Expand Down Expand Up @@ -674,7 +674,7 @@ func TestPickLogging(t *testing.T) {
now := time.Now()

// 创建测试数据点
createLogPoint := func(name string, fields map[string]interface{}) *point.Point {
createLogPoint := func(name string, fields map[string]any) *point.Point {
pt := point.NewPoint("logging", point.NewKVs(fields), point.CommonLoggingOptions()...)
pt.SetTime(now)
return pt
Expand All @@ -694,19 +694,19 @@ func TestPickLogging(t *testing.T) {
GroupKey: "user_id",
},
points: []*point.Point{
createLogPoint("user_action", map[string]interface{}{
createLogPoint("user_action", map[string]any{
"message": "User logged in",
"user_id": "user_123",
"level": "info",
"status": "ok",
}),
createLogPoint("user_action", map[string]interface{}{
createLogPoint("user_action", map[string]any{
"message": "User viewed profile",
"user_id": "user_123", // 同一个用户
"level": "info",
"status": "ok",
}),
createLogPoint("user_action", map[string]interface{}{
createLogPoint("user_action", map[string]any{
"message": "Another user action",
"user_id": "user_456", // 不同用户
"level": "info",
Expand All @@ -723,19 +723,19 @@ func TestPickLogging(t *testing.T) {
GroupKey: "user_id",
},
points: []*point.Point{
createLogPoint("system", map[string]interface{}{
createLogPoint("system", map[string]any{
"message": "System started",
"level": "info",
"status": "ok",
// 没有 user_id
}),
createLogPoint("user_action", map[string]interface{}{
createLogPoint("user_action", map[string]any{
"message": "User logged in",
"user_id": "user_123",
"level": "info",
"status": "ok",
}),
createLogPoint("system", map[string]interface{}{
createLogPoint("system", map[string]any{
"message": "System error",
"level": "error",
"status": "error",
Expand All @@ -752,22 +752,22 @@ func TestPickLogging(t *testing.T) {
GroupKey: "order_id",
},
points: []*point.Point{
createLogPoint("order", map[string]interface{}{
createLogPoint("order", map[string]any{
"message": "Order created",
"order_id": "ORD-12345", // 字符串
"level": "info",
}),
createLogPoint("order", map[string]interface{}{
createLogPoint("order", map[string]any{
"message": "Order updated",
"order_id": int64(12345), // int64
"level": "info",
}),
createLogPoint("order", map[string]interface{}{
createLogPoint("order", map[string]any{
"message": "Order completed",
"order_id": float64(12345.0), // float64
"level": "info",
}),
createLogPoint("order", map[string]interface{}{
createLogPoint("order", map[string]any{
"message": "Invalid order",
"order_id": true, // 不支持的类型
"level": "error",
Expand All @@ -783,17 +783,17 @@ func TestPickLogging(t *testing.T) {
GroupKey: "session_id",
},
points: []*point.Point{
createLogPoint("session", map[string]interface{}{
createLogPoint("session", map[string]any{
"message": "Session started",
"session_id": "sess_abc",
"level": "info",
}),
createLogPoint("session", map[string]interface{}{
createLogPoint("session", map[string]any{
"message": "Session activity",
"session_id": "", // 空字符串
"level": "info",
}),
createLogPoint("session", map[string]interface{}{
createLogPoint("session", map[string]any{
"message": "No session id",
"level": "info",
// 没有 session_id
Expand All @@ -809,19 +809,19 @@ func TestPickLogging(t *testing.T) {
GroupKey: "user_id",
},
points: []*point.Point{
createLogPoint("error", map[string]interface{}{
createLogPoint("error", map[string]any{
"message": "Login failed",
"user_id": "user_123",
"level": "error",
"status": "error", // 有错误状态
}),
createLogPoint("info", map[string]interface{}{
createLogPoint("info", map[string]any{
"message": "Login successful",
"user_id": "user_123",
"level": "info",
"status": "ok",
}),
createLogPoint("error", map[string]interface{}{
createLogPoint("error", map[string]any{
"message": "Payment failed",
"user_id": "user_456",
"level": "error",
Expand All @@ -838,7 +838,7 @@ func TestPickLogging(t *testing.T) {
GroupKey: "user_id",
},
points: []*point.Point{
createLogPoint("test", map[string]interface{}{
createLogPoint("test", map[string]any{
"message": "Test message",
"user_id": "user_123",
"level": "info",
Expand All @@ -855,8 +855,8 @@ func TestPickLogging(t *testing.T) {
},
points: func() []*point.Point {
var points []*point.Point
for i := 0; i < 100; i++ {
points = append(points, createLogPoint("request", map[string]interface{}{
for i := range 100 {
points = append(points, createLogPoint("request", map[string]any{
"message": "Request processed",
"request_id": fmt.Sprintf("req_%d", i%10), // 10个不同的请求ID
"level": "info",
Expand Down
8 changes: 4 additions & 4 deletions aggregate/timewheel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var dataGroupPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &DataGroup{}
},
}
Expand Down Expand Up @@ -70,7 +70,7 @@ func NewGlobalSampler(shardCount int, waitTime time.Duration) *GlobalSampler {
configMap: make(map[string]*TailSamplingConfigs),
}

for i := 0; i < shardCount; i++ {
for i := range shardCount {
// 1. 初始化 Shard 结构体
sampler.shards[i] = &Shard{
activeMap: make(map[uint64]*DataGroup),
Expand All @@ -79,7 +79,7 @@ func NewGlobalSampler(shardCount int, waitTime time.Duration) *GlobalSampler {

// 2. 初始化时间轮的 3600 个槽位
// 必须为每个槽位创建一个新的 list.List
for j := 0; j < 3600; j++ {
for j := range 3600 {
sampler.shards[i].slots[j] = list.New()
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (s *GlobalSampler) Ingest(packet *DataPacket) {
// 懒加载初始化
if shard.activeMap == nil {
shard.activeMap = make(map[uint64]*DataGroup)
for i := 0; i < 3600; i++ {
for i := range 3600 {
shard.slots[i] = list.New()
}
}
Expand Down
6 changes: 3 additions & 3 deletions aggregate/timewheel_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func BenchmarkGlobalSamplerTimeWheelIngestMergeGroup(b *testing.B) {
sampler := newBenchmarkGlobalSampler(b, ttl, nil)
sampler.Ingest(newBenchmarkTracePacket(1, nil))
packets := make([]*DataPacket, 0, packetCount)
for i := 0; i < packetCount; i++ {
for range packetCount {
packets = append(packets, newBenchmarkTracePacket(1, nil))
}

Expand Down Expand Up @@ -132,7 +132,7 @@ func newBenchmarkGlobalSampler(tb testing.TB, ttl time.Duration, pipelines []*Sa

func newBenchmarkTracePackets(count int, payload []byte) []*DataPacket {
packets := make([]*DataPacket, 0, count)
for i := 0; i < count; i++ {
for i := range count {
packets = append(packets, newBenchmarkTracePacket(uint64(i+1), payload))
}
return packets
Expand All @@ -158,7 +158,7 @@ func benchmarkTracePayload() []byte {
}

func drainBenchmarkSampler(sampler *GlobalSampler, seconds int) {
for i := 0; i < seconds; i++ {
for range seconds {
releaseBenchmarkDataGroups(sampler.AdvanceTime())
}
}
Expand Down
Loading
Loading