Skip to content
Open
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
15 changes: 12 additions & 3 deletions api/errorgroups/v1/errorgroups.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ enum Order {
ORDER_OLDEST = 2;
}

message TimeRange {
google.protobuf.Duration duration = 1;
google.protobuf.Timestamp from = 2;
google.protobuf.Timestamp to = 3;
}

message GetGroupsRequest {
message Filter {
bool is_new = 1;
Expand All @@ -31,13 +37,14 @@ message GetGroupsRequest {
string service = 1;
optional string env = 2;
optional string release = 3;
google.protobuf.Duration duration = 4;
google.protobuf.Duration duration = 4 [deprecated = true];
uint32 limit = 5;
uint32 offset = 6;
Order order = 7;
bool with_total = 8;
optional string source = 9;
optional Filter filter = 10;
optional TimeRange time_range = 11;
}

message GetGroupsResponse {
Expand All @@ -57,10 +64,11 @@ message GetGroupsResponse {
message GetTopGroupsRequest {
optional string env = 1;
optional string source = 2;
google.protobuf.Duration duration = 3;
google.protobuf.Duration duration = 3 [deprecated = true];
uint32 limit = 4;
uint32 offset = 5;
bool with_total = 6;
optional TimeRange time_range = 7;
}

message GetTopGroupsResponse {
Expand All @@ -80,8 +88,9 @@ message GetHistRequest {
optional uint64 group_hash = 2;
optional string env = 3;
optional string release = 4;
optional google.protobuf.Duration duration = 5;
optional google.protobuf.Duration duration = 5 [deprecated = true];
optional string source = 6;
optional TimeRange time_range = 7;
}

message GetHistResponse {
Expand Down
30 changes: 28 additions & 2 deletions internal/api/errorgroups/v1/grpc/api.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package grpc

import (
"google.golang.org/protobuf/types/known/durationpb"

"github.com/ozontech/seq-ui/internal/app/types"
"github.com/ozontech/seq-ui/internal/pkg/service/errorgroups"
generated "github.com/ozontech/seq-ui/pkg/errorgroups/v1"
api "github.com/ozontech/seq-ui/pkg/errorgroups/v1"
)

type API struct {
generated.UnimplementedErrorGroupsServiceServer
api.UnimplementedErrorGroupsServiceServer

service errorgroups.Service
}
Expand All @@ -16,3 +19,26 @@ func New(svc errorgroups.Service) *API {
service: svc,
}
}

type trReq interface {
GetTimeRange() *api.TimeRange
GetDuration() *durationpb.Duration
}

func parseTimeRange(req trReq) *types.TimeRange {
var timeRange *types.TimeRange
if tr := req.GetTimeRange(); tr != nil {
timeRange = &types.TimeRange{
Duration: tr.Duration.AsDuration(),

From: tr.From.AsTime(),
To: tr.To.AsTime(),
}
}
if timeRange == nil && req.GetDuration() != nil {
timeRange = &types.TimeRange{
Duration: req.GetDuration().AsDuration(),
}
}
return timeRange
}
13 changes: 5 additions & 8 deletions internal/api/errorgroups/v1/grpc/get_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package grpc
import (
"context"
"encoding/json"
"time"

"go.opentelemetry.io/otel/attribute"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -41,20 +40,18 @@ func (a *API) GetGroups(ctx context.Context, req *errorgroups.GetGroupsRequest)
filterRaw, _ := json.Marshal(req.Filter)
attributes = append(attributes, attribute.KeyValue{Key: "filter", Value: attribute.StringValue(string(filterRaw))})
}
span.SetAttributes(attributes...)

var duration *time.Duration
if req.Duration != nil {
parsedDuration := req.Duration.AsDuration()
duration = &parsedDuration
if req.TimeRange != nil {
trRaw, _ := json.Marshal(req.TimeRange)
attributes = append(attributes, attribute.KeyValue{Key: "time_range", Value: attribute.StringValue(string(trRaw))})
}
span.SetAttributes(attributes...)

request := types.GetErrorGroupsRequest{
Service: req.Service,
Env: req.Env,
Source: req.Source,
Release: req.Release,
Duration: duration,
TimeRange: parseTimeRange(req),
Limit: req.Limit,
Offset: req.Offset,
Order: types.ErrorGroupsOrder(req.Order),
Expand Down
155 changes: 150 additions & 5 deletions internal/api/errorgroups/v1/grpc/get_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestGetGroups(t *testing.T) {
source = "test-source"
release = "test-release"
duration = 2 * time.Minute
now = time.Now()
now = time.Now().Truncate(0).UTC()
oneMinuteAgo = now.Add(-1 * time.Minute)
twoMinutesAgo = now.Add(-2 * time.Minute)
someErr = errors.New("some err")
Expand All @@ -47,7 +47,7 @@ func TestGetGroups(t *testing.T) {
mockArgs *mockArgs
}{
{
name: "ok",
name: "ok_duration",

req: &errorgroups_v1.GetGroupsRequest{
Service: service,
Expand Down Expand Up @@ -82,13 +82,160 @@ func TestGetGroups(t *testing.T) {
},
},

mockArgs: &mockArgs{
req: types.GetErrorGroupsRequest{
Service: service,
Env: &env,
Source: &source,
Release: &release,
TimeRange: &types.TimeRange{
Duration: duration,
},
Limit: 2,
Offset: 0,
Order: types.OrderOldest,
WithTotal: true,
},

groups: []types.ErrorGroup{
{
Hash: 123,
Message: "some error 1",
Source: source,
Count: 10,
FirstSeenAt: twoMinutesAgo,
LastSeenAt: oneMinuteAgo,
},
{
Hash: 456,
Message: "some error 2",
Source: source,
Count: 5,
FirstSeenAt: twoMinutesAgo,
LastSeenAt: oneMinuteAgo,
},
},
total: 10,
},
},
{
name: "ok_timerange",

req: &errorgroups_v1.GetGroupsRequest{
Service: service,
Env: &env,
Source: &source,
Release: &release,
Duration: durationpb.New(duration),
TimeRange: &errorgroups_v1.TimeRange{
From: timestamppb.New(twoMinutesAgo),
To: timestamppb.New(now),
},
Limit: 2,
Offset: 0,
Order: errorgroups_v1.Order_ORDER_OLDEST,
WithTotal: true,
},
want: &errorgroups_v1.GetGroupsResponse{
Total: 10,
Groups: []*errorgroups_v1.GetGroupsResponse_Group{
{
Hash: 123,
Message: "some error 1",
Source: source,
SeenTotal: 10,
FirstSeenAt: timestamppb.New(twoMinutesAgo),
LastSeenAt: timestamppb.New(oneMinuteAgo),
},
{
Hash: 456,
Message: "some error 2",
Source: source,
SeenTotal: 5,
FirstSeenAt: timestamppb.New(twoMinutesAgo),
LastSeenAt: timestamppb.New(oneMinuteAgo),
},
},
},

mockArgs: &mockArgs{
req: types.GetErrorGroupsRequest{
Service: service,
Env: &env,
Source: &source,
Release: &release,
TimeRange: &types.TimeRange{
From: twoMinutesAgo,
To: now,
},
Limit: 2,
Offset: 0,
Order: types.OrderOldest,
WithTotal: true,
},

groups: []types.ErrorGroup{
{
Hash: 123,
Message: "some error 1",
Source: source,
Count: 10,
FirstSeenAt: twoMinutesAgo,
LastSeenAt: oneMinuteAgo,
},
{
Hash: 456,
Message: "some error 2",
Source: source,
Count: 5,
FirstSeenAt: twoMinutesAgo,
LastSeenAt: oneMinuteAgo,
},
},
total: 10,
},
},
{
name: "ok_no_timerange",

req: &errorgroups_v1.GetGroupsRequest{
Service: service,
Env: &env,
Source: &source,
Release: &release,
Limit: 2,
Offset: 0,
Order: errorgroups_v1.Order_ORDER_OLDEST,
WithTotal: true,
},
want: &errorgroups_v1.GetGroupsResponse{
Total: 10,
Groups: []*errorgroups_v1.GetGroupsResponse_Group{
{
Hash: 123,
Message: "some error 1",
Source: source,
SeenTotal: 10,
FirstSeenAt: timestamppb.New(twoMinutesAgo),
LastSeenAt: timestamppb.New(oneMinuteAgo),
},
{
Hash: 456,
Message: "some error 2",
Source: source,
SeenTotal: 5,
FirstSeenAt: timestamppb.New(twoMinutesAgo),
LastSeenAt: timestamppb.New(oneMinuteAgo),
},
},
},

mockArgs: &mockArgs{
req: types.GetErrorGroupsRequest{
Service: service,
Env: &env,
Source: &source,
Release: &release,
Duration: &duration,
Limit: 2,
Offset: 0,
Order: types.OrderOldest,
Expand Down Expand Up @@ -124,7 +271,6 @@ func TestGetGroups(t *testing.T) {
Env: &env,
Source: &source,
Release: &release,
Duration: durationpb.New(duration),
Limit: 2,
Offset: 0,
Order: errorgroups_v1.Order_ORDER_OLDEST,
Expand Down Expand Up @@ -161,7 +307,6 @@ func TestGetGroups(t *testing.T) {
Env: &env,
Source: &source,
Release: &release,
Duration: &duration,
Limit: 2,
Offset: 0,
Order: types.OrderOldest,
Expand Down
14 changes: 6 additions & 8 deletions internal/api/errorgroups/v1/grpc/get_hist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package grpc

import (
"context"
"encoding/json"
"strconv"
"time"

"go.opentelemetry.io/otel/attribute"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -39,21 +39,19 @@ func (a *API) GetHist(ctx context.Context, req *errorgroups.GetHistRequest) (*er
if req.Source != nil {
attributes = append(attributes, attribute.KeyValue{Key: "source", Value: attribute.StringValue(*req.Source)})
}
span.SetAttributes(attributes...)

var duration *time.Duration
if req.Duration != nil {
parsedDuration := req.Duration.AsDuration()
duration = &parsedDuration
if req.TimeRange != nil {
trRaw, _ := json.Marshal(req.TimeRange)
attributes = append(attributes, attribute.KeyValue{Key: "time_range", Value: attribute.StringValue(string(trRaw))})
}
span.SetAttributes(attributes...)

request := types.GetErrorHistRequest{
Service: req.Service,
GroupHash: req.GroupHash,
Env: req.Env,
Source: req.Source,
Release: req.Release,
Duration: duration,
TimeRange: parseTimeRange(req),
}
hist, err := a.service.GetHist(ctx, request)
if err != nil {
Expand Down
Loading
Loading