From dcc334d441ec47b4295f3918b95623d4a7bf2f2b Mon Sep 17 00:00:00 2001 From: odubajDT Date: Mon, 27 Jan 2025 16:38:04 +0100 Subject: [PATCH] working version Signed-off-by: odubajDT --- .chloggen/docker-resource-failure.yaml | 27 +++++++++ .../internal/resourcedetection.go | 58 ++----------------- 2 files changed, 31 insertions(+), 54 deletions(-) create mode 100644 .chloggen/docker-resource-failure.yaml diff --git a/.chloggen/docker-resource-failure.yaml b/.chloggen/docker-resource-failure.yaml new file mode 100644 index 0000000000000..e5390f3398b2b --- /dev/null +++ b/.chloggen/docker-resource-failure.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: processor/resourcedetection + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Introduce retry logic for failed resource detection." + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [34761] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/processor/resourcedetectionprocessor/internal/resourcedetection.go b/processor/resourcedetectionprocessor/internal/resourcedetection.go index 9e99a87a7fe3d..c8374814d5b80 100644 --- a/processor/resourcedetectionprocessor/internal/resourcedetection.go +++ b/processor/resourcedetectionprocessor/internal/resourcedetection.go @@ -108,34 +108,12 @@ func NewResourceProvider(logger *zap.Logger, timeout time.Duration, attributesTo func (p *ResourceProvider) Get(ctx context.Context, client *http.Client) (resource pcommon.Resource, schemaURL string, err error) { p.once.Do(func() { - var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(ctx, client.Timeout) - defer cancel() p.detectResource(ctx, client) }) return p.detectedResource.resource, p.detectedResource.schemaURL, p.detectedResource.err } -// func (p *ResourceProvider) Get(ctx context.Context, client *http.Client) (resource pcommon.Resource, schemaURL string, err error) { -// var cancel context.CancelFunc -// for { -// ctx, cancel = context.WithTimeout(ctx, client.Timeout) -// defer cancel() - -// err = p.detectResource(ctx) -// if err == nil { -// break -// } - -// // Handle the error (e.g., log it, wait before retrying, etc.) -// p.logger.Warn("Failed to detect resource: Retrying...", zap.Error(err)) -// time.Sleep(2 * time.Second) // Wait before retrying -// } - -// return p.detectedResource.resource, p.detectedResource.schemaURL, p.detectedResource.err -// } - func (p *ResourceProvider) detectResource(ctx context.Context, client *http.Client) { p.detectedResource = &resourceResult{} @@ -154,11 +132,12 @@ func (p *ResourceProvider) detectResource(ctx context.Context, client *http.Clie for _, detector := range p.detectors { go func(detector Detector) { for { - //ctx, _ = context.WithTimeout(ctx, client.Timeout) - r, schemaURL, err := detector.Detect(context.TODO()) + sleep := 2 * time.Second + r, schemaURL, err := detector.Detect(ctx) if err != nil { p.logger.Warn("failed to detect resource", zap.Error(err)) - time.Sleep(2 * time.Second) // Wait before retrying + time.Sleep(sleep) + sleep *= 2 } else { resultsChan <- result{r: r, schemaURL: schemaURL, err: nil} return @@ -186,35 +165,6 @@ func (p *ResourceProvider) detectResource(ctx context.Context, client *http.Clie p.detectedResource.schemaURL = mergedSchemaURL } -// func (p *ResourceProvider) detectResource(ctx context.Context) { -// p.detectedResource = &resourceResult{} - -// res := pcommon.NewResource() -// mergedSchemaURL := "" - -// p.logger.Info("began detecting resource information") - -// for _, detector := range p.detectors { -// r, schemaURL, err := detector.Detect(ctx) -// if err != nil { -// p.logger.Warn("failed to detect resource", zap.Error(err)) -// } else { -// mergedSchemaURL = MergeSchemaURL(mergedSchemaURL, schemaURL) -// MergeResource(res, r, false) -// } -// } - -// droppedAttributes := filterAttributes(res.Attributes(), p.attributesToKeep) - -// p.logger.Info("detected resource information", zap.Any("resource", res.Attributes().AsRaw())) -// if len(droppedAttributes) > 0 { -// p.logger.Info("dropped resource information", zap.Strings("resource keys", droppedAttributes)) -// } - -// p.detectedResource.resource = res -// p.detectedResource.schemaURL = mergedSchemaURL -// } - func MergeSchemaURL(currentSchemaURL string, newSchemaURL string) string { if currentSchemaURL == "" { return newSchemaURL