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

Update go-client - new telemetry #1330

Merged
merged 6 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions internal/pkg/mapper/scheduler/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package scheduler
import (
"context"

"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/keboola"
"github.com/keboola/go-client/pkg/request"

"github.com/keboola/keboola-as-code/internal/pkg/model"
)
Expand Down Expand Up @@ -32,7 +32,7 @@ func (m *schedulerMapper) AfterRemoteOperation(ctx context.Context, changes *mod
keboolaProjectAPI := m.KeboolaProjectAPI()

// Create requests pool
grp := client.NewRunGroup(ctx, keboolaProjectAPI.Client())
grp := request.NewRunGroup(ctx, keboolaProjectAPI.Client())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V go-client sa rozdelil client pkg na: client a request, v tomto commite je upraveny kod aby reflektoval tuto zmenu.


// Activate saved configs
for _, o := range saved {
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/mapper/scheduler/remote_activate.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package scheduler

import (
"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/request"

"github.com/keboola/keboola-as-code/internal/pkg/model"
)

// onRemoteSave activates scheduler by Scheduler API when scheduler configuration is created/updated.
func (m *schedulerMapper) onRemoteSave(grp *client.RunGroup, configState *model.ConfigState) {
func (m *schedulerMapper) onRemoteSave(grp *request.RunGroup, configState *model.ConfigState) {
grp.Add(m.KeboolaProjectAPI().ActivateScheduleRequest(configState.ID, ""))
}
4 changes: 2 additions & 2 deletions internal/pkg/mapper/scheduler/remote_deactivate.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package scheduler

import (
"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/request"

"github.com/keboola/keboola-as-code/internal/pkg/model"
)

// onRemoteDelete deactivates scheduler by Scheduler API when scheduler configuration is deleted.
func (m *schedulerMapper) onRemoteDelete(grp *client.RunGroup, configState *model.ConfigState) {
func (m *schedulerMapper) onRemoteDelete(grp *request.RunGroup, configState *model.ConfigState) {
grp.Add(m.KeboolaProjectAPI().DeleteSchedulesForConfigurationRequest(configState.ID))
}
6 changes: 3 additions & 3 deletions internal/pkg/plan/encrypt/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package encrypt
import (
"context"

"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/keboola"
"github.com/keboola/go-client/pkg/request"
"github.com/keboola/go-utils/pkg/orderedmap"

"github.com/keboola/keboola-as-code/internal/pkg/log"
Expand Down Expand Up @@ -38,7 +38,7 @@ func newExecutor(ctx context.Context, projectID keboola.ProjectID, logger log.Lo

func (e *executor) invoke() error {
// Encrypt values
wg := client.NewWaitGroup(e.ctx)
wg := request.NewWaitGroup(e.ctx)
for _, action := range e.actions {
wg.Send(e.encryptRequest(action))
}
Expand All @@ -54,7 +54,7 @@ func (e *executor) invoke() error {
return e.errors.ErrorOrNil()
}

func (e *executor) encryptRequest(action *action) client.Sendable {
func (e *executor) encryptRequest(action *action) request.Sendable {
object := action.object

// Each key for encryption, in the API call, must start with #
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/service/buffer/storage/token/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"sync"

"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/keboola"
"github.com/keboola/go-client/pkg/request"

"github.com/keboola/keboola-as-code/internal/pkg/service/buffer/store/key"
"github.com/keboola/keboola-as-code/internal/pkg/service/buffer/store/model"
Expand Down Expand Up @@ -103,7 +103,7 @@ func (m *Manager) RefreshToken(ctx context.Context, rb rollback.Builder, token *
return nil
}

func (m *Manager) createTokenRequest(exportKey key.ExportKey, permissions keboola.BucketPermissions) client.APIRequest[*keboola.Token] {
func (m *Manager) createTokenRequest(exportKey key.ExportKey, permissions keboola.BucketPermissions) request.APIRequest[*keboola.Token] {
return m.keboolaProjectAPI.
CreateTokenRequest(
keboola.WithDescription(
Expand Down
26 changes: 13 additions & 13 deletions internal/pkg/state/remote/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"sort"
"sync"

"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/keboola"
"github.com/keboola/go-client/pkg/request"
"github.com/keboola/go-utils/pkg/deepcopy"
"github.com/keboola/go-utils/pkg/orderedmap"
"github.com/spf13/cast"
Expand Down Expand Up @@ -78,7 +78,7 @@ func (u *UnitOfWork) LoadAll(filter model.ObjectsFilter) {
req := u.keboolaProjectAPI.
ListBranchesRequest().
WithOnSuccess(func(ctx context.Context, apiBranches *[]*keboola.Branch) error {
wg := client.NewWaitGroup(ctx)
wg := request.NewWaitGroup(ctx)
for _, apiBranch := range *apiBranches {
branch := model.NewBranch(apiBranch)

Expand Down Expand Up @@ -266,7 +266,7 @@ func (u *UnitOfWork) Invoke() error {
u.runGroups.SortKeys(sort.Strings)
for _, level := range u.runGroups.Keys() {
grp, _ := u.runGroups.Get(level)
if err := grp.(*client.RunGroup).RunAndWait(); err != nil {
if err := grp.(*request.RunGroup).RunAndWait(); err != nil {
u.errors.Append(err)
break
}
Expand Down Expand Up @@ -319,7 +319,7 @@ func (u *UnitOfWork) createOrUpdate(objectState model.ObjectState, object model.
}
}

func (u *UnitOfWork) createRequest(objectState model.ObjectState, object model.Object, recipe *model.RemoteSaveRecipe) client.APIRequest[keboola.Object] {
func (u *UnitOfWork) createRequest(objectState model.ObjectState, object model.Object, recipe *model.RemoteSaveRecipe) request.APIRequest[keboola.Object] {
apiObject, _ := recipe.Object.(model.ToAPIObject).ToAPIObject(u.changeDescription, nil)
request := u.keboolaProjectAPI.
CreateRequest(apiObject).
Expand Down Expand Up @@ -358,7 +358,7 @@ func (u *UnitOfWork) createRequest(objectState model.ObjectState, object model.O
return request
}

func (u *UnitOfWork) updateRequest(objectState model.ObjectState, object model.Object, recipe *model.RemoteSaveRecipe, changedFields model.ChangedFields) client.APIRequest[keboola.Object] {
func (u *UnitOfWork) updateRequest(objectState model.ObjectState, object model.Object, recipe *model.RemoteSaveRecipe, changedFields model.ChangedFields) request.APIRequest[keboola.Object] {
apiObject, apiChangedFields := recipe.Object.(model.ToAPIObject).ToAPIObject(u.changeDescription, changedFields)
return u.keboolaProjectAPI.
UpdateRequest(apiObject, apiChangedFields).
Expand All @@ -371,9 +371,9 @@ func (u *UnitOfWork) updateRequest(objectState model.ObjectState, object model.O
}

func (u *UnitOfWork) delete(objectState model.ObjectState) {
request := u.keboolaProjectAPI.
req := u.keboolaProjectAPI.
DeleteRequest(objectState.(model.ToAPIObjectKey).ToAPIObjectKey()).
WithOnSuccess(func(_ context.Context, _ client.NoResult) error {
WithOnSuccess(func(_ context.Context, _ request.NoResult) error {
u.Manifest().Delete(objectState)
objectState.SetRemoteState(nil)
u.changes.AddDeleted(objectState)
Expand All @@ -382,32 +382,32 @@ func (u *UnitOfWork) delete(objectState model.ObjectState) {

// Limit concurrency of branch operations, see u.branchesSem comment.
if objectState.Kind().IsBranch() {
request.
req.
WithBefore(func(ctx context.Context) error {
return u.branchesSem.Acquire(ctx, 1)
}).
WithOnComplete(func(_ context.Context, _ client.NoResult, err error) error {
WithOnComplete(func(_ context.Context, _ request.NoResult, err error) error {
u.branchesSem.Release(1)
return err
})
}

grp := u.runGroupFor(objectState.Level())
grp.Add(request)
grp.Add(req)
}

// runGroupFor each level (branches, configs, rows).
func (u *UnitOfWork) runGroupFor(level int) *client.RunGroup {
func (u *UnitOfWork) runGroupFor(level int) *request.RunGroup {
if u.invoked {
panic(errors.New(`invoked UnitOfWork cannot be reused`))
}

key := cast.ToString(level)
if value, found := u.runGroups.Get(key); found {
return value.(*client.RunGroup)
return value.(*request.RunGroup)
}

grp := client.NewRunGroup(u.ctx, u.keboolaProjectAPI.Client())
grp := request.NewRunGroup(u.ctx, u.keboolaProjectAPI.Client())
u.runGroups.Set(key, grp)
return grp
}
25 changes: 13 additions & 12 deletions internal/pkg/utils/testproject/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/keboola"
"github.com/keboola/go-client/pkg/request"
"github.com/keboola/go-utils/pkg/testproject"
"github.com/spf13/cast"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -254,7 +255,7 @@ func (p *Project) createBranches(branches []*fixtures.BranchState) error {
createBranchSem := semaphore.NewWeighted(1)

// Create branches
grp := client.NewWaitGroup(ctx)
grp := request.NewWaitGroup(ctx)
for _, fixture := range branches {
fixture := fixture
grp.Send(p.createBranchRequest(fixture, createBranchSem))
Expand All @@ -272,7 +273,7 @@ func (p *Project) createBucketsTables(buckets []*fixtures.Bucket) error {
defer cancelFn()

// Create buckets and tables
grp := client.NewWaitGroup(ctx)
grp := request.NewWaitGroup(ctx)
for _, b := range buckets {
req := p.keboolaProjectAPI.
CreateBucketRequest(&keboola.Bucket{
Expand Down Expand Up @@ -454,15 +455,15 @@ func (p *Project) createSandboxes(defaultBranchID keboola.BranchID, sandboxes []
return nil
}

func (p *Project) createBranchRequest(fixture *fixtures.BranchState, createBranchSem *semaphore.Weighted) client.APIRequest[*keboola.Branch] {
var request client.APIRequest[*keboola.Branch]
func (p *Project) createBranchRequest(fixture *fixtures.BranchState, createBranchSem *semaphore.Weighted) request.APIRequest[*keboola.Branch] {
var req request.APIRequest[*keboola.Branch]

// Create branch
if fixture.IsDefault {
// Reset default branch description (default branch cannot be created/deleted)
request = client.NewNoOperationAPIRequest(p.defaultBranch) // default branch already exists
req = request.NewNoOperationAPIRequest(p.defaultBranch) // default branch already exists
if p.defaultBranch.Description != fixture.Description {
request = request.WithOnSuccess(func(ctx context.Context, branch *keboola.Branch) error {
req = req.WithOnSuccess(func(ctx context.Context, branch *keboola.Branch) error {
branch.Description = fixture.Description
return p.keboolaProjectAPI.
UpdateBranchRequest(branch, []string{"description"}).
Expand All @@ -483,7 +484,7 @@ func (p *Project) createBranchRequest(fixture *fixtures.BranchState, createBranc
}
} else {
// Create a new branch
request = p.keboolaProjectAPI.
req = p.keboolaProjectAPI.
CreateBranchRequest(fixture.ToAPI()).
WithBefore(func(ctx context.Context) error {
p.logf("▶ Branch \"%s\"...", fixture.Name)
Expand All @@ -501,20 +502,20 @@ func (p *Project) createBranchRequest(fixture *fixtures.BranchState, createBranc
}

// Branch is ready
request = request.WithOnSuccess(func(ctx context.Context, branch *keboola.Branch) error {
req = req.WithOnSuccess(func(ctx context.Context, branch *keboola.Branch) error {
p.addBranch(branch)
return nil
})

// Set branch metadata
request = request.WithOnSuccess(func(ctx context.Context, branch *keboola.Branch) error {
req = req.WithOnSuccess(func(ctx context.Context, branch *keboola.Branch) error {
return p.keboolaProjectAPI.
AppendBranchMetadataRequest(branch.BranchKey, fixture.Metadata).
WithBefore(func(ctx context.Context) error {
p.logf("▶ Branch metadata \"%s\"...", fixture.Name)
return nil
}).
WithOnComplete(func(ctx context.Context, _ client.NoResult, err error) error {
WithOnComplete(func(ctx context.Context, _ request.NoResult, err error) error {
if err == nil {
p.logf("✔️ Branch metadata \"%s\".", fixture.Name)
return nil
Expand All @@ -524,7 +525,7 @@ func (p *Project) createBranchRequest(fixture *fixtures.BranchState, createBranc
}).
SendOrErr(ctx)
})
return request
return req
}

func (p *Project) createConfigsInDefaultBranch(configs []string) error {
Expand Down Expand Up @@ -651,7 +652,7 @@ func (p *Project) prepareConfigs(ctx context.Context, grp *errgroup.Group, sendR
p.logf("▶ Config metadata \"%s\"...", configDesc)
return nil
}).
WithOnSuccess(func(_ context.Context, _ client.NoResult) error {
WithOnSuccess(func(_ context.Context, _ request.NoResult) error {
p.logf("✔️️ Config metadata \"%s\".", configDesc)
return nil
}).
Expand Down
24 changes: 12 additions & 12 deletions internal/pkg/utils/testproject/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/keboola"
"github.com/keboola/go-client/pkg/request"
"golang.org/x/sync/errgroup"

"github.com/keboola/keboola-as-code/internal/pkg/fixtures"
Expand All @@ -30,10 +30,10 @@ func (p *Project) NewSnapshot() (*fixtures.ProjectSnapshot, error) {

// Branches
grp.Go(func() error {
request := p.keboolaProjectAPI.
req := p.keboolaProjectAPI.
ListBranchesRequest().
WithOnSuccess(func(ctx context.Context, apiBranches *[]*keboola.Branch) error {
wg := client.NewWaitGroup(ctx)
wg := request.NewWaitGroup(ctx)
for _, apiBranch := range *apiBranches {
apiBranch := apiBranch
branch := &fixtures.BranchWithConfigs{Branch: &fixtures.Branch{}, Configs: make([]*fixtures.Config, 0)}
Expand Down Expand Up @@ -123,38 +123,38 @@ func (p *Project) NewSnapshot() (*fixtures.ProjectSnapshot, error) {

return nil
})
return request.SendOrErr(ctx)
return req.SendOrErr(ctx)
})

// Schedules for main branch
var schedules []*keboola.Schedule
grp.Go(func() error {
request := p.keboolaProjectAPI.
req := p.keboolaProjectAPI.
ListSchedulesRequest().
WithOnSuccess(func(_ context.Context, apiSchedules *[]*keboola.Schedule) error {
schedules = append(schedules, *apiSchedules...)
return nil
})
return request.SendOrErr(ctx)
return req.SendOrErr(ctx)
})

workspacesMap := make(map[string]*keboola.Workspace)
grp.Go(func() error {
request := p.keboolaProjectAPI.
req := p.keboolaProjectAPI.
ListWorkspaceInstancesRequest().
WithOnSuccess(func(ctx context.Context, result *[]*keboola.Workspace) error {
for _, sandbox := range *result {
workspacesMap[sandbox.ID.String()] = sandbox
}
return nil
})
return request.SendOrErr(ctx)
return req.SendOrErr(ctx)
})

// Storage Buckets
bucketsMap := map[keboola.BucketID]*fixtures.Bucket{}
grp.Go(func() error {
request := p.keboolaProjectAPI.
req := p.keboolaProjectAPI.
ListBucketsRequest().
WithOnSuccess(func(_ context.Context, apiBuckets *[]*keboola.Bucket) error {
for _, b := range *apiBuckets {
Expand All @@ -168,19 +168,19 @@ func (p *Project) NewSnapshot() (*fixtures.ProjectSnapshot, error) {
}
return nil
})
return request.SendOrErr(ctx)
return req.SendOrErr(ctx)
})

// Storage Tables
var tables []*keboola.Table
grp.Go(func() error {
request := p.keboolaProjectAPI.
req := p.keboolaProjectAPI.
ListTablesRequest(keboola.WithBuckets(), keboola.WithColumns()).
WithOnSuccess(func(_ context.Context, apiTables *[]*keboola.Table) error {
tables = append(tables, *apiTables...)
return nil
})
return request.SendOrErr(ctx)
return req.SendOrErr(ctx)
})

// Storage Files
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/version/check_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/Masterminds/semver"
"github.com/keboola/go-client/pkg/client"
"github.com/keboola/go-client/pkg/request"

"github.com/keboola/keboola-as-code/internal/pkg/env"
"github.com/keboola/keboola-as-code/internal/pkg/log"
Expand Down Expand Up @@ -78,8 +79,7 @@ func (c *checker) getLatestVersion() (string, error) {
// Load releases
// The last release may be without assets (build in progress), so we load the last 5 releases.
result := make([]interface{}, 0)
_, _, err := client.
NewHTTPRequest(c.client).
_, _, err := request.NewHTTPRequest(c.client).
WithGet("repos/keboola/keboola-as-code/releases?per_page=5").
WithResult(&result).
Send(c.ctx)
Expand Down