Skip to content

Commit

Permalink
cassandra exporter implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
emreyalvac committed Feb 7, 2023
1 parent c7c8ffa commit 957a208
Show file tree
Hide file tree
Showing 22 changed files with 978 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .chloggen/cassandra-exporter-implementation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: cassandra_exporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Cassandra exporter implementation

# One or more tracking issues related to the change
issues: [ ]

# (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:
5 changes: 5 additions & 0 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-zookeeper/zk v1.0.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gocql/gocql v1.3.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
Expand Down Expand Up @@ -218,6 +219,7 @@ require (
github.com/grobie/gomemcache v0.0.0-20180201122607-1f779c573665 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/hashicorp/consul/api v1.18.0 // indirect
github.com/hashicorp/cronexpr v1.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down Expand Up @@ -308,6 +310,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuredataexplorerexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/carbonexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/cassandraexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/coralogixexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter v0.69.0 // indirect
Expand Down Expand Up @@ -684,6 +687,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azure

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

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

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

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/coralogixexporter => ../../exporter/coralogixexporter
Expand Down
5 changes: 5 additions & 0 deletions cmd/configschema/go.sum

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

5 changes: 5 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-zookeeper/zk v1.0.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gocql/gocql v1.3.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
Expand Down Expand Up @@ -207,6 +208,7 @@ require (
github.com/grobie/gomemcache v0.0.0-20180201122607-1f779c573665 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/hashicorp/consul/api v1.18.0 // indirect
github.com/hashicorp/cronexpr v1.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down Expand Up @@ -297,6 +299,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuredataexplorerexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/carbonexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/cassandraexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/coralogixexporter v0.69.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter v0.69.0 // indirect
Expand Down Expand Up @@ -936,6 +939,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/click

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

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

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite => ../../pkg/translator/prometheusremotewrite

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dotnetdiagnosticsreceiver => ../../receiver/dotnetdiagnosticsreceiver
Expand Down
5 changes: 5 additions & 0 deletions cmd/otelcontribcol/go.sum

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

2 changes: 2 additions & 0 deletions cmd/oteltestbedcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/tence

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

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

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/saphanareceiver => ../../receiver/saphanareceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudspannerreceiver => ../../receiver/googlecloudspannerreceiver
Expand Down
8 changes: 8 additions & 0 deletions exporter/cassandraexporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include ../../Makefile.Common

local-run-example:
cd ../../ && GOOS=linux go build -o ./local/otelcontribcol ./cmd/otelcontribcol
cd example && docker-compose up -d
recreate-otel-collector:
cd ../../ && GOOS=linux go build -o ./local/otelcontribcol ./cmd/otelcontribcol
cd example && docker-compose up --build otelcollector
46 changes: 46 additions & 0 deletions exporter/cassandraexporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Cassandra Exporter

| Status | |
|--------------------------|-----------|
| Stability | [alpha] |
| Supported pipeline types | traces |
| Distributions | [contrib] |

## Configuration options

The following settings can be optionally configured:

- `dsn` The Cassandra server DSN (Data Source Name), for example `127.0.0.1`.
reference: [https://pkg.go.dev/github.com/gocql/gocql](https://pkg.go.dev/github.com/gocql/gocql)
- `keyspace` (default = otel): The keyspace name.
- `trace_table` (default = otel_spans): The table name for traces.
- `replication` (default = class: SimpleStrategy, replication_factor: 1) The strategy of
replication. https://cassandra.apache.org/doc/4.1/cassandra/architecture/dynamo.html#replication-strategy
- `compression` (default = LZ4Compressor) https://cassandra.apache.org/doc/latest/cassandra/operating/compression.html

## Example

```yaml
receivers:
examplereceiver:
processors:
batch:
timeout: 5s
send_batch_size: 100000
exporters:
cassandra:
dsn: 127.0.0.1
keyspace: "otel"
trace_table: "otel_spans"
replication:
class: "SimpleStrategy"
replication_factor: 1
compression:
algorithm: "ZstdCompressor"
service:
pipelines:
logs:
receivers: [ examplereceiver ]
processors: [ batch ]
exporters: [ cassandra ]
```
18 changes: 18 additions & 0 deletions exporter/cassandraexporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cassandraexporter

type Config struct {
DSN string `mapstructure:"dsn"`
Keyspace string `mapstructure:"keyspace"`
TraceTable string `mapstructure:"trace_table"`
Replication Replication `mapstructure:"replication"`
Compression Compression `mapstructure:"compression"`
}

type Replication struct {
Class string `mapstructure:"class"`
ReplicationFactor int `mapstructure:"replication_factor"`
}

type Compression struct {
Algorithm string `mapstructure:"algorithm"'`
}
69 changes: 69 additions & 0 deletions exporter/cassandraexporter/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cassandraexporter

import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"
"path/filepath"
"testing"
)

const defaultDSN = "127.0.0.1"

func TestLoadConfig(t *testing.T) {
t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)

defaultCfg := createDefaultConfig()
defaultCfg.(*Config).DSN = defaultDSN

tests := []struct {
id component.ID
expected component.Config
}{

{
id: component.NewIDWithName(typeStr, ""),
expected: defaultCfg,
},
}

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))

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
}
21 changes: 21 additions & 0 deletions exporter/cassandraexporter/example/otel-collector-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
exporters:
cassandra:
dsn: 127.0.0.1
keyspace: "otel"
trace_table: "otel_spans"
replication:
class: "SimpleStrategy"
replication_factor: 1
compression:
algorithm: "ZstdCompressor"

service:
pipelines:
traces:
receivers: [ otlp ]
exporters: [ cassandra ]
Loading

0 comments on commit 957a208

Please sign in to comment.