Skip to content
Merged
Show file tree
Hide file tree
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 Aug 13, 2025
03acea6
feat: add host.type, cloud.account.id and cloud.availability_zone
paulojmdias Aug 13, 2025
6cd2848
fix: remove cloud.region
paulojmdias Aug 13, 2025
713435d
Merge branch 'main' into feat/39117
paulojmdias Aug 13, 2025
adc030a
feat: add documentation and tests
paulojmdias Aug 13, 2025
a109fba
fix: fix tests and remove unneded skips
paulojmdias Aug 14, 2025
1962082
Merge branch 'main' into feat/39117
paulojmdias Aug 14, 2025
dae81ab
Merge branch 'main' into feat/39117
paulojmdias Aug 14, 2025
dec3260
fix: fix test replacing context.Background() by t.Context()
paulojmdias Aug 14, 2025
cce6256
fix: missing test replacing context.Background() by t.Context()
paulojmdias Aug 14, 2025
ea6bd63
Merge branch 'main' into feat/39117
paulojmdias Aug 14, 2025
2a5c379
Merge branch 'main' into feat/39117
paulojmdias Aug 14, 2025
264ece5
Merge branch 'main' into feat/39117
paulojmdias Aug 16, 2025
1d455c2
Merge branch 'main' into feat/39117
paulojmdias Aug 18, 2025
e466824
Merge branch 'main' into feat/39117
paulojmdias Aug 18, 2025
41f2908
Merge branch 'main' of github.com:paulojmdias/opentelemetry-collector…
paulojmdias Sep 8, 2025
21d4b4c
Merge branch 'main' of github.com:paulojmdias/opentelemetry-collector…
paulojmdias Sep 8, 2025
8123a59
feat: add codeowners and labels
paulojmdias Sep 8, 2025
0d8e761
Merge branch 'main' into feat/39117
paulojmdias Sep 8, 2025
84eda3b
Merge branch 'main' of github.com:paulojmdias/opentelemetry-collector…
paulojmdias Sep 29, 2025
25b6d53
chore: fix codeowners
paulojmdias Sep 29, 2025
49c46bc
chore: revert comments
paulojmdias Sep 29, 2025
7f4acd7
chore: make genlabels gencodeowners
paulojmdias Sep 29, 2025
fa6bd79
chore: make genlabels
paulojmdias Sep 29, 2025
0d88067
Merge branch 'main' into feat/39117
atoulme Oct 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/feat_39117.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: 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"]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ processor/resourcedetectionprocessor/internal/akamai/ @open-telemetry
processor/resourcedetectionprocessor/internal/digitalocean/ @open-telemetry/collector-contrib-approvers @dashpole @paulojmdias
processor/resourcedetectionprocessor/internal/dynatrace/ @open-telemetry/collector-contrib-approvers @bacherfl @evan-bradley
processor/resourcedetectionprocessor/internal/hetzner/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @dashpole @paulojmdias
processor/resourcedetectionprocessor/internal/openstack/nova/ @open-telemetry/collector-contrib-approvers @dashpole @paulojmdias
processor/resourcedetectionprocessor/internal/oraclecloud/ @open-telemetry/collector-contrib-approvers @dashpole
processor/resourcedetectionprocessor/internal/scaleway/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @dashpole @paulojmdias
processor/resourcedetectionprocessor/internal/vultr/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @dashpole @paulojmdias
Expand Down
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/beta_stability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ body:
label: Component
description: Which component does your request concern?
options:
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
- cmd/codecovgen
- cmd/golden
- cmd/opampsupervisor
Expand Down Expand Up @@ -210,6 +210,7 @@ body:
- processor/resourcedetection/internal/digitalocean
- processor/resourcedetection/internal/dynatrace
- processor/resourcedetection/internal/hetzner
- processor/resourcedetection/internal/openstack/nova
- processor/resourcedetection/internal/oraclecloud
- processor/resourcedetection/internal/scaleway
- processor/resourcedetection/internal/vultr
Expand Down
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ body:
description: Which component(s) does your bug report concern?
multiple: true
options:
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
- cmd/codecovgen
- cmd/golden
- cmd/opampsupervisor
Expand Down Expand Up @@ -213,6 +213,7 @@ body:
- processor/resourcedetection/internal/digitalocean
- processor/resourcedetection/internal/dynatrace
- processor/resourcedetection/internal/hetzner
- processor/resourcedetection/internal/openstack/nova
- processor/resourcedetection/internal/oraclecloud
- processor/resourcedetection/internal/scaleway
- processor/resourcedetection/internal/vultr
Expand Down
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ body:
description: Which component(s) does your feature request concern?
multiple: true
options:
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
- cmd/codecovgen
- cmd/golden
- cmd/opampsupervisor
Expand Down Expand Up @@ -207,6 +207,7 @@ body:
- processor/resourcedetection/internal/digitalocean
- processor/resourcedetection/internal/dynatrace
- processor/resourcedetection/internal/hetzner
- processor/resourcedetection/internal/openstack/nova
- processor/resourcedetection/internal/oraclecloud
- processor/resourcedetection/internal/scaleway
- processor/resourcedetection/internal/vultr
Expand Down
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ body:
description: Which component(s) does your issue concern?
multiple: true
options:
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
- cmd/codecovgen
- cmd/golden
- cmd/opampsupervisor
Expand Down Expand Up @@ -207,6 +207,7 @@ body:
- processor/resourcedetection/internal/digitalocean
- processor/resourcedetection/internal/dynatrace
- processor/resourcedetection/internal/hetzner
- processor/resourcedetection/internal/openstack/nova
- processor/resourcedetection/internal/oraclecloud
- processor/resourcedetection/internal/scaleway
- processor/resourcedetection/internal/vultr
Expand Down
13 changes: 7 additions & 6 deletions .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ body:
description: Which component is no longer maintained?
multiple: true
options:
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
# NOTE: The list below is autogenerated using `make generate-gh-issue-templates`
# Do not manually edit it.
# Start components list
- cmd/codecovgen
- cmd/golden
- cmd/opampsupervisor
Expand Down Expand Up @@ -212,6 +212,7 @@ body:
- processor/resourcedetection/internal/digitalocean
- processor/resourcedetection/internal/dynatrace
- processor/resourcedetection/internal/hetzner
- processor/resourcedetection/internal/openstack/nova
- processor/resourcedetection/internal/oraclecloud
- processor/resourcedetection/internal/scaleway
- processor/resourcedetection/internal/vultr
Expand Down Expand Up @@ -346,7 +347,7 @@ body:
- type: textarea
attributes:
label: Details
description: Please provide details
description: Please provide details
value: |
Code owners for this component have explicitly stated they will no longer maintain the code
or have been unresponsive to issues/pull requests.
Expand All @@ -357,9 +358,9 @@ body:
- [ ] On <date 6 months from now>, 6 months from now, the component will be removed

https://github.com/open-telemetry/opentelemetry-collector#unmaintained

## Pull requests / Issues

- type: dropdown
attributes:
label: Tip
Expand Down
1 change: 1 addition & 0 deletions .github/component_labels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ processor/resourcedetectionprocessor/internal/akamai processor/resourcedetection
processor/resourcedetectionprocessor/internal/digitalocean processor/resourcedetection/internal/digitalocean
processor/resourcedetectionprocessor/internal/dynatrace processor/resourcedetection/internal/dynatrace
processor/resourcedetectionprocessor/internal/hetzner processor/resourcedetection/internal/hetzner
processor/resourcedetectionprocessor/internal/openstack/nova processor/resourcedetection/internal/openstack/nova
processor/resourcedetectionprocessor/internal/oraclecloud processor/resourcedetection/internal/oraclecloud
processor/resourcedetectionprocessor/internal/scaleway processor/resourcedetection/internal/scaleway
processor/resourcedetectionprocessor/internal/vultr processor/resourcedetection/internal/vultr
Expand Down
127 changes: 127 additions & 0 deletions internal/metadataproviders/openstack/nova/metadata.go
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)
}
Loading
Loading