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

feat: log malformed data during upsert ES docs #70

Merged
merged 1 commit into from
Jan 4, 2024
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
5 changes: 5 additions & 0 deletions internal/workermanager/discovery_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/goto/compass/core/asset"
Expand Down Expand Up @@ -108,6 +109,10 @@ func (m *Manager) SyncAssets(ctx context.Context, job worker.JobSpec) error {

for _, ast := range assets {
if err := m.discoveryRepo.Upsert(ctx, ast); err != nil {
if strings.Contains(err.Error(), "illegal_argument_exception") {
m.logger.Error(err.Error())
haveiss marked this conversation as resolved.
Show resolved Hide resolved
continue
}
return err
}
}
Expand Down
8 changes: 8 additions & 0 deletions internal/workermanager/in_situ_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ package workermanager
import (
"context"
"fmt"
"strings"
"sync"

"github.com/goto/compass/core/asset"
"github.com/goto/salt/log"
)

type InSituWorker struct {
discoveryRepo DiscoveryRepository
assetRepo asset.Repository
mutex sync.Mutex
logger log.Logger
}

func NewInSituWorker(deps Deps) *InSituWorker {
return &InSituWorker{
discoveryRepo: deps.DiscoveryRepo,
assetRepo: deps.AssetRepo,
logger: deps.Logger,
}
}

Expand Down Expand Up @@ -61,6 +65,10 @@ func (m *InSituWorker) EnqueueSyncAssetJob(ctx context.Context, service string)

for _, ast := range assets {
if err := m.discoveryRepo.Upsert(ctx, ast); err != nil {
if strings.Contains(err.Error(), "illegal_argument_exception") {
m.logger.Error(err.Error())
continue
Copy link

Choose a reason for hiding this comment

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

@batrov just trying to understand here, if we have invalid format/argument for the field, we want to ignore it and keep processing remaining assets, but if we get any other error while upserting, we will return the error, without processing remaining assets?

Copy link
Author

Choose a reason for hiding this comment

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

yes that is expected, that way the backed up index won't get deleted and we can analyze other error before retrying the sync job.

}
return err
}
}
Expand Down
Loading