Skip to content

Commit

Permalink
Merge branch 'main' into ui-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
mahadzaryab1 authored Dec 18, 2024
2 parents 37a551f + 34bf409 commit af9daa6
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 117 deletions.
14 changes: 14 additions & 0 deletions cmd/anonymizer/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Options struct {
HashCustomTags bool
HashLogs bool
HashProcess bool
StartTime int64
EndTime int64
}

const (
Expand All @@ -28,6 +30,8 @@ const (
hashLogsFlag = "hash-logs"
hashProcessFlag = "hash-process"
maxSpansCount = "max-spans-count"
startTime = "start-time"
endTime = "end-time"
)

// AddFlags adds flags for anonymizer main program
Expand Down Expand Up @@ -72,6 +76,16 @@ func (o *Options) AddFlags(command *cobra.Command) {
maxSpansCount,
-1,
"The maximum number of spans to anonymize")
command.Flags().Int64Var(
&o.StartTime,
startTime,
0,
"The start time of time window for searching trace, timestampe in unix nanoseconds")
command.Flags().Int64Var(
&o.EndTime,
endTime,
0,
"The end time of time window for searching trace, timestampe in unix nanoseconds")

// mark traceid flag as mandatory
command.MarkFlagRequired(traceIDFlag)
Expand Down
6 changes: 6 additions & 0 deletions cmd/anonymizer/app/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func TestOptionsWithDefaultFlags(t *testing.T) {
assert.False(t, o.HashLogs)
assert.False(t, o.HashProcess)
assert.Equal(t, -1, o.MaxSpansCount)
assert.Equal(t, int64(0), o.StartTime)
assert.Equal(t, int64(0), o.EndTime)
}

func TestOptionsWithFlags(t *testing.T) {
Expand All @@ -40,6 +42,8 @@ func TestOptionsWithFlags(t *testing.T) {
"--hash-logs",
"--hash-process",
"--max-spans-count=100",
"--start-time=1",
"--end-time=2",
})

assert.Equal(t, "192.168.1.10:16686", o.QueryGRPCHostPort)
Expand All @@ -50,6 +54,8 @@ func TestOptionsWithFlags(t *testing.T) {
assert.True(t, o.HashLogs)
assert.True(t, o.HashProcess)
assert.Equal(t, 100, o.MaxSpansCount)
assert.Equal(t, int64(1), o.StartTime)
assert.Equal(t, int64(2), o.EndTime)
}

func TestMain(m *testing.M) {
Expand Down
9 changes: 6 additions & 3 deletions cmd/anonymizer/app/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"strings"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -49,14 +50,16 @@ func unwrapNotFoundErr(err error) error {
}

// QueryTrace queries for a trace and returns all spans inside it
func (q *Query) QueryTrace(traceID string) ([]model.Span, error) {
func (q *Query) QueryTrace(traceID string, startTime time.Time, endTime time.Time) ([]model.Span, error) {
mTraceID, err := model.TraceIDFromString(traceID)
if err != nil {
return nil, fmt.Errorf("failed to convert the provided trace id: %w", err)
}
// TODO: add start time & end time

request := api_v2.GetTraceRequest{
TraceID: mTraceID,
TraceID: mTraceID,
StartTime: startTime,
EndTime: endTime,
}

stream, err := q.client.GetTrace(context.Background(), &request)
Expand Down
16 changes: 12 additions & 4 deletions cmd/anonymizer/app/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -108,24 +109,31 @@ func TestQueryTrace(t *testing.T) {
defer q.Close()

t.Run("No error", func(t *testing.T) {
s.spanReader.On("GetTrace", matchContext, matchGetTraceParameters).Return(
startTime := time.Date(1970, time.January, 1, 0, 0, 0, 1000, time.UTC)
endTime := time.Date(1970, time.January, 1, 0, 0, 0, 2000, time.UTC)
expectedGetTraceParameters := spanstore.GetTraceParameters{
TraceID: mockTraceID,
StartTime: startTime,
EndTime: endTime,
}
s.spanReader.On("GetTrace", matchContext, expectedGetTraceParameters).Return(
mockTraceGRPC, nil).Once()

spans, err := q.QueryTrace(mockTraceID.String())
spans, err := q.QueryTrace(mockTraceID.String(), startTime, endTime)
require.NoError(t, err)
assert.Equal(t, len(spans), len(mockTraceGRPC.Spans))
})

t.Run("Invalid TraceID", func(t *testing.T) {
_, err := q.QueryTrace(mockInvalidTraceID)
_, err := q.QueryTrace(mockInvalidTraceID, time.Time{}, time.Time{})
assert.ErrorContains(t, err, "failed to convert the provided trace id")
})

t.Run("Trace not found", func(t *testing.T) {
s.spanReader.On("GetTrace", matchContext, matchGetTraceParameters).Return(
nil, spanstore.ErrTraceNotFound).Once()

spans, err := q.QueryTrace(mockTraceID.String())
spans, err := q.QueryTrace(mockTraceID.String(), time.Time{}, time.Time{})
assert.Nil(t, spans)
assert.ErrorIs(t, err, spanstore.ErrTraceNotFound)
})
Expand Down
15 changes: 14 additions & 1 deletion cmd/anonymizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -53,7 +54,11 @@ func main() {
logger.Fatal("error while creating query object", zap.Error(err))
}

spans, err := query.QueryTrace(options.TraceID)
spans, err := query.QueryTrace(
options.TraceID,
initTime(options.StartTime),
initTime(options.EndTime),
)
if err != nil {
logger.Fatal("error while querying for trace", zap.Error(err))
}
Expand Down Expand Up @@ -93,3 +98,11 @@ func main() {
os.Exit(1)
}
}

func initTime(ts int64) time.Time {
var t time.Time
if ts != 0 {
t = time.Unix(0, ts)
}
return t
}
112 changes: 61 additions & 51 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/bsm/sarama-cluster v2.1.13+incompatible
github.com/crossdock/crossdock-go v0.0.0-20160816171116-049aabb0122b
github.com/dgraph-io/badger/v4 v4.5.0
github.com/elastic/go-elasticsearch/v8 v8.16.0
github.com/elastic/go-elasticsearch/v8 v8.17.0
github.com/fsnotify/fsnotify v1.8.0
github.com/go-logr/zapr v1.3.0
github.com/gocql/gocql v1.7.0
Expand All @@ -23,17 +23,17 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.2.0
github.com/kr/pretty v0.3.1
github.com/olivere/elastic v6.2.37+incompatible
github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kafkareceiver v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kafkareceiver v0.116.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.116.0
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.61.0
Expand Down Expand Up @@ -102,54 +102,47 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/antchfx/xmlquery v1.4.2 // indirect
github.com/antchfx/xpath v1.3.2 // indirect
github.com/dgraph-io/ristretto/v2 v2.0.0 // indirect
github.com/ebitengine/purego v0.8.1 // indirect
github.com/expr-lang/expr v1.16.9 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status v0.115.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/collector/connector/connectortest v0.116.0 // indirect
go.opentelemetry.io/collector/connector/xconnector v0.116.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.116.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.116.0 // indirect
go.opentelemetry.io/collector/consumer/xconsumer v0.116.0 // indirect
go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper v0.116.0 // indirect
go.opentelemetry.io/collector/exporter/xexporter v0.116.0 // indirect
go.opentelemetry.io/collector/internal/fanoutconsumer v0.116.0 // indirect
go.opentelemetry.io/collector/internal/memorylimiter v0.116.0 // indirect
go.opentelemetry.io/collector/internal/sharedcomponent v0.116.0 // indirect
go.opentelemetry.io/collector/pipeline/xpipeline v0.116.0 // indirect
go.opentelemetry.io/collector/processor/xprocessor v0.116.0 // indirect
go.opentelemetry.io/collector/receiver/receivertest v0.116.0 // indirect
go.opentelemetry.io/collector/receiver/xreceiver v0.116.0 // indirect
go.opentelemetry.io/contrib/bridges/otelzap v0.6.0 // indirect
)

require (
github.com/IBM/sarama v1.43.3 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/antchfx/xmlquery v1.4.2 // indirect
github.com/antchfx/xpath v1.3.2 // indirect
github.com/aws/aws-msk-iam-sasl-signer-go v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/aws/aws-sdk-go-v2 v1.19.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.28 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.27 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.35 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.36 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.29 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.13 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.13 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.19.3 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/ristretto/v2 v2.0.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eapache/go-resiliency v1.7.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/ebitengine/purego v0.8.1 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/elastic/go-grok v0.3.1 // indirect
github.com/elastic/lunes v0.1.0 // indirect
github.com/expr-lang/expr v1.16.9 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/goccy/go-json v0.10.4 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
Expand Down Expand Up @@ -192,19 +185,20 @@ require (
github.com/mostynb/go-grpc-compression v1.2.3 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchpersignal v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/kafka/topic v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.115.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchpersignal v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/kafka/topic v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.116.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.116.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
Expand Down Expand Up @@ -235,22 +229,38 @@ require (
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/collector v0.116.0 // indirect
go.opentelemetry.io/collector/client v1.22.0 // indirect
go.opentelemetry.io/collector/config/configcompression v1.22.0 // indirect
go.opentelemetry.io/collector/config/confignet v1.22.0
go.opentelemetry.io/collector/config/configopaque v1.22.0
go.opentelemetry.io/collector/config/configtelemetry v0.116.0 // indirect
go.opentelemetry.io/collector/config/internal v0.116.0 // indirect
go.opentelemetry.io/collector/connector/connectortest v0.116.0 // indirect
go.opentelemetry.io/collector/connector/xconnector v0.116.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.116.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.116.0 // indirect
go.opentelemetry.io/collector/consumer/xconsumer v0.116.0 // indirect
go.opentelemetry.io/collector/exporter/debugexporter v0.116.0
go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper v0.116.0 // indirect
go.opentelemetry.io/collector/exporter/xexporter v0.116.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.116.0 // indirect
go.opentelemetry.io/collector/extension/experimental/storage v0.116.0 // indirect
go.opentelemetry.io/collector/extension/extensioncapabilities v0.116.0
go.opentelemetry.io/collector/featuregate v1.22.0 // indirect
go.opentelemetry.io/collector/internal/fanoutconsumer v0.116.0 // indirect
go.opentelemetry.io/collector/internal/memorylimiter v0.116.0 // indirect
go.opentelemetry.io/collector/internal/sharedcomponent v0.116.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.116.0 // indirect
go.opentelemetry.io/collector/pdata/testdata v0.116.0 // indirect
go.opentelemetry.io/collector/pipeline/xpipeline v0.116.0 // indirect
go.opentelemetry.io/collector/processor/xprocessor v0.116.0 // indirect
go.opentelemetry.io/collector/receiver/receivertest v0.116.0 // indirect
go.opentelemetry.io/collector/receiver/xreceiver v0.116.0 // indirect
go.opentelemetry.io/collector/semconv v0.116.0 // indirect
go.opentelemetry.io/collector/service v0.116.0 // indirect
go.opentelemetry.io/contrib/bridges/otelzap v0.6.0 // indirect
go.opentelemetry.io/contrib/config v0.10.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.31.0 // indirect
go.opentelemetry.io/contrib/zpages v0.56.0 // indirect
Expand Down
Loading

0 comments on commit af9daa6

Please sign in to comment.