Skip to content

Commit

Permalink
add veopscmdb exporer
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Tan <[email protected]>
  • Loading branch information
JaredTan95 committed Jun 17, 2024
1 parent 184fa8d commit c52aa41
Show file tree
Hide file tree
Showing 23 changed files with 1,006 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ exporters:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/syslogexporter v0.102.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/tencentcloudlogserviceexporter v0.102.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter v0.102.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/veopscmdbexporter v0.102.0

processors:
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.102.0
Expand Down Expand Up @@ -434,6 +435,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/processor/remotetapprocessor => ../../processor/remotetapprocessor
- github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumologicprocessor => ../../processor/sumologicprocessor
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/syslogexporter => ../../exporter/syslogexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/veopscmdbexporter => ../../exporter/veopscmdbexporter
# see https://github.com/mattn/go-ieproxy/issues/45
- github.com/mattn/go-ieproxy => github.com/mattn/go-ieproxy v0.0.1
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest
Expand Down
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/cmd/otelcontrib

go 1.21.0

toolchain go1.21.11
toolchain go1.22.2

require (
github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provider/s3provider v0.102.0
Expand Down Expand Up @@ -60,6 +60,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter v0.102.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/syslogexporter v0.102.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/tencentcloudlogserviceexporter v0.102.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/veopscmdbexporter v0.102.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter v0.102.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/ackextension v0.102.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/asapauthextension v0.102.0
Expand Down Expand Up @@ -708,7 +709,7 @@ require (
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.936 // indirect
github.com/tg123/go-htpasswd v1.2.2 // indirect
github.com/tidwall/gjson v1.14.2 // indirect
github.com/tidwall/gjson v1.17.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/tinylru v1.1.0 // indirect
Expand Down Expand Up @@ -1225,6 +1226,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/sumo

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/syslogexporter => ../../exporter/syslogexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/veopscmdbexporter => ../../exporter/veopscmdbexporter

replace github.com/mattn/go-ieproxy => github.com/mattn/go-ieproxy v0.0.1

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest
Expand Down
4 changes: 2 additions & 2 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions exporter/veopscmdbexporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
33 changes: 33 additions & 0 deletions exporter/veopscmdbexporter/README.md
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"
```
51 changes: 51 additions & 0 deletions exporter/veopscmdbexporter/config.go
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)
66 changes: 66 additions & 0 deletions exporter/veopscmdbexporter/config_test.go
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
}
7 changes: 7 additions & 0 deletions exporter/veopscmdbexporter/doc.go
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"
52 changes: 52 additions & 0 deletions exporter/veopscmdbexporter/factory.go
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),
)
}
36 changes: 36 additions & 0 deletions exporter/veopscmdbexporter/factory_test.go
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()))
}
Loading

0 comments on commit c52aa41

Please sign in to comment.