Skip to content

Commit

Permalink
[exporter/cassandra] close #27828 added authorization by username and…
Browse files Browse the repository at this point in the history
… password
  • Loading branch information
go-follow committed Oct 18, 2023
1 parent 80094bc commit d4a8080
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exporter/cassandraexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The following settings can be optionally configured:
- `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
- `auth` (default = username: "", password: "") Authorization for the Cassandra.

## Example

Expand All @@ -39,4 +40,7 @@ exporters:
replication_factor: 1
compression:
algorithm: "ZstdCompressor"
auth:
username: "your-username"
password: "your-password"
```
6 changes: 6 additions & 0 deletions exporter/cassandraexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {
LogsTable string `mapstructure:"logs_table"`
Replication Replication `mapstructure:"replication"`
Compression Compression `mapstructure:"compression"`
Auth Auth `mapstructure:"auth"`
}

type Replication struct {
Expand All @@ -21,3 +22,8 @@ type Replication struct {
type Compression struct {
Algorithm string `mapstructure:"algorithm"`
}

type Auth struct {
UserName string `mapstructure:"username"`
Password string `mapstructure:"password"`
}
6 changes: 6 additions & 0 deletions exporter/cassandraexporter/exporter_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ type logsExporter struct {

func newLogsExporter(logger *zap.Logger, cfg *Config) (*logsExporter, error) {
cluster := gocql.NewCluster(cfg.DSN)
if cfg.Auth.UserName != "" && cfg.Auth.Password != "" {
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: cfg.Auth.UserName,
Password: cfg.Auth.Password,
}
}
session, err := cluster.CreateSession()
cluster.Keyspace = cfg.Keyspace
cluster.Consistency = gocql.Quorum
Expand Down
6 changes: 6 additions & 0 deletions exporter/cassandraexporter/exporter_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ type tracesExporter struct {

func newTracesExporter(logger *zap.Logger, cfg *Config) (*tracesExporter, error) {
cluster := gocql.NewCluster(cfg.DSN)
if cfg.Auth.UserName != "" && cfg.Auth.Password != "" {
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: cfg.Auth.UserName,
Password: cfg.Auth.Password,
}
}
session, err := cluster.CreateSession()
cluster.Keyspace = cfg.Keyspace
cluster.Consistency = gocql.Quorum
Expand Down

0 comments on commit d4a8080

Please sign in to comment.