-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[processor/resourcedetection] support openstack nova into resourcedetection processor #41973
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
082ab3a
[processor/resourcedetection] support openstack nova into resourcedet…
paulojmdias 03acea6
feat: add host.type, cloud.account.id and cloud.availability_zone
paulojmdias 6cd2848
fix: remove cloud.region
paulojmdias 713435d
Merge branch 'main' into feat/39117
paulojmdias adc030a
feat: add documentation and tests
paulojmdias a109fba
fix: fix tests and remove unneded skips
paulojmdias 1962082
Merge branch 'main' into feat/39117
paulojmdias dae81ab
Merge branch 'main' into feat/39117
paulojmdias dec3260
fix: fix test replacing context.Background() by t.Context()
paulojmdias cce6256
fix: missing test replacing context.Background() by t.Context()
paulojmdias ea6bd63
Merge branch 'main' into feat/39117
paulojmdias 2a5c379
Merge branch 'main' into feat/39117
paulojmdias 264ece5
Merge branch 'main' into feat/39117
paulojmdias 1d455c2
Merge branch 'main' into feat/39117
paulojmdias e466824
Merge branch 'main' into feat/39117
paulojmdias 41f2908
Merge branch 'main' of github.com:paulojmdias/opentelemetry-collector…
paulojmdias 21d4b4c
Merge branch 'main' of github.com:paulojmdias/opentelemetry-collector…
paulojmdias 8123a59
feat: add codeowners and labels
paulojmdias 0d8e761
Merge branch 'main' into feat/39117
paulojmdias 84eda3b
Merge branch 'main' of github.com:paulojmdias/opentelemetry-collector…
paulojmdias 25b6d53
chore: fix codeowners
paulojmdias 49c46bc
chore: revert comments
paulojmdias 7f4acd7
chore: make genlabels gencodeowners
paulojmdias fa6bd79
chore: make genlabels
paulojmdias 0d88067
Merge branch 'main' into feat/39117
atoulme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: enhancement | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
| component: resourcedetection | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: "Add Openstack Nova resource detector to gather Openstack instance metadata as resource attributes" | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [39117] | ||
|
|
||
| # (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: The Openstack Nova resource detector has been added to gather metadata such as host name, ID, cloud provider, region, and availability zone as resource attributes, enhancing the observability of Openstack environments. | ||
|
|
||
| # 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: ["user"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package nova // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders/openstack/nova" | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "time" | ||
| ) | ||
|
|
||
| const ( | ||
| openstackMetaURL = "http://169.254.169.254/openstack/latest/meta_data.json" | ||
| ec2MetaBaseURL = "http://169.254.169.254/latest/meta-data/" | ||
| ) | ||
|
|
||
| type Provider interface { | ||
| Get(ctx context.Context) (Document, error) | ||
| Hostname(ctx context.Context) (string, error) | ||
| InstanceID(ctx context.Context) (string, error) | ||
| InstanceType(ctx context.Context) (string, error) | ||
| } | ||
|
|
||
| type metadataClient struct { | ||
| client *http.Client | ||
| } | ||
|
|
||
| var _ Provider = (*metadataClient)(nil) | ||
|
|
||
| // Document is a minimal representation of OpenStack's meta_data.json | ||
| type Document struct { | ||
| AvailabilityZone string `json:"availability_zone"` | ||
| Hostname string `json:"hostname"` | ||
| Name string `json:"name"` | ||
| Meta map[string]string `json:"meta"` | ||
| ProjectID string `json:"project_id"` | ||
| UUID string `json:"uuid"` | ||
| } | ||
|
|
||
| // NewProvider returns a new Nova metadata provider with a short timeout. | ||
| func NewProvider() Provider { | ||
| return &metadataClient{ | ||
| client: &http.Client{ | ||
| Timeout: 2 * time.Second, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (c *metadataClient) getMetadata(ctx context.Context) (Document, error) { | ||
| req, err := http.NewRequestWithContext(ctx, http.MethodGet, openstackMetaURL, http.NoBody) | ||
| if err != nil { | ||
| return Document{}, err | ||
| } | ||
|
|
||
| resp, err := c.client.Do(req) | ||
| if err != nil { | ||
| return Document{}, fmt.Errorf("failed to query nova metadata service: %w", err) | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| if resp.StatusCode != http.StatusOK { | ||
| body, _ := io.ReadAll(resp.Body) | ||
| return Document{}, fmt.Errorf("metadata service returned %d: %s", resp.StatusCode, string(body)) | ||
| } | ||
|
|
||
| var doc Document | ||
| if err := json.NewDecoder(resp.Body).Decode(&doc); err != nil { | ||
| return Document{}, fmt.Errorf("failed to decode nova metadata: %w", err) | ||
| } | ||
|
|
||
| return doc, nil | ||
| } | ||
|
|
||
| func (c *metadataClient) getEc2Metadata(ctx context.Context, fullURL string) (string, error) { | ||
| req, err := http.NewRequestWithContext(ctx, http.MethodGet, fullURL, http.NoBody) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| resp, err := c.client.Do(req) | ||
| if err != nil { | ||
| return "", fmt.Errorf("metadata GET %s: %w", fullURL, err) | ||
| } | ||
| defer resp.Body.Close() | ||
| if resp.StatusCode != http.StatusOK { | ||
| b, _ := io.ReadAll(resp.Body) | ||
| return "", fmt.Errorf("metadata %s returned %d: %s", fullURL, resp.StatusCode, string(b)) | ||
| } | ||
| b, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return string(b), nil | ||
| } | ||
|
|
||
| func (c *metadataClient) InstanceID(ctx context.Context) (string, error) { | ||
| doc, err := c.getMetadata(ctx) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if doc.UUID == "" { | ||
| return "", errors.New("instance ID (uuid) not found in metadata") | ||
| } | ||
| return doc.UUID, nil | ||
| } | ||
|
|
||
| func (c *metadataClient) Hostname(ctx context.Context) (string, error) { | ||
| doc, err := c.getMetadata(ctx) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if doc.Hostname == "" { | ||
| return "", errors.New("hostname not found in metadata") | ||
| } | ||
| return doc.Hostname, nil | ||
| } | ||
|
|
||
| func (c *metadataClient) InstanceType(ctx context.Context) (string, error) { | ||
| return c.getEc2Metadata(ctx, ec2MetaBaseURL+"instance-type") | ||
| } | ||
|
|
||
| func (c *metadataClient) Get(ctx context.Context) (Document, error) { | ||
| return c.getMetadata(ctx) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.