Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generate gogo annotations for api_v3 #6233

Merged
merged 9 commits into from
Nov 21, 2024
Merged
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ cmd/tracegen/tracegen-*
crossdock/crossdock-*

run-crossdock.log
proto-gen/.patched-otel-proto/
__pycache__
.asset-manifest.json
deploy/
Expand Down
14 changes: 11 additions & 3 deletions Makefile.Protobuf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ PATCHED_OTEL_PROTO_DIR = proto-gen/.patched-otel-proto

PROTO_INCLUDES := \
-Iidl/proto/api_v2 \
-Iidl/proto/api_v3 \
-Imodel/proto/metrics \
-I/usr/include/github.com/gogo/protobuf

Expand Down Expand Up @@ -127,9 +126,18 @@ proto-zipkin:
# Note that the .pb.go types must be generated into the same internal package $(API_V3_PATH)
# where a manually defined traces.go file is located.
API_V3_PATH=cmd/query/app/internal/api_v3
API_V3_PATCHED_DIR=proto-gen/.patched/api_v3
API_V3_PATCHED=$(API_V3_PATCHED_DIR)/query_service.proto
.PHONY: patch-api-v3
patch-api-v3:
mkdir -p $(API_V3_PATCHED_DIR)
cat idl/proto/api_v3/query_service.proto | \
$(SED) -f ./proto-gen/patch-api-v3.sed \
> $(API_V3_PATCHED)

.PHONY: proto-api-v3
proto-api-v3:
$(call proto_compile, $(API_V3_PATH), idl/proto/api_v3/query_service.proto, -Iidl/opentelemetry-proto)
proto-api-v3: patch-api-v3
$(call proto_compile, $(API_V3_PATH), $(API_V3_PATCHED), -I$(API_V3_PATCHED_DIR) -Iidl/opentelemetry-proto)
@echo "🏗️ replace TracesData with internal custom type"
$(SED) -i 's/v1.TracesData/TracesData/g' $(API_V3_PATH)/query_service.pb.go
@echo "🏗️ remove OTEL import because we're not using any other OTLP types"
Expand Down
39 changes: 11 additions & 28 deletions cmd/query/app/apiv3/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"errors"
"fmt"

"github.com/gogo/protobuf/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -51,44 +50,28 @@
if query == nil {
return status.Error(codes.InvalidArgument, "missing query")
}
if query.GetStartTimeMin() == nil ||
query.GetStartTimeMax() == nil {
if query.GetStartTimeMin().IsZero() ||
query.GetStartTimeMax().IsZero() {
return errors.New("start time min and max are required parameters")
}

queryParams := &spanstore.TraceQueryParameters{
ServiceName: query.GetServiceName(),
OperationName: query.GetOperationName(),
Tags: query.GetAttributes(),
NumTraces: int(query.GetNumTraces()),
NumTraces: int(query.GetSearchDepth()),
}
if query.GetStartTimeMin() != nil {
startTimeMin, err := types.TimestampFromProto(query.GetStartTimeMin())
if err != nil {
return err
}
queryParams.StartTimeMin = startTimeMin
if ts := query.GetStartTimeMin(); !ts.IsZero() {
queryParams.StartTimeMin = ts
}
if query.GetStartTimeMax() != nil {
startTimeMax, err := types.TimestampFromProto(query.GetStartTimeMax())
if err != nil {
return err
}
queryParams.StartTimeMax = startTimeMax
if ts := query.GetStartTimeMax(); !ts.IsZero() {
queryParams.StartTimeMax = ts
}
if query.GetDurationMin() != nil {
durationMin, err := types.DurationFromProto(query.GetDurationMin())
if err != nil {
return err
}
queryParams.DurationMin = durationMin
if d := query.GetDurationMin(); d != 0 {
queryParams.DurationMin = d

Check warning on line 71 in cmd/query/app/apiv3/grpc_handler.go

View check run for this annotation

Codecov / codecov/patch

cmd/query/app/apiv3/grpc_handler.go#L71

Added line #L71 was not covered by tests
}
if query.GetDurationMax() != nil {
durationMax, err := types.DurationFromProto(query.GetDurationMax())
if err != nil {
return err
}
queryParams.DurationMax = durationMax
if d := query.GetDurationMax(); d != 0 {
queryParams.DurationMax = d

Check warning on line 74 in cmd/query/app/apiv3/grpc_handler.go

View check run for this annotation

Codecov / codecov/patch

cmd/query/app/apiv3/grpc_handler.go#L74

Added line #L74 was not covered by tests
}

traces, err := h.QueryService.FindTraces(stream.Context(), queryParams)
Expand Down
23 changes: 9 additions & 14 deletions cmd/query/app/apiv3/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"errors"
"net"
"testing"
"time"

"github.com/gogo/protobuf/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -124,7 +124,9 @@ func TestGetTraceTraceIDError(t *testing.T) {
}, nil).Once()

getTraceStream, err := tsc.client.GetTrace(context.Background(), &api_v3.GetTraceRequest{
TraceId: "Z",
TraceId: "Z",
StartTime: time.Now().Add(-2 * time.Hour),
EndTime: time.Now(),
})
require.NoError(t, err)
recv, err := getTraceStream.Recv()
Expand All @@ -150,10 +152,8 @@ func TestFindTraces(t *testing.T) {
ServiceName: "myservice",
OperationName: "opname",
Attributes: map[string]string{"foo": "bar"},
StartTimeMin: &types.Timestamp{},
StartTimeMax: &types.Timestamp{},
DurationMin: &types.Duration{},
DurationMax: &types.Duration{},
StartTimeMin: time.Now().Add(-2 * time.Hour),
StartTimeMax: time.Now(),
},
})
require.NoError(t, err)
Expand All @@ -172,10 +172,7 @@ func TestFindTracesQueryNil(t *testing.T) {
assert.Nil(t, recv)

responseStream, err = tsc.client.FindTraces(context.Background(), &api_v3.FindTracesRequest{
Query: &api_v3.TraceQueryParameters{
StartTimeMin: nil,
StartTimeMax: nil,
},
Query: &api_v3.TraceQueryParameters{},
})
require.NoError(t, err)
recv, err = responseStream.Recv()
Expand All @@ -190,10 +187,8 @@ func TestFindTracesStorageError(t *testing.T) {

responseStream, err := tsc.client.FindTraces(context.Background(), &api_v3.FindTracesRequest{
Query: &api_v3.TraceQueryParameters{
StartTimeMin: &types.Timestamp{},
StartTimeMax: &types.Timestamp{},
DurationMin: &types.Duration{},
DurationMax: &types.Duration{},
StartTimeMin: time.Now().Add(-2 * time.Hour),
StartTimeMax: time.Now(),
},
})
require.NoError(t, err)
Expand Down
Loading
Loading