-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/bmchelix] Second PR of New component: BMC Helix Exporter (#…
…37350) * Implemented core functionality in `exporter.go` to handle metric transformation and payload dispatch to BMC Helix. * Added `metrics_client.go` with HTTP client configuration. * Added `metrics_producer.go` to produce BMC Helix-compatible payloads. * Added unit tests. <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This pull request introduces the BMC Helix Exporter, which is responsible for exporting metrics to BMC Helix Operations Management. The most important changes include the implementation of the exporter, configuration adjustments, and the addition of unit tests. ##### Implementation of BMC Helix Exporter: * [`exporter/bmchelixexporter/exporter.go`](diffhunk://#diff-4a430330ea5f9e90bc37821ca52351bc66219d4da8a1da11299b049cd4864214R1-R84): Introduced `BmcHelixExporter` class with methods to start the exporter and push metrics to BMC Helix. * Developed `metrics_producer.go` to build the BMC Helix Operations Management expected metric payloads. * [`exporter/bmchelixexporter/metrics_client.go`](diffhunk://#diff-9a8d71b75da3d5cc679440769fae03014ae601d122e65e5797ea9866cb9cf341R1-R93): Added `MetricsClient` class responsible for sending metrics payloads to BMC Helix. ##### Configuration Adjustments: * [`exporter/bmchelixexporter/config.go`](diffhunk://#diff-4b576c9fd2cd87cecaf1fd1182f88283e38a6e2f4c6c28549f98f22ad60949dcL8-L17): Replaced `Endpoint` and `Timeout` fields with `confighttp.ClientConfig` to handle HTTP client configuration. * [`exporter/bmchelixexporter/factory.go`](diffhunk://#diff-f69eea4d007085533aa8bb35cc91f6c41f1783a87998eaa3ddefd1730ea2d0fbR30-R54): Updated `createDefaultConfig` to use `confighttp.NewDefaultClientConfig` and adjusted the `createMetricsExporter` function to initialize the exporter properly. ##### Unit Tests: * [`exporter/bmchelixexporter/config_test.go`](diffhunk://#diff-b79eedb9dda64716aecd4902019fc29dc3ade40d26b5b32081d60d5c43d6fd4bL34-L45): Modified tests to accommodate changes in configuration structure and added helper function `createDefaultClientConfig`. * [`exporter/bmchelixexporter/exporter_test.go`](diffhunk://#diff-ed008fa0f26264e77c8516b3334f98fdc7f9bbac4fd7bc09719033c57331ad5fR1-R28): Added unit tests for `newBmcHelixExporter` function to ensure proper initialization. * `exporter/bmchelixexporter/metrics_producer.go`: Added unit tests. * `exporter/bmchelixexporter/metrics_client.go`: Added unit tests. ##### Changelog Entry: * [`.chloggen/bmchelixexporter-metrics-implementation.yaml`](diffhunk://#diff-e86aa08891f9688ad1995e82d398c481bedbbdea3903847c853585869c2feb65R1-R27): Added a new changelog entry for the BMC Helix Exporter metrics implementation. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #36773 <!--Describe what testing was performed and which tests were added. #### Testing--> <!--Describe the documentation added.- #### Documentation-> <!--Please delete paragraphs that you did not use before submitting.-->
- Loading branch information
Showing
12 changed files
with
919 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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: new_component | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: bmchelixexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: metrics implementation | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [36773] | ||
|
||
# (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] |
This file contains 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 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 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,76 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package bmchelixexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/bmchelixexporter" | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/exporter" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.uber.org/zap" | ||
|
||
om "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/bmchelixexporter/internal/operationsmanagement" | ||
) | ||
|
||
// metricsExporter is responsible for exporting metrics to BMC Helix | ||
type metricsExporter struct { | ||
config *Config | ||
logger *zap.Logger | ||
version string | ||
telemetrySettings component.TelemetrySettings | ||
producer *om.MetricsProducer | ||
client *om.MetricsClient | ||
} | ||
|
||
// newMetricsExporter instantiates a new metrics exporter for BMC Helix | ||
func newMetricsExporter(config *Config, createSettings exporter.Settings) (*metricsExporter, error) { | ||
if config == nil { | ||
return nil, errors.New("nil config") | ||
} | ||
|
||
return &metricsExporter{ | ||
config: config, | ||
version: createSettings.BuildInfo.Version, | ||
logger: createSettings.Logger, | ||
telemetrySettings: createSettings.TelemetrySettings, | ||
}, nil | ||
} | ||
|
||
// pushMetrics is invoked by the OpenTelemetry Collector to push metrics to BMC Helix | ||
func (me *metricsExporter) pushMetrics(ctx context.Context, md pmetric.Metrics) error { | ||
helixMetrics, err := me.producer.ProduceHelixPayload(md) | ||
if err != nil { | ||
me.logger.Error("Failed to build BMC Helix Metrics payload", zap.Error(err)) | ||
return err | ||
} | ||
|
||
err = me.client.SendHelixPayload(ctx, helixMetrics) | ||
if err != nil { | ||
me.logger.Error("Failed to send BMC Helix Metrics payload", zap.Error(err)) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// start is invoked during service start | ||
func (me *metricsExporter) start(ctx context.Context, host component.Host) error { | ||
me.logger.Info("Starting BMC Helix Metrics Exporter") | ||
|
||
// Initialize and store the MetricsProducer | ||
me.producer = om.NewMetricsProducer(me.logger) | ||
|
||
// Initialize and store the MetricsClient | ||
client, err := om.NewMetricsClient(ctx, me.config.ClientConfig, me.config.APIKey, host, me.telemetrySettings, me.logger) | ||
if err != nil { | ||
me.logger.Error("Failed to create MetricsClient", zap.Error(err)) | ||
return err | ||
} | ||
me.client = client | ||
|
||
me.logger.Info("Initialized BMC Helix Metrics Exporter") | ||
return nil | ||
} |
This file contains 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,28 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package bmchelixexporter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/exporter/exportertest" | ||
) | ||
|
||
func TestNewMetricsExporterWithNilConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
exp, err := newMetricsExporter(nil, exportertest.NewNopSettings()) | ||
assert.Nil(t, exp) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestNewMetricsExporterWithDefaultConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := createDefaultConfig().(*Config) | ||
exp, err := newMetricsExporter(cfg, exportertest.NewNopSettings()) | ||
assert.NotNil(t, exp) | ||
assert.NoError(t, err) | ||
} |
This file contains 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 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
Oops, something went wrong.