Skip to content

Commit

Permalink
feat: add username and password to es client (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
kavzovic committed Aug 8, 2024
1 parent c4d9830 commit a85859d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,24 @@ Check out on [go-dcp](https://github.com/Trendyol/go-dcp#configuration)

### Elasticsearch Specific Configuration

| Variable | Type | Required | Default | Description |
|---------------------------------------------|-------------------|----------|--------------|-----------------------------------------------------------------------------------------------------|
| `elasticsearch.collectionIndexMapping` | map[string]string | yes | | Defines which Couchbase collection events will be written to which index |
| `elasticsearch.urls` | []string | yes | | Elasticsearch connection urls |
| `elasticsearch.typeName` | string | no | | Defines Elasticsearch index type name |
| `elasticsearch.batchSizeLimit` | int | no | 1000 | Maximum message count for batch, if exceed flush will be triggered. |
| `elasticsearch.batchTickerDuration` | time.Duration | no | 10s | Batch is being flushed automatically at specific time intervals for long waiting messages in batch. |
| `elasticsearch.batchByteSizeLimit` | int, string | no | 10mb | Maximum size(byte) for batch, if exceed flush will be triggered. `10mb` is default. |
| `elasticsearch.maxConnsPerHost` | int | no | 512 | Maximum number of connections per each host which may be established |
| `elasticsearch.maxIdleConnDuration` | time.Duration | no | 10s | Idle keep-alive connections are closed after this duration. |
| `elasticsearch.compressionEnabled` | boolean | no | false | Compression can be used if message size is large, CPU usage may be affected. |
| `elasticsearch.concurrentRequest` | int | no | 1 | Concurrent bulk request count |
| `elasticsearch.disableDiscoverNodesOnStart` | boolean | no | false | Disable discover nodes when initializing the client. |
| `elasticsearch.discoverNodesInterval` | time.Duration | no | 5m | Discover nodes periodically |
| `elasticsearch.rejectionLog.index` | string | no | cbes-rejects | Rejection log index name. `cbes-rejects` is default. |
| `elasticsearch.rejectionLog.includeSource` | boolean | no | false | Includes rejection log source info. `false` is default. |
| Variable | Type | Required | Default | Description |
|---------------------------------------------|-------------------|------------|--------------|-----------------------------------------------------------------------------------------------------|
| `elasticsearch.collectionIndexMapping` | map[string]string | yes | | Defines which Couchbase collection events will be written to which index |
| `elasticsearch.urls` | []string | yes | | Elasticsearch connection urls |
| `elasticsearch.username` | string | no | | The username of Elasticsearch |
| `elasticsearch.password` | string | no | | The password of Elasticsearch |
| `elasticsearch.typeName` | string | no | | Defines Elasticsearch index type name |
| `elasticsearch.batchSizeLimit` | int | no | 1000 | Maximum message count for batch, if exceed flush will be triggered. |
| `elasticsearch.batchTickerDuration` | time.Duration | no | 10s | Batch is being flushed automatically at specific time intervals for long waiting messages in batch. |
| `elasticsearch.batchByteSizeLimit` | int, string | no | 10mb | Maximum size(byte) for batch, if exceed flush will be triggered. `10mb` is default. |
| `elasticsearch.maxConnsPerHost` | int | no | 512 | Maximum number of connections per each host which may be established |
| `elasticsearch.maxIdleConnDuration` | time.Duration | no | 10s | Idle keep-alive connections are closed after this duration. |
| `elasticsearch.compressionEnabled` | boolean | no | false | Compression can be used if message size is large, CPU usage may be affected. |
| `elasticsearch.concurrentRequest` | int | no | 1 | Concurrent bulk request count |
| `elasticsearch.disableDiscoverNodesOnStart` | boolean | no | false | Disable discover nodes when initializing the client. |
| `elasticsearch.discoverNodesInterval` | time.Duration | no | 5m | Discover nodes periodically |
| `elasticsearch.rejectionLog.index` | string | no | cbes-rejects | Rejection log index name. `cbes-rejects` is default. |
| `elasticsearch.rejectionLog.includeSource` | boolean | no | false | Includes rejection log source info. `false` is default. |

## Exposed metrics

Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

type Elasticsearch struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
BatchByteSizeLimit any `yaml:"batchByteSizeLimit"`
CollectionIndexMapping map[string]string `yaml:"collectionIndexMapping"`
MaxConnsPerHost *int `yaml:"maxConnsPerHost"`
Expand Down
2 changes: 2 additions & 0 deletions elasticsearch/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

func NewElasticClient(config *config.Config) (*elasticsearch.Client, error) {
es, err := elasticsearch.NewClient(elasticsearch.Config{
Username: config.Elasticsearch.Username,
Password: config.Elasticsearch.Password,
MaxRetries: math.MaxInt,
Addresses: config.Elasticsearch.Urls,
Transport: newTransport(config.Elasticsearch),
Expand Down

0 comments on commit a85859d

Please sign in to comment.