Skip to content
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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ mock:
-destination=internal/app/auth/mock/auth.go \
github.com/ozontech/seq-ui/internal/app/auth \
OIDCProvider,JWTProvider
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/dashboards/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/dashboards \
Service
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/async_searches/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/async_searches \
Service
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/userprofile/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/userprofile \
Service
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/massexport/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/massexport \
Service

.PHONY: protoc
protoc:
Expand Down
19 changes: 10 additions & 9 deletions cmd/seq-ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
dashboards_v1 "github.com/ozontech/seq-ui/internal/api/dashboards/v1"
errorgroups_v1 "github.com/ozontech/seq-ui/internal/api/errorgroups/v1"
massexport_v1 "github.com/ozontech/seq-ui/internal/api/massexport/v1"
"github.com/ozontech/seq-ui/internal/api/profiles"
seqapi_v1 "github.com/ozontech/seq-ui/internal/api/seqapi/v1"
userprofile_v1 "github.com/ozontech/seq-ui/internal/api/userprofile/v1"
"github.com/ozontech/seq-ui/internal/app/config"
Expand All @@ -30,12 +29,14 @@ import (
"github.com/ozontech/seq-ui/internal/pkg/client/seqdb"
"github.com/ozontech/seq-ui/internal/pkg/repository"
repositorych "github.com/ozontech/seq-ui/internal/pkg/repository_ch"
"github.com/ozontech/seq-ui/internal/pkg/service"
asyncsearches "github.com/ozontech/seq-ui/internal/pkg/service/async_searches"
"github.com/ozontech/seq-ui/internal/pkg/service/dashboards"
"github.com/ozontech/seq-ui/internal/pkg/service/errorgroups"
"github.com/ozontech/seq-ui/internal/pkg/service/massexport"
"github.com/ozontech/seq-ui/internal/pkg/service/massexport/filestore"
"github.com/ozontech/seq-ui/internal/pkg/service/massexport/sessionstore"
"github.com/ozontech/seq-ui/internal/pkg/service/profiles"
"github.com/ozontech/seq-ui/internal/pkg/service/userprofile"
"github.com/ozontech/seq-ui/logger"
"github.com/ozontech/seq-ui/tracing"
)
Expand Down Expand Up @@ -151,23 +152,23 @@ func initApp(ctx context.Context, cfg config.Config) *api.Registrar {
}

var (
asyncSearchesService *asyncsearches.Service
p *profiles.Profiles
asyncSearchesService asyncsearches.Service
userProfileV1 *userprofile_v1.UserProfile
dashboardsV1 *dashboards_v1.Dashboards
)
if db != nil {
repo := repository.New(db, cfg.Server.DB.RequestTimeout)
svc := service.New(repo)
p = profiles.New(svc)
userProfilesSvc := userprofile.New(repo.UserProfiles, repo.FavoriteQueries)
dashboardsSvc := dashboards.New(repo.Dashboards)
profiles.InitProfiles(userProfilesSvc)

userProfileV1 = userprofile_v1.New(svc, p)
dashboardsV1 = dashboards_v1.New(svc, p)
userProfileV1 = userprofile_v1.New(userProfilesSvc)
dashboardsV1 = dashboards_v1.New(dashboardsSvc)

asyncSearchesService = asyncsearches.New(ctx, repo, defaultClient, cfg.Handlers.AsyncSearch)
}

seqApiV1 := seqapi_v1.New(cfg.Handlers.SeqAPI, seqDBClients, inmemWithRedisCache, redisCache, asyncSearchesService, p)
seqApiV1 := seqapi_v1.New(cfg.Handlers.SeqAPI, seqDBClients, inmemWithRedisCache, redisCache, asyncSearchesService)

logger.Info("initializing clickhouse")
ch, err := initClickHouse(ctx, cfg.Server.CH)
Expand Down
9 changes: 4 additions & 5 deletions internal/api/dashboards/v1/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import (

grpc_api "github.com/ozontech/seq-ui/internal/api/dashboards/v1/grpc"
http_api "github.com/ozontech/seq-ui/internal/api/dashboards/v1/http"
"github.com/ozontech/seq-ui/internal/api/profiles"
"github.com/ozontech/seq-ui/internal/pkg/service"
"github.com/ozontech/seq-ui/internal/pkg/service/dashboards"
)

type Dashboards struct {
grpcAPI *grpc_api.API
httpAPI *http_api.API
}

