Skip to content

Commit

Permalink
added shutdownFn and update startFn
Browse files Browse the repository at this point in the history
  • Loading branch information
daidokoro committed Jul 12, 2023
1 parent e099935 commit 42bb956
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions otel-agent/ecs-ec2/ecsattributesprocessor/ecsattributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

// global variable used to store metadata endpoints within package
var ecsMetadataHandler metadataHandler
var idReg = regexp.MustCompile(`^[a-z0-9]+`)

func processLogsFunc(logger *zap.Logger, c *Config) processorhelper.ProcessLogsFunc {
return func(ctx context.Context, ld plog.Logs) (plog.Logs, error) {
Expand Down Expand Up @@ -60,22 +61,28 @@ func getContainerId(rlog *plog.ResourceLogs, sources ...string) (id string) {
}

// strip any unneeed values for eg. file extension
id = regexp.MustCompile(`^[a-z0-9]+`).
FindString(id)

id = idReg.FindString(id)
return
}

func startFn(logger *zap.Logger) func(ctx context.Context, host component.Host) error {
return func(ctx context.Context, host component.Host) error {
func startFn(logger *zap.Logger) component.StartFunc {
return func(ctx context.Context, _ component.Host) error {
ecsMetadataHandler = metadataHandler{
metadata: make(map[string]Metadata),
logger: logger,
endpoints: getEndpoints,
stop: make(chan struct{}, 1),
}

ecsMetadataHandler.start()
logger.Info("started")
logger.Info("starting")
return ecsMetadataHandler.start()
}
}

func shutdownFn() component.ShutdownFunc {
return func(ctx context.Context) error {
ecsMetadataHandler.shutdown()
ecsMetadataHandler.logger.Info("shutdown")
return nil
}
}

0 comments on commit 42bb956

Please sign in to comment.