Skip to content

Commit ecf2afd

Browse files
authored
Add new awsebsnvmereceiver (#1603)
1 parent 717eb2b commit ecf2afd

31 files changed

+3611
-0
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ require (
181181
go.opentelemetry.io/collector/exporter/nopexporter v0.115.0
182182
go.opentelemetry.io/collector/extension v0.115.0
183183
go.opentelemetry.io/collector/extension/zpagesextension v0.115.0
184+
go.opentelemetry.io/collector/filter v0.115.0
184185
go.opentelemetry.io/collector/otelcol v0.115.0
185186
go.opentelemetry.io/collector/processor v0.115.0
186187
go.opentelemetry.io/collector/processor/batchprocessor v0.115.0
@@ -224,6 +225,7 @@ require (
224225
go.opentelemetry.io/collector/processor/processortest v0.115.0
225226
go.opentelemetry.io/collector/receiver/receivertest v0.115.0
226227
go.opentelemetry.io/collector/scraper v0.115.0
228+
go.uber.org/goleak v1.3.0
227229
)
228230

229231
require (

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,8 @@ go.opentelemetry.io/collector/extension/zpagesextension v0.115.0 h1:zYrZZocc7n0Z
16811681
go.opentelemetry.io/collector/extension/zpagesextension v0.115.0/go.mod h1:OaXwNHF3MAcInBzCXrhXbTNHfIi9b7YGhXjtCFZqxNY=
16821682
go.opentelemetry.io/collector/featuregate v1.22.0 h1:1TUcdqA5VpEsX1Lrr6GG15CptZxDXxiu5AXgwpeNSR4=
16831683
go.opentelemetry.io/collector/featuregate v1.22.0/go.mod h1:3GaXqflNDVwWndNGBJ1+XJFy3Fv/XrFgjMN60N3z7yg=
1684+
go.opentelemetry.io/collector/filter v0.115.0 h1:pYnHUFDSHSjEIFZit+CU09itVkDXgV+WcV2HOkjvQcE=
1685+
go.opentelemetry.io/collector/filter v0.115.0/go.mod h1:aewQ+jmvpH88gPVWpNXiWSm+wwJVxTK4f23ex2NMd2c=
16841686
go.opentelemetry.io/collector/internal/fanoutconsumer v0.115.0 h1:6DRiSECeApFq6Jj5ug77rG53R6FzJEZBfygkyMEXdpg=
16851687
go.opentelemetry.io/collector/internal/fanoutconsumer v0.115.0/go.mod h1:vgQf5HQdmLQqpDHpDq2S3nTRoUuKtRcZpRTsy+UiwYw=
16861688
go.opentelemetry.io/collector/internal/memorylimiter v0.115.0 h1:U07IJxyHZXM6eLn8cOq/Lycx6DhQZhpDOuYtIRw/d6I=

receiver/awsebsnvmereceiver/config.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package awsebsnvmereceiver
5+
6+
import (
7+
"go.opentelemetry.io/collector/component"
8+
"go.opentelemetry.io/collector/receiver/scraperhelper"
9+
10+
"github.com/aws/amazon-cloudwatch-agent/receiver/awsebsnvmereceiver/internal/metadata"
11+
)
12+
13+
type Config struct {
14+
scraperhelper.ControllerConfig `mapstructure:",squash"`
15+
metadata.MetricsBuilderConfig `mapstructure:",squash"`
16+
Devices []string `mapstructure:"devices,omitempty"`
17+
}
18+
19+
var _ component.Config = (*Config)(nil)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package awsebsnvmereceiver
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestConfigValidate(t *testing.T) {
14+
c := Config{}
15+
err := c.Validate()
16+
require.NotNil(t, err)
17+
}
18+
19+
func TestConfigWithDevices(t *testing.T) {
20+
testCases := []struct {
21+
name string
22+
devices []string
23+
}{
24+
{
25+
name: "empty devices",
26+
devices: []string{},
27+
},
28+
{
29+
name: "single device",
30+
devices: []string{"nvme0n1"},
31+
},
32+
{
33+
name: "multiple devices",
34+
devices: []string{"nvme0n1", "nvme1n1"},
35+
},
36+
{
37+
name: "wildcard",
38+
devices: []string{"*"},
39+
},
40+
}
41+
42+
for _, tc := range testCases {
43+
t.Run(tc.name, func(t *testing.T) {
44+
cfg := createDefaultConfig().(*Config)
45+
cfg.Devices = tc.devices
46+
47+
// Just verify we can set the devices field
48+
assert.Equal(t, tc.devices, cfg.Devices)
49+
})
50+
}
51+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)
2+
3+
# awsebsnvmereceiver
4+
5+
## Default Metrics
6+
7+
The following metrics are emitted by default. Each of them can be disabled by applying the following configuration:
8+
9+
```yaml
10+
metrics:
11+
<metric_name>:
12+
enabled: false
13+
```
14+
15+
### diskio_ebs_total_read_ops
16+
17+
The total number of completed read operations
18+
19+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
20+
| ---- | ----------- | ---------- | ----------------------- | --------- |
21+
| 1 | Sum | Int | Cumulative | true |
22+
23+
## Optional Metrics
24+
25+
The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration:
26+
27+
```yaml
28+
metrics:
29+
<metric_name>:
30+
enabled: true
31+
```
32+
33+
### diskio_ebs_ec2_instance_performance_exceeded_iops
34+
35+
The total time, in microseconds, that the EBS volume exceeded the attached Amazon EC2 instance's maximum IOPS performance
36+
37+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
38+
| ---- | ----------- | ---------- | ----------------------- | --------- |
39+
| us | Sum | Int | Cumulative | true |
40+
41+
### diskio_ebs_ec2_instance_performance_exceeded_tp
42+
43+
The total time, in microseconds, that the EBS volume exceeded the attached Amazon EC2 instance's maximum throughput performance
44+
45+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
46+
| ---- | ----------- | ---------- | ----------------------- | --------- |
47+
| us | Sum | Int | Cumulative | true |
48+
49+
### diskio_ebs_total_read_bytes
50+
51+
The total number of read bytes transferred
52+
53+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
54+
| ---- | ----------- | ---------- | ----------------------- | --------- |
55+
| By | Sum | Int | Cumulative | true |
56+
57+
### diskio_ebs_total_read_time
58+
59+
The total time spent, in microseconds, by all completed read operations
60+
61+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
62+
| ---- | ----------- | ---------- | ----------------------- | --------- |
63+
| us | Sum | Int | Cumulative | true |
64+
65+
### diskio_ebs_total_write_bytes
66+
67+
The total number of write bytes transferred
68+
69+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
70+
| ---- | ----------- | ---------- | ----------------------- | --------- |
71+
| By | Sum | Int | Cumulative | true |
72+
73+
### diskio_ebs_total_write_ops
74+
75+
The total number of completed write operations
76+
77+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
78+
| ---- | ----------- | ---------- | ----------------------- | --------- |
79+
| 1 | Sum | Int | Cumulative | true |
80+
81+
### diskio_ebs_total_write_time
82+
83+
The total time spent, in microseconds, by all completed write operations
84+
85+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
86+
| ---- | ----------- | ---------- | ----------------------- | --------- |
87+
| us | Sum | Int | Cumulative | true |
88+
89+
### diskio_ebs_volume_performance_exceeded_iops
90+
91+
The total time, in microseconds, that IOPS demand exceeded the volume's provisioned IOPS performance
92+
93+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
94+
| ---- | ----------- | ---------- | ----------------------- | --------- |
95+
| us | Sum | Int | Cumulative | true |
96+
97+
### diskio_ebs_volume_performance_exceeded_tp
98+
99+
The total time, in microseconds, that throughput demand exceeded the volume's provisioned throughput performance
100+
101+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
102+
| ---- | ----------- | ---------- | ----------------------- | --------- |
103+
| us | Sum | Int | Cumulative | true |
104+
105+
### diskio_ebs_volume_queue_length
106+
107+
The number of read and write operations waiting to be completed
108+
109+
| Unit | Metric Type | Value Type |
110+
| ---- | ----------- | ---------- |
111+
| 1 | Gauge | Int |
112+
113+
## Resource Attributes
114+
115+
| Name | Description | Values | Enabled |
116+
| ---- | ----------- | ------ | ------- |
117+
| VolumeId | Unique identifier to the EBS volume | Any Str | true |
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package awsebsnvmereceiver
5+
6+
import (
7+
"context"
8+
9+
"go.opentelemetry.io/collector/component"
10+
"go.opentelemetry.io/collector/consumer"
11+
"go.opentelemetry.io/collector/receiver"
12+
"go.opentelemetry.io/collector/receiver/scraperhelper"
13+
otelscraper "go.opentelemetry.io/collector/scraper"
14+
15+
"github.com/aws/amazon-cloudwatch-agent/internal/util/collections"
16+
"github.com/aws/amazon-cloudwatch-agent/receiver/awsebsnvmereceiver/internal/metadata"
17+
"github.com/aws/amazon-cloudwatch-agent/receiver/awsebsnvmereceiver/internal/nvme"
18+
)
19+
20+
func NewFactory() receiver.Factory {
21+
return receiver.NewFactory(metadata.Type,
22+
createDefaultConfig,
23+
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
24+
}
25+
26+
func createDefaultConfig() component.Config {
27+
return &Config{
28+
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
29+
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
30+
Devices: []string{},
31+
}
32+
}
33+
34+
func createMetricsReceiver(
35+
_ context.Context,
36+
settings receiver.Settings,
37+
baseCfg component.Config,
38+
consumer consumer.Metrics,
39+
) (receiver.Metrics, error) {
40+
cfg := baseCfg.(*Config)
41+
nvmeScraper := newScraper(cfg, settings, &nvme.Util{}, collections.NewSet[string](cfg.Devices...))
42+
scraper, err := otelscraper.NewMetrics(nvmeScraper.scrape, otelscraper.WithStart(nvmeScraper.start), otelscraper.WithShutdown(nvmeScraper.shutdown))
43+
if err != nil {
44+
return nil, err
45+
}
46+
47+
return scraperhelper.NewScraperControllerReceiver(
48+
&cfg.ControllerConfig, settings, consumer,
49+
scraperhelper.AddScraper(metadata.Type, scraper),
50+
)
51+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package awsebsnvmereceiver
5+
6+
import (
7+
"context"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
"go.opentelemetry.io/collector/consumer/consumertest"
13+
"go.opentelemetry.io/collector/receiver/receivertest"
14+
)
15+
16+
func TestCreateDefaultConfig(t *testing.T) {
17+
config := createDefaultConfig().(*Config)
18+
assert.NotNil(t, config)
19+
assert.Empty(t, config.Devices)
20+
}
21+
22+
func TestCreateMetricsReceiver(t *testing.T) {
23+
testCases := []struct {
24+
name string
25+
devices []string
26+
}{
27+
{
28+
name: "no devices",
29+
devices: []string{},
30+
},
31+
{
32+
name: "with devices",
33+
devices: []string{"nvme0n1", "nvme1n1"},
34+
},
35+
{
36+
name: "with wildcard",
37+
devices: []string{"*"},
38+
},
39+
}
40+
41+
for _, tc := range testCases {
42+
t.Run(tc.name, func(t *testing.T) {
43+
cfg := createDefaultConfig().(*Config)
44+
cfg.Devices = tc.devices
45+
46+
receiver, err := createMetricsReceiver(
47+
context.Background(),
48+
receivertest.NewNopSettings(),
49+
cfg,
50+
consumertest.NewNop(),
51+
)
52+
53+
require.NoError(t, err)
54+
require.NotNil(t, receiver)
55+
})
56+
}
57+
}

receiver/awsebsnvmereceiver/generated_component_test.go

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)