Skip to content

Commit

Permalink
[CDS-305] Fix initialisation delay for metadata on ecsattributes proc…
Browse files Browse the repository at this point in the history
…essor (#253)

* added initial syncmetadata call and error on initial call

* changelog

* Update otel-agent/ecs-ec2/CHANGELOG.md

Co-authored-by: Povilas Versockas <[email protected]>

---------

Co-authored-by: Povilas Versockas <[email protected]>
  • Loading branch information
daidokoro and povilasv committed Jul 17, 2023
1 parent b1497b1 commit 6fcc408
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions otel-agent/ecs-ec2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## OpenTelemtry-Agent

### v0.0.29 / 2023-07-14
* [FIX] fixed issue with ecsattributes processor not initialising correctly

### v0.0.28 / 2023-07-05
* [UPGRADE] coralogixrepo/otel-coralogix-ecs-ec2 container version updated to 0.80.0
* [UPGRADE] added custom ecsattributes processor to the container
Expand Down
30 changes: 21 additions & 9 deletions otel-agent/ecs-ec2/ecsattributesprocessor/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ func (m *metadataHandler) syncMetadata(ctx context.Context, endpoints map[string
func (m *metadataHandler) start() error {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
m.logger.Sugar().Errorf("failed to intial docker API client: %ss", err)
m.logger.Sugar().Errorf("failed to intial docker API client: %w", err)
return err
}

// initial sync
if err := syncMetadata(context.Background(), m); err != nil {
m.logger.Sugar().Errorf("failed to sync metadata: %w", err)
return err
}

Expand All @@ -90,12 +96,18 @@ func (m *metadataHandler) start() error {
for {
select {
case <-ticker.C:
syncMetadata(ctx, m)
if err := syncMetadata(ctx, m); err != nil {
m.logger.Sugar().Errorf("failed to sync metadata: %w", err)
}

case event := <-dockerEvents:
if event.Type == events.ContainerEventType && event.Action == "create" {
m.logger.Debug("new container id detected, re-syncing metadata", zap.String("id", event.ID))
syncMetadata(ctx, m)
if !(event.Type == events.ContainerEventType && event.Action == "create") {
continue
}

m.logger.Debug("new container id detected, re-syncing metadata", zap.String("id", event.ID))
if err := syncMetadata(ctx, m); err != nil {
m.logger.Sugar().Errorf("failed to sync metadata: %w", err)
}

case err := <-errors:
Expand Down Expand Up @@ -168,19 +180,19 @@ func getEndpoints(ctx context.Context) (map[string][]string, error) {
return m, nil
}

func syncMetadata(ctx context.Context, m *metadataHandler) {
func syncMetadata(ctx context.Context, m *metadataHandler) error {
endpoints, err := m.endpoints(ctx)
if err != nil {
m.logger.Sugar().Errorf("failed to fetch metadata endpoints: %w", err)
return
return fmt.Errorf("failed to fetch metadata endpoints: %w", err)
}

m.Lock()
m.logger.Debug("updating endpoints", zap.String("processor", metadata.Type))
if err := m.syncMetadata(ctx, endpoints); err != nil {
m.logger.Sugar().Errorf("%s failed to update metadata endpoints: %w", metadata.Type, err)
return fmt.Errorf("%s failed to update metadata endpoints: %w", metadata.Type, err)
}

m.Unlock()
m.logger.Debug("number of containers with detected metadata endpoints", zap.Int("count", len(endpoints)))
return nil
}

0 comments on commit 6fcc408

Please sign in to comment.