Skip to content

Commit

Permalink
working version
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Jan 27, 2025
1 parent 3e8cb2e commit dcc334d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 54 deletions.
27 changes: 27 additions & 0 deletions .chloggen/docker-resource-failure.yaml
Original file line number Diff line number Diff line change
@@ -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: []
58 changes: 4 additions & 54 deletions processor/resourcedetectionprocessor/internal/resourcedetection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dcc334d

Please sign in to comment.