Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro committed Nov 21, 2024
1 parent b670f8a commit 665fd40
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 41 deletions.
37 changes: 10 additions & 27 deletions cmd/query/app/apiv3/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"

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

Expand Down Expand Up @@ -51,8 +50,8 @@ func (h *Handler) FindTraces(request *api_v3.FindTracesRequest, stream api_v3.Qu
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")
}

Expand All @@ -62,33 +61,17 @@ func (h *Handler) FindTraces(request *api_v3.FindTracesRequest, stream api_v3.Qu
Tags: query.GetAttributes(),
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
}
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
}

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
10 changes: 10 additions & 0 deletions cmd/query/app/internal/api_v3/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func (*TracesData) MarshalTo([]byte /* data */) (n int, err error) {
panic("unimplemented")
}

// MarshalToSizedBuffer is used by Gogo.
func (td *TracesData) MarshalToSizedBuffer(buf []byte) (int, error) {
data, err := td.Marshal()
if err != nil {
return 0, err
}
copy(buf, data)
return len(data), nil
}

// MarshalJSONPB implements gogocodec.CustomType.
func (td *TracesData) MarshalJSONPB(*jsonpb.Marshaler) ([]byte, error) {
return new(ptrace.JSONMarshaler).MarshalTraces(td.ToTraces())
Expand Down

0 comments on commit 665fd40

Please sign in to comment.