func New(svc service.Service, p *profiles.Profiles) *Dashboards {
func New(svc dashboards.Service) *Dashboards {
return &Dashboards{
grpcAPI: grpc_api.New(svc, p),
httpAPI: http_api.New(svc, p),
grpcAPI: grpc_api.New(svc),
httpAPI: http_api.New(svc),
}
}

Expand Down
15 changes: 6 additions & 9 deletions internal/api/dashboards/v1/grpc/api.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package grpc

import (
"github.com/ozontech/seq-ui/internal/api/profiles"
"github.com/ozontech/seq-ui/internal/pkg/service"
"github.com/ozontech/seq-ui/pkg/dashboards/v1"
"github.com/ozontech/seq-ui/internal/pkg/service/dashboards"
api "github.com/ozontech/seq-ui/pkg/dashboards/v1"
)

type API struct {
dashboards.UnimplementedDashboardsServiceServer
api.UnimplementedDashboardsServiceServer

service service.Service
profiles *profiles.Profiles
service dashboards.Service
}

func New(svc service.Service, p *profiles.Profiles) *API {
func New(svc dashboards.Service) *API {
return &API{
service: svc,
profiles: p,
service: svc,
}
}
11 changes: 3 additions & 8 deletions internal/api/dashboards/v1/grpc/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ func (a *API) Create(ctx context.Context, req *dashboards.CreateRequest) (*dashb
},
)

profileID, err := a.profiles.GeIDFromContext(ctx)
if err != nil {
return nil, grpcutil.ProcessError(err)
}

request := types.CreateDashboardRequest{
ProfileID: profileID,
Name: req.Name,
Meta: req.Meta,
Name: req.Name,
Meta: req.Meta,
}

uuid, err := a.service.CreateDashboard(ctx, request)
if err != nil {
return nil, grpcutil.ProcessError(err)
Expand Down
73 changes: 20 additions & 53 deletions internal/api/dashboards/v1/grpc/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package grpc

import (
"context"
"errors"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -15,12 +14,6 @@ import (
)

func TestCreate(t *testing.T) {
userName := "unnamed"
var profileID int64 = 1
dashboardUUID := "064dc707-02b8-7000-8201-02a7f396738a"
dashboardName := "my_dashboard"
dashboardMeta := "my_meta"

type mockArgs struct {
req types.CreateDashboardRequest
resp string
Expand All @@ -35,82 +28,56 @@ func TestCreate(t *testing.T) {
wantCode codes.Code

mockArgs *mockArgs
noUser bool
}{
{
name: "success",
name: "ok",
req: &dashboards.CreateRequest{
Name: dashboardName,
Meta: dashboardMeta,
Name: testDashboardName,
Meta: testDashboardMeta,
},
want: &dashboards.CreateResponse{
Uuid: dashboardUUID,
Uuid: testDashboardUUID,
},
wantCode: codes.OK,
mockArgs: &mockArgs{
req: types.CreateDashboardRequest{
ProfileID: profileID,
Name: dashboardName,
Meta: dashboardMeta,
Name: testDashboardName,
Meta: testDashboardMeta,
},
resp: dashboardUUID,
},
},
{
name: "err_no_user",
wantCode: codes.Unauthenticated,
noUser: true,
},
{
name: "err_svc_empty_name",
req: &dashboards.CreateRequest{
Meta: dashboardMeta,
resp: testDashboardUUID,
},
wantCode: codes.InvalidArgument,
},
{
name: "err_svc_empty_meta",
name: "err_svc",
req: &dashboards.CreateRequest{
Name: dashboardName,
},
wantCode: codes.InvalidArgument,
},
{
name: "err_repo_random",
req: &dashboards.CreateRequest{
Name: dashboardName,
Meta: dashboardMeta,
Name: testDashboardName,
Meta: testDashboardMeta,
},
wantCode: codes.Internal,
mockArgs: &mockArgs{
req: types.CreateDashboardRequest{
ProfileID: profileID,
Name: dashboardName,
Meta: dashboardMeta,
Name: testDashboardName,
Meta: testDashboardMeta,
},
err: errors.New("random repo err"),
err: errSomethingWrong,
},
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

api, mockedRepo := newTestData(t)
api, mockedSvc := setupTestAPI(t)

if tt.mockArgs != nil {
mockedRepo.EXPECT().Create(gomock.Any(), tt.mockArgs.req).
Return(tt.mockArgs.resp, tt.mockArgs.err).Times(1)
}

ctx := context.Background()
if !tt.noUser {
ctx = context.WithValue(ctx, types.UserKey{}, userName)
api.profiles.SetID(userName, profileID)
mockedSvc.EXPECT().
CreateDashboard(gomock.Any(), tt.mockArgs.req).
Return(tt.mockArgs.resp, tt.mockArgs.err).
Times(1)
}

got, err := api.Create(ctx, tt.req)
got, err := api.Create(context.Background(), tt.req)

require.Equal(t, tt.wantCode, status.Code(err))
if tt.wantCode != codes.OK {
Expand Down
11 changes: 3 additions & 8 deletions internal/api/dashboards/v1/grpc/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ func (a *API) Delete(ctx context.Context, req *dashboards.DeleteRequest) (*dashb
},
)

profileID, err := a.profiles.GeIDFromContext(ctx)
if err != nil {
return nil, grpcutil.ProcessError(err)
}

request := types.DeleteDashboardRequest{
UUID: req.Uuid,
ProfileID: profileID,
UUID: req.Uuid,
}
if err = a.service.DeleteDashboard(ctx, request); err != nil {

if err := a.service.DeleteDashboard(ctx, request); err != nil {
return nil, grpcutil.ProcessError(err)
}

Expand Down
Loading
Loading