forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jared Tan <[email protected]>
- Loading branch information
1 parent
184fa8d
commit c52aa41
Showing
23 changed files
with
1,006 additions
and
4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
include ../../Makefile.Common |
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,33 @@ | ||
# Veops CMDB Exporter | ||
<!-- status autogenerated section --> | ||
| Status | | | ||
| ------------- |-----------| | ||
| Stability | [alpha]: logs | | ||
| Distributions | [contrib] | | ||
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aexporter%2Fhoneycombmarker%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aexporter%2Fhoneycombmarker) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aexporter%2Fhoneycombmarker%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aexporter%2Fhoneycombmarker) | | ||
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@TylerHelmuth](https://www.github.com/TylerHelmuth), [@fchikwekwe](https://www.github.com/fchikwekwe) | | ||
|
||
[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha | ||
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib | ||
<!-- end autogenerated section --> | ||
|
||
This exporter allows creating [markers](https://docs.honeycomb.io/working-with-your-data/markers/), via the [Honeycomb Markers API](https://docs.honeycomb.io/api/tag/Markers#operation/createMarker), based on the look of incoming telemetry. | ||
|
||
The following configuration options are supported: | ||
|
||
* `api_key` (Required): This is the API key for your CMDB account. | ||
* `api_secret` (Required): This is the API secret for your CMDB account. | ||
* `api_url` (Optional): This sets the hostname to send marker data to. If not set, will default to `http://localhost:5000/api/v0.1/ci` | ||
* `ci_matches` (Required): This is a list of configurations to create an CI. | ||
* `resouce_name`: (Required): Specifies the kubernetes resoruce type name(following `k8sobjectsreceiver`). | ||
* `ci_type` (Required): Specifies the marker type. | ||
Example: | ||
```yaml | ||
exporters: | ||
veopscmdbexporter: | ||
api_key: "test-apikey" | ||
api_secret: "test-apisecret" | ||
ci_matches: | ||
- resource_name: namespaces | ||
ci_type: "1" | ||
``` |
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,51 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package veopscmdbexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/veopscmdbexporter" | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/config/configopaque" | ||
"go.opentelemetry.io/collector/config/configretry" | ||
"go.opentelemetry.io/collector/exporter/exporterhelper" | ||
) | ||
|
||
// Config defines configuration for the CMDB exporter. | ||
type Config struct { | ||
// APIKey is the authentication token associated with the Honeycomb account. | ||
APIKey configopaque.String `mapstructure:"api_key"` | ||
APISecret configopaque.String `mapstructure:"api_secret"` | ||
|
||
// API URL to use (defaults to http://localhost:5000) | ||
APIAddress string `mapstructure:"api_address"` | ||
|
||
// CIMatches is the list of CIs to create | ||
KubernetesClusterCIType int64 `mapstructure:"kubernetes_cluster_ci_type"` | ||
|
||
confighttp.ClientConfig `mapstructure:",squash"` | ||
exporterhelper.QueueSettings `mapstructure:"sending_queue"` | ||
configretry.BackOffConfig `mapstructure:"retry_on_failure"` | ||
} | ||
|
||
var _ component.Config = (*Config)(nil) | ||
|
||
func (cfg *Config) Validate() error { | ||
if cfg.APIKey == "" || cfg.APISecret == "" { | ||
return fmt.Errorf("invalid API Key or API Secret") | ||
} | ||
|
||
if cfg.KubernetesClusterCIType == 0 { | ||
return fmt.Errorf("no KubernetesClusterCIType supplied") | ||
} | ||
|
||
if cfg.APIAddress == "" { | ||
cfg.APIAddress = "http://localhost:5000" | ||
} | ||
|
||
return nil | ||
} | ||
|
||
var _ component.Config = (*Config)(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,66 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package veopscmdbexporter | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/veopscmdbexporter/internal/metadata" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/confmap/confmaptest" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
id component.ID | ||
expected component.Config | ||
}{ | ||
{ | ||
id: component.NewIDWithName(metadata.Type, ""), | ||
expected: &Config{ | ||
APIKey: "test-apikey", | ||
APIAddress: "http://localhost:5000", | ||
CIMatches: map[string]string{ | ||
"namespaces": "1", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.id.String(), func(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
|
||
sub, err := cm.Sub(tt.id.String()) | ||
require.NoError(t, err) | ||
require.NoError(t, component.UnmarshalConfig(sub, cfg)) | ||
|
||
if tt.expected == nil { | ||
err = component.ValidateConfig(cfg) | ||
assert.Error(t, err) | ||
return | ||
} | ||
|
||
assert.NoError(t, component.ValidateConfig(cfg)) | ||
assert.Equal(t, tt.expected, cfg) | ||
}) | ||
} | ||
} | ||
|
||
func withDefaultConfig(fns ...func(*Config)) *Config { | ||
cfg := createDefaultConfig().(*Config) | ||
for _, fn := range fns { | ||
fn(cfg) | ||
} | ||
return cfg | ||
} |
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,7 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:generate mdatagen metadata.yaml | ||
|
||
// Package honeycombmarkerexporter exports CI data to Honeycomb. | ||
package veopscmdbexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/honeycombmarkerexporter" |
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,52 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package veopscmdbexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/veopscmdbexporter" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/exporter" | ||
"go.opentelemetry.io/collector/exporter/exporterhelper" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/veopscmdbexporter/internal/metadata" | ||
) | ||
|
||
func NewFactory() exporter.Factory { | ||
return exporter.NewFactory( | ||
metadata.Type, | ||
createDefaultConfig, | ||
exporter.WithLogs(createLogsExporter, metadata.LogsStability), | ||
) | ||
} | ||
|
||
func createDefaultConfig() component.Config { | ||
return &Config{ | ||
APIAddress: "http://localhost:5000", | ||
} | ||
} | ||
|
||
func createLogsExporter( | ||
ctx context.Context, | ||
set exporter.CreateSettings, | ||
cfg component.Config, | ||
) (exporter.Logs, error) { | ||
cf := cfg.(*Config) | ||
|
||
logsExp, err := newVeopsCMDBExporter(set, cf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return exporterhelper.NewLogsExporter( | ||
ctx, | ||
set, | ||
cfg, | ||
logsExp.exportResources, | ||
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}), | ||
exporterhelper.WithRetry(cf.BackOffConfig), | ||
exporterhelper.WithQueue(cf.QueueSettings), | ||
exporterhelper.WithStart(logsExp.start), | ||
) | ||
} |
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,36 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package veopscmdbexporter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/exporter/exportertest" | ||
) | ||
|
||
const defaultURL = `http://localhost:5000` | ||
|
||
func TestCreateDefaultConfig(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
assert.NotNil(t, cfg, "failed to create default config") | ||
assert.NoError(t, componenttest.CheckConfigStruct(cfg)) | ||
} | ||
|
||
func TestFactory_CreateLogsExporter(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := withDefaultConfig(func(cfg *Config) { | ||
cfg.APIAddress = defaultURL | ||
}) | ||
params := exportertest.NewNopCreateSettings() | ||
exporter, err := factory.CreateLogsExporter(context.Background(), params, cfg) | ||
require.NoError(t, err) | ||
require.NotNil(t, exporter) | ||
|
||
require.NoError(t, exporter.Shutdown(context.TODO())) | ||
} |
Oops, something went wrong.