From 71018ab14893a5c58e05ffb0410fa5da37e2b5d8 Mon Sep 17 00:00:00 2001 From: Colin Desmond Date: Thu, 17 Aug 2023 11:29:39 +0100 Subject: [PATCH 1/8] Added persistent_queue capability to Azure Monitor Exporter --- exporter/azuremonitorexporter/README.md | 5 +++++ exporter/azuremonitorexporter/config.go | 12 +++++++----- exporter/azuremonitorexporter/logexporter.go | 8 +++++++- exporter/azuremonitorexporter/metricexporter.go | 7 ++++++- exporter/azuremonitorexporter/traceexporter.go | 7 ++++++- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/exporter/azuremonitorexporter/README.md b/exporter/azuremonitorexporter/README.md index cadcb562e92c..6fd0698a4202 100644 --- a/exporter/azuremonitorexporter/README.md +++ b/exporter/azuremonitorexporter/README.md @@ -27,6 +27,11 @@ The following settings can be optionally configured: - `maxbatchsize` (default = 1024): The maximum number of telemetry items that can be submitted in each request. If this many items are buffered, the buffer will be flushed before `maxbatchinterval` expires. - `maxbatchinterval` (default = 10s): The maximum time to wait before sending a batch of telemetry. - `spaneventsenabled` (default = false): Enables export of span events. +- `sending_queue` + - `enabled` (default = false) + - `num_consumers` (default = 10): Number of consumers that dequeue batches; ignored if `enabled` is `false` + - `queue_size` (default = 1000): Maximum number of batches kept in memory before data; ignored if `enabled` is `false` + - `storage` (default = `none`): When set, enables persistence and uses the component specified as a storage extension for the persistent queue Example: diff --git a/exporter/azuremonitorexporter/config.go b/exporter/azuremonitorexporter/config.go index 6c5042954344..e473494a4b3c 100644 --- a/exporter/azuremonitorexporter/config.go +++ b/exporter/azuremonitorexporter/config.go @@ -7,13 +7,15 @@ import ( "time" "go.opentelemetry.io/collector/config/configopaque" + "go.opentelemetry.io/collector/exporter/exporterhelper" ) // Config defines configuration for Azure Monitor type Config struct { - Endpoint string `mapstructure:"endpoint"` - InstrumentationKey configopaque.String `mapstructure:"instrumentation_key"` - MaxBatchSize int `mapstructure:"maxbatchsize"` - MaxBatchInterval time.Duration `mapstructure:"maxbatchinterval"` - SpanEventsEnabled bool `mapstructure:"spaneventsenabled"` + exporterhelper.QueueSettings `mapstructure:"sending_queue"` + Endpoint string `mapstructure:"endpoint"` + InstrumentationKey configopaque.String `mapstructure:"instrumentation_key"` + MaxBatchSize int `mapstructure:"maxbatchsize"` + MaxBatchInterval time.Duration `mapstructure:"maxbatchinterval"` + SpanEventsEnabled bool `mapstructure:"spaneventsenabled"` } diff --git a/exporter/azuremonitorexporter/logexporter.go b/exporter/azuremonitorexporter/logexporter.go index c823887d3f60..901c09d595f4 100644 --- a/exporter/azuremonitorexporter/logexporter.go +++ b/exporter/azuremonitorexporter/logexporter.go @@ -47,5 +47,11 @@ func newLogsExporter(config *Config, transportChannel transportChannel, set expo logger: set.Logger, } - return exporterhelper.NewLogsExporter(context.TODO(), set, config, exporter.onLogData) + return exporterhelper.NewLogsExporter( + context.TODO(), + set, + config, + exporter.onLogData, + exporterhelper.WithQueue(config.QueueSettings), + ) } diff --git a/exporter/azuremonitorexporter/metricexporter.go b/exporter/azuremonitorexporter/metricexporter.go index bd264fad600a..94d9148ceb2c 100644 --- a/exporter/azuremonitorexporter/metricexporter.go +++ b/exporter/azuremonitorexporter/metricexporter.go @@ -49,5 +49,10 @@ func newMetricsExporter(config *Config, transportChannel transportChannel, set e packer: newMetricPacker(set.Logger), } - return exporterhelper.NewMetricsExporter(context.TODO(), set, config, exporter.onMetricData) + return exporterhelper.NewMetricsExporter( + context.TODO(), + set, + config, + exporter.onMetricData, + exporterhelper.WithQueue(config.QueueSettings)) } diff --git a/exporter/azuremonitorexporter/traceexporter.go b/exporter/azuremonitorexporter/traceexporter.go index a3dc717c3ae3..3bd3bf5a812c 100644 --- a/exporter/azuremonitorexporter/traceexporter.go +++ b/exporter/azuremonitorexporter/traceexporter.go @@ -70,5 +70,10 @@ func newTracesExporter(config *Config, transportChannel transportChannel, set ex logger: set.Logger, } - return exporterhelper.NewTracesExporter(context.TODO(), set, config, exporter.onTraceData) + return exporterhelper.NewTracesExporter( + context.TODO(), + set, + config, + exporter.onTraceData, + exporterhelper.WithQueue(config.QueueSettings)) } From f14681d5a395eb8711310b20e5dcec4085dce16e Mon Sep 17 00:00:00 2001 From: Colin Desmond Date: Thu, 17 Aug 2023 13:57:02 +0100 Subject: [PATCH 2/8] Added to config unit test to check for sending_queue --- exporter/azuremonitorexporter/config_test.go | 9 +++++++++ exporter/azuremonitorexporter/factory.go | 2 ++ exporter/azuremonitorexporter/testdata/config.yaml | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/exporter/azuremonitorexporter/config_test.go b/exporter/azuremonitorexporter/config_test.go index 0e271073e400..573a76bad8db 100644 --- a/exporter/azuremonitorexporter/config_test.go +++ b/exporter/azuremonitorexporter/config_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap/confmaptest" + "go.opentelemetry.io/collector/exporter/exporterhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter/internal/metadata" ) @@ -22,6 +23,8 @@ func TestLoadConfig(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) + disk := component.NewIDWithName("disk", "") + tests := []struct { id component.ID expected component.Config @@ -39,6 +42,12 @@ func TestLoadConfig(t *testing.T) { MaxBatchSize: 100, MaxBatchInterval: 10 * time.Second, SpanEventsEnabled: false, + QueueSettings: exporterhelper.QueueSettings{ + QueueSize: 1000, + Enabled: true, + NumConsumers: 10, + StorageID: &disk, + }, }, }, } diff --git a/exporter/azuremonitorexporter/factory.go b/exporter/azuremonitorexporter/factory.go index aee00000a27c..b81f3b29b995 100644 --- a/exporter/azuremonitorexporter/factory.go +++ b/exporter/azuremonitorexporter/factory.go @@ -13,6 +13,7 @@ import ( "github.com/microsoft/ApplicationInsights-Go/appinsights" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/exporter/exporterhelper" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter/internal/metadata" @@ -48,6 +49,7 @@ func createDefaultConfig() component.Config { MaxBatchSize: 1024, MaxBatchInterval: 10 * time.Second, SpanEventsEnabled: false, + QueueSettings: exporterhelper.NewDefaultQueueSettings(), } } diff --git a/exporter/azuremonitorexporter/testdata/config.yaml b/exporter/azuremonitorexporter/testdata/config.yaml index c182f3bd8ae2..b8b0f7b6cf02 100644 --- a/exporter/azuremonitorexporter/testdata/config.yaml +++ b/exporter/azuremonitorexporter/testdata/config.yaml @@ -8,3 +8,12 @@ azuremonitor/2: maxbatchsize: 100 # maxbatchinterval is the maximum time to wait before calling the configured endpoint. maxbatchinterval: 10s + + sending_queue: + # queue_size is the maximum number of items that can be queued before dropping data + queue_size: 1000 + enabled: true + num_consumers: 10 + storage: disk + +disk/3: \ No newline at end of file From d9f6ed08563b902f9b4cb11999e43e9e04a985bd Mon Sep 17 00:00:00 2001 From: Colin Desmond Date: Tue, 29 Aug 2023 17:44:09 +0100 Subject: [PATCH 3/8] Added change log entry --- ...xporter_azuremonitor_persistent_queue.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 .chloggen/codesmon_exporter_azuremonitor_persistent_queue.yaml diff --git a/.chloggen/codesmon_exporter_azuremonitor_persistent_queue.yaml b/.chloggen/codesmon_exporter_azuremonitor_persistent_queue.yaml new file mode 100755 index 000000000000..1063cd0b8838 --- /dev/null +++ b/.chloggen/codesmon_exporter_azuremonitor_persistent_queue.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: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: azuremonitorexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Extended Azure Monitor exporter to support persistent queue. Default is for QueueSettings.Enabled to be false. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [25859] + +# (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: [user] From 71120030ef674910d651a388f01918f7b65c7a53 Mon Sep 17 00:00:00 2001 From: Colin Desmond Date: Thu, 17 Aug 2023 11:29:39 +0100 Subject: [PATCH 4/8] Added persistent_queue capability to Azure Monitor Exporter --- exporter/azuremonitorexporter/README.md | 5 +++++ exporter/azuremonitorexporter/config.go | 12 +++++++----- exporter/azuremonitorexporter/logexporter.go | 8 +++++++- exporter/azuremonitorexporter/metricexporter.go | 7 ++++++- exporter/azuremonitorexporter/traceexporter.go | 7 ++++++- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/exporter/azuremonitorexporter/README.md b/exporter/azuremonitorexporter/README.md index cadcb562e92c..6fd0698a4202 100644 --- a/exporter/azuremonitorexporter/README.md +++ b/exporter/azuremonitorexporter/README.md @@ -27,6 +27,11 @@ The following settings can be optionally configured: - `maxbatchsize` (default = 1024): The maximum number of telemetry items that can be submitted in each request. If this many items are buffered, the buffer will be flushed before `maxbatchinterval` expires. - `maxbatchinterval` (default = 10s): The maximum time to wait before sending a batch of telemetry. - `spaneventsenabled` (default = false): Enables export of span events. +- `sending_queue` + - `enabled` (default = false) + - `num_consumers` (default = 10): Number of consumers that dequeue batches; ignored if `enabled` is `false` + - `queue_size` (default = 1000): Maximum number of batches kept in memory before data; ignored if `enabled` is `false` + - `storage` (default = `none`): When set, enables persistence and uses the component specified as a storage extension for the persistent queue Example: diff --git a/exporter/azuremonitorexporter/config.go b/exporter/azuremonitorexporter/config.go index 6c5042954344..e473494a4b3c 100644 --- a/exporter/azuremonitorexporter/config.go +++ b/exporter/azuremonitorexporter/config.go @@ -7,13 +7,15 @@ import ( "time" "go.opentelemetry.io/collector/config/configopaque" + "go.opentelemetry.io/collector/exporter/exporterhelper" ) // Config defines configuration for Azure Monitor type Config struct { - Endpoint string `mapstructure:"endpoint"` - InstrumentationKey configopaque.String `mapstructure:"instrumentation_key"` - MaxBatchSize int `mapstructure:"maxbatchsize"` - MaxBatchInterval time.Duration `mapstructure:"maxbatchinterval"` - SpanEventsEnabled bool `mapstructure:"spaneventsenabled"` + exporterhelper.QueueSettings `mapstructure:"sending_queue"` + Endpoint string `mapstructure:"endpoint"` + InstrumentationKey configopaque.String `mapstructure:"instrumentation_key"` + MaxBatchSize int `mapstructure:"maxbatchsize"` + MaxBatchInterval time.Duration `mapstructure:"maxbatchinterval"` + SpanEventsEnabled bool `mapstructure:"spaneventsenabled"` } diff --git a/exporter/azuremonitorexporter/logexporter.go b/exporter/azuremonitorexporter/logexporter.go index c823887d3f60..901c09d595f4 100644 --- a/exporter/azuremonitorexporter/logexporter.go +++ b/exporter/azuremonitorexporter/logexporter.go @@ -47,5 +47,11 @@ func newLogsExporter(config *Config, transportChannel transportChannel, set expo logger: set.Logger, } - return exporterhelper.NewLogsExporter(context.TODO(), set, config, exporter.onLogData) + return exporterhelper.NewLogsExporter( + context.TODO(), + set, + config, + exporter.onLogData, + exporterhelper.WithQueue(config.QueueSettings), + ) } diff --git a/exporter/azuremonitorexporter/metricexporter.go b/exporter/azuremonitorexporter/metricexporter.go index bd264fad600a..94d9148ceb2c 100644 --- a/exporter/azuremonitorexporter/metricexporter.go +++ b/exporter/azuremonitorexporter/metricexporter.go @@ -49,5 +49,10 @@ func newMetricsExporter(config *Config, transportChannel transportChannel, set e packer: newMetricPacker(set.Logger), } - return exporterhelper.NewMetricsExporter(context.TODO(), set, config, exporter.onMetricData) + return exporterhelper.NewMetricsExporter( + context.TODO(), + set, + config, + exporter.onMetricData, + exporterhelper.WithQueue(config.QueueSettings)) } diff --git a/exporter/azuremonitorexporter/traceexporter.go b/exporter/azuremonitorexporter/traceexporter.go index 244b5cda727a..f5f5e19c6126 100644 --- a/exporter/azuremonitorexporter/traceexporter.go +++ b/exporter/azuremonitorexporter/traceexporter.go @@ -70,5 +70,10 @@ func newTracesExporter(config *Config, transportChannel transportChannel, set ex logger: set.Logger, } - return exporterhelper.NewTracesExporter(context.TODO(), set, config, exporter.onTraceData) + return exporterhelper.NewTracesExporter( + context.TODO(), + set, + config, + exporter.onTraceData, + exporterhelper.WithQueue(config.QueueSettings)) } From 3dcfcb4e24fab1541f55b80e3435a4641b638ea8 Mon Sep 17 00:00:00 2001 From: Colin Desmond Date: Thu, 17 Aug 2023 13:57:02 +0100 Subject: [PATCH 5/8] Added to config unit test to check for sending_queue --- exporter/azuremonitorexporter/config_test.go | 9 +++++++++ exporter/azuremonitorexporter/factory.go | 2 ++ exporter/azuremonitorexporter/testdata/config.yaml | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/exporter/azuremonitorexporter/config_test.go b/exporter/azuremonitorexporter/config_test.go index 0e271073e400..573a76bad8db 100644 --- a/exporter/azuremonitorexporter/config_test.go +++ b/exporter/azuremonitorexporter/config_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap/confmaptest" + "go.opentelemetry.io/collector/exporter/exporterhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter/internal/metadata" ) @@ -22,6 +23,8 @@ func TestLoadConfig(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) + disk := component.NewIDWithName("disk", "") + tests := []struct { id component.ID expected component.Config @@ -39,6 +42,12 @@ func TestLoadConfig(t *testing.T) { MaxBatchSize: 100, MaxBatchInterval: 10 * time.Second, SpanEventsEnabled: false, + QueueSettings: exporterhelper.QueueSettings{ + QueueSize: 1000, + Enabled: true, + NumConsumers: 10, + StorageID: &disk, + }, }, }, } diff --git a/exporter/azuremonitorexporter/factory.go b/exporter/azuremonitorexporter/factory.go index aee00000a27c..b81f3b29b995 100644 --- a/exporter/azuremonitorexporter/factory.go +++ b/exporter/azuremonitorexporter/factory.go @@ -13,6 +13,7 @@ import ( "github.com/microsoft/ApplicationInsights-Go/appinsights" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/exporter/exporterhelper" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter/internal/metadata" @@ -48,6 +49,7 @@ func createDefaultConfig() component.Config { MaxBatchSize: 1024, MaxBatchInterval: 10 * time.Second, SpanEventsEnabled: false, + QueueSettings: exporterhelper.NewDefaultQueueSettings(), } } diff --git a/exporter/azuremonitorexporter/testdata/config.yaml b/exporter/azuremonitorexporter/testdata/config.yaml index c182f3bd8ae2..b8b0f7b6cf02 100644 --- a/exporter/azuremonitorexporter/testdata/config.yaml +++ b/exporter/azuremonitorexporter/testdata/config.yaml @@ -8,3 +8,12 @@ azuremonitor/2: maxbatchsize: 100 # maxbatchinterval is the maximum time to wait before calling the configured endpoint. maxbatchinterval: 10s + + sending_queue: + # queue_size is the maximum number of items that can be queued before dropping data + queue_size: 1000 + enabled: true + num_consumers: 10 + storage: disk + +disk/3: \ No newline at end of file From e003865e1c61b06d307e19133703620bd82f9742 Mon Sep 17 00:00:00 2001 From: Colin Desmond Date: Tue, 29 Aug 2023 17:44:09 +0100 Subject: [PATCH 6/8] Added change log entry --- ...xporter_azuremonitor_persistent_queue.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 .chloggen/codesmon_exporter_azuremonitor_persistent_queue.yaml diff --git a/.chloggen/codesmon_exporter_azuremonitor_persistent_queue.yaml b/.chloggen/codesmon_exporter_azuremonitor_persistent_queue.yaml new file mode 100755 index 000000000000..1063cd0b8838 --- /dev/null +++ b/.chloggen/codesmon_exporter_azuremonitor_persistent_queue.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: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: azuremonitorexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Extended Azure Monitor exporter to support persistent queue. Default is for QueueSettings.Enabled to be false. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [25859] + +# (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: [user] From cbc0d054c0ed86da88168fd7151a7d6f8544fde4 Mon Sep 17 00:00:00 2001 From: "colin.desmond" Date: Mon, 6 Nov 2023 10:29:51 +0000 Subject: [PATCH 7/8] Merge conflict --- exporter/azuremonitorexporter/config.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/exporter/azuremonitorexporter/config.go b/exporter/azuremonitorexporter/config.go index e473494a4b3c..9187187f36cc 100644 --- a/exporter/azuremonitorexporter/config.go +++ b/exporter/azuremonitorexporter/config.go @@ -13,9 +13,10 @@ import ( // Config defines configuration for Azure Monitor type Config struct { exporterhelper.QueueSettings `mapstructure:"sending_queue"` - Endpoint string `mapstructure:"endpoint"` - InstrumentationKey configopaque.String `mapstructure:"instrumentation_key"` - MaxBatchSize int `mapstructure:"maxbatchsize"` - MaxBatchInterval time.Duration `mapstructure:"maxbatchinterval"` - SpanEventsEnabled bool `mapstructure:"spaneventsenabled"` + Endpoint string `mapstructure:"endpoint"` + ConnectionString configopaque.String `mapstructure:"connection_string"` + InstrumentationKey configopaque.String `mapstructure:"instrumentation_key"` + MaxBatchSize int `mapstructure:"maxbatchsize"` + MaxBatchInterval time.Duration `mapstructure:"maxbatchinterval"` + SpanEventsEnabled bool `mapstructure:"spaneventsenabled"` } From afb58ccbcb12be154b16be95de9ee483fd765fa5 Mon Sep 17 00:00:00 2001 From: "colin.desmond" Date: Mon, 6 Nov 2023 12:19:53 +0000 Subject: [PATCH 8/8] GCI'd the code. --- exporter/azuremonitorexporter/config.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/exporter/azuremonitorexporter/config.go b/exporter/azuremonitorexporter/config.go index 9187187f36cc..a4be0f3cfcb2 100644 --- a/exporter/azuremonitorexporter/config.go +++ b/exporter/azuremonitorexporter/config.go @@ -13,10 +13,10 @@ import ( // Config defines configuration for Azure Monitor type Config struct { exporterhelper.QueueSettings `mapstructure:"sending_queue"` - Endpoint string `mapstructure:"endpoint"` - ConnectionString configopaque.String `mapstructure:"connection_string"` - InstrumentationKey configopaque.String `mapstructure:"instrumentation_key"` - MaxBatchSize int `mapstructure:"maxbatchsize"` - MaxBatchInterval time.Duration `mapstructure:"maxbatchinterval"` - SpanEventsEnabled bool `mapstructure:"spaneventsenabled"` + Endpoint string `mapstructure:"endpoint"` + ConnectionString configopaque.String `mapstructure:"connection_string"` + InstrumentationKey configopaque.String `mapstructure:"instrumentation_key"` + MaxBatchSize int `mapstructure:"maxbatchsize"` + MaxBatchInterval time.Duration `mapstructure:"maxbatchinterval"` + SpanEventsEnabled bool `mapstructure:"spaneventsenabled"` }