Skip to content

Commit

Permalink
feat: add sync asset handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
batrov committed Dec 4, 2023
1 parent 455b3e6 commit e40ef69
Show file tree
Hide file tree
Showing 17 changed files with 2,185 additions and 1,550 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ help: ##@help show this help
NAME="github.com/goto/compass"
VERSION=$(shell git describe --always --tags 2>/dev/null)
COVERFILE="/tmp/compass.coverprofile"
PROTON_COMMIT := "a6b2821e8ddd1127a63d3b376f860990d58931da"
PROTON_COMMIT := "eaca9798d1c1d7b3101ec1259c7e5fb949afba28"

TOOLS_MOD_DIR = ./tools
TOOLS_DIR = $(abspath ./.tools)
Expand Down
43 changes: 43 additions & 0 deletions core/asset/mocks/worker_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions core/asset/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Service struct {
type Worker interface {
EnqueueIndexAssetJob(ctx context.Context, ast Asset) error
EnqueueDeleteAssetJob(ctx context.Context, urn string) error
EnqueueSyncAssetJob(ctx context.Context, services []string) error
Close() error
}

Expand Down Expand Up @@ -229,6 +230,22 @@ func (s *Service) SuggestAssets(ctx context.Context, cfg SearchConfig) (suggesti
return s.discoveryRepository.Suggest(ctx, cfg)
}

func (s *Service) SyncAssets(ctx context.Context, services []string) error {
// select from job queue

// bad request, job already there

// if not, insert

// recreate index logic

// validate

s.worker.EnqueueSyncAssetJob(ctx, services)

Check failure on line 244 in core/asset/service.go

View workflow job for this annotation

GitHub Actions / golangci

Error return value of `s.worker.EnqueueSyncAssetJob` is not checked (errcheck)

return nil
}

func (s *Service) instrumentAssetOp(ctx context.Context, op, id string, err error) {
identifier := "URN"
if isValidUUID(id) {
Expand Down
9 changes: 9 additions & 0 deletions internal/server/v1beta1/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type AssetService interface {
SuggestAssets(ctx context.Context, cfg asset.SearchConfig) (suggestions []string, err error)

AddProbe(ctx context.Context, assetURN string, probe *asset.Probe) error

SyncAssets(ctx context.Context, services []string) error
}

func (server *APIServer) GetAllAssets(ctx context.Context, req *compassv1beta1.GetAllAssetsRequest) (*compassv1beta1.GetAllAssetsResponse, error) {
Expand Down Expand Up @@ -344,6 +346,13 @@ func (server *APIServer) CreateAssetProbe(ctx context.Context, req *compassv1bet
}, nil
}

func (server *APIServer) SyncAssets(ctx context.Context, req *compassv1beta1.SyncAssetsRequest) (*compassv1beta1.SyncAssetsResponse, error) {

Check failure on line 350 in internal/server/v1beta1/asset.go

View workflow job for this annotation

GitHub Actions / golangci

File is not `gofumpt`-ed with `-extra` (gofumpt)
server.assetService.SyncAssets(ctx, req.GetServices())

Check failure on line 351 in internal/server/v1beta1/asset.go

View workflow job for this annotation

GitHub Actions / golangci

Error return value of `server.assetService.SyncAssets` is not checked (errcheck)

return nil, nil
}

func (server *APIServer) upsertAsset(
ctx context.Context,
ast asset.Asset,
Expand Down
54 changes: 49 additions & 5 deletions internal/server/v1beta1/mocks/asset_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions internal/server/v1beta1/mocks/discussion_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions internal/server/v1beta1/mocks/star_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions internal/server/v1beta1/mocks/tag_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions internal/server/v1beta1/mocks/tag_template_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions internal/server/v1beta1/mocks/user_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/workermanager/discovery_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ func (m *Manager) DeleteAsset(ctx context.Context, job worker.JobSpec) error {
}
return nil
}

func (m *Manager) EnqueueSyncAssetJob(ctx context.Context, services []string) error {

Check failure on line 95 in internal/workermanager/discovery_worker.go

View workflow job for this annotation

GitHub Actions / golangci

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 95 in internal/workermanager/discovery_worker.go

View workflow job for this annotation

GitHub Actions / golangci

unused-parameter: parameter 'services' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 95 in internal/workermanager/discovery_worker.go

View workflow job for this annotation

GitHub Actions / golangci

unused-receiver: method receiver 'm' is not referenced in method's body, consider removing or renaming it as _ (revive)
return nil
}
4 changes: 4 additions & 0 deletions internal/workermanager/in_situ_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ func (m *InSituWorker) EnqueueDeleteAssetJob(ctx context.Context, urn string) er
return nil
}

func (m *InSituWorker) EnqueueSyncAssetJob(ctx context.Context, services []string) error {

Check failure on line 35 in internal/workermanager/in_situ_worker.go

View workflow job for this annotation

GitHub Actions / golangci

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 35 in internal/workermanager/in_situ_worker.go

View workflow job for this annotation

GitHub Actions / golangci

unused-parameter: parameter 'services' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 35 in internal/workermanager/in_situ_worker.go

View workflow job for this annotation

GitHub Actions / golangci

unused-receiver: method receiver 'm' is not referenced in method's body, consider removing or renaming it as _ (revive)
return nil
}

func (*InSituWorker) Close() error { return nil }
48 changes: 48 additions & 0 deletions proto/compass.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,44 @@ paths:
type: string
tags:
- Asset
/v1beta1/assets/sync:
post:
summary: Syncs assets in elasticsearch
description: Synchronize all assets in DB to elasticsearch
operationId: CompassService_SyncAssets
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/SyncAssetsResponse'
"400":
description: Returned when the data that user input is wrong.
schema:
$ref: '#/definitions/Status'
"404":
description: Returned when the resource does not exist.
schema:
$ref: '#/definitions/Status'
"409":
description: Returned when the resource already exist.
schema:
$ref: '#/definitions/Status'
"500":
description: Returned when theres is something wrong on the server side.
schema:
$ref: '#/definitions/Status'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/Status'
parameters:
- name: body
in: body
required: true
schema:
$ref: '#/definitions/SyncAssetsRequest'
tags:
- Asset
/v1beta1/discussions:
get:
summary: Get all discussions
Expand Down Expand Up @@ -2291,6 +2329,16 @@ definitions:
type: array
items:
type: string
SyncAssetsRequest:
type: object
properties:
services:
type: array
items:
type: string
description: filter by multiple services
SyncAssetsResponse:
type: object
TagTemplate:
type: object
properties:
Expand Down
Loading

0 comments on commit e40ef69

Please sign in to comment.