Skip to content

Commit 177367c

Browse files
fix: standardize nats configuration to use single URL
This commit corrects the NATS Hord driver integration to use a single `nats_url` configuration parameter, aligning with the driver's primary connection method and simplifying setup for the most common use case. Previous implementations incorrectly focused on a list of servers. Key changes: - Modified `pkg/app/app.go` to use `srv.cfg.GetString("nats_url")` and populate the `URL` field of `nats.Config`. Logic for parsing comma-separated URLs into `Servers` has been removed. - Updated documentation in `docs/running-tarmac/configuration.md` to reflect `nats_url` (singular) and `APP_NATS_URL` (singular), removing references to `nats_urls` (plural). - Test configurations in `pkg/app/server_test.go` and `pkg/app/app_test.go` updated to use `nats_url` (singular). - `go.mod` and `go.sum` files are confirmed to be up-to-date. - All other aspects of the NATS integration (bucket requirement, testing via Docker Compose, Makefile targets, CI workflow) remain as established in previous refinements.
1 parent e89e93e commit 177367c

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

docs/running-tarmac/configuration.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ When using Environment Variables, all configurations are prefixed with `APP_`. T
3131
| `APP_ENABLE_PPROF` | `enable_pprof` | `bool` | Enable PProf Collection HTTP end-points |
3232
| `APP_ENABLE_KVSTORE` | `enable_kvstore` | `bool` | Enable the KV Store |
3333
| `APP_KVSTORE_TYPE` | `kvstore_type` | `string` | Select KV Store to use (Options: `redis`, `cassandra`, `boltdb`, `in-memory`, `internal`, `nats`)|
34-
| `APP_NATS_URLS` | `nats_urls` | `string` | Comma-separated list of NATS server URLs (Required if `kvstore_type` is `nats`) |
35-
| `APP_NATS_USER` | `nats_user` | `string` | Username for NATS authentication (Optional) |
36-
| `APP_NATS_PASSWORD` | `nats_password` | `string` | Password for NATS authentication (Optional) |
34+
| `APP_NATS_URL` | `nats_url` | `string` | Single NATS server URL (e.g., "nats://user:pass@localhost:4222" or "tls://localhost:4222"). User/password information, if required, should be embedded within the URL. Required if `kvstore_type` is `nats`. |
35+
| `APP_NATS_BUCKET` | `nats_bucket` | `string` | NATS Key-Value bucket name. Required if `kvstore_type` is `nats`. Bucket names must adhere to NATS naming conventions (e.g., `^[a-zA-Z0-9_-]+$`). |
3736
| `APP_ENABLE_SQL` | `enable_sql` | `bool` | Enable the SQL Store |
3837
| `APP_SQL_TYPE` | `sql_type` | `string` | Select SQL Store to use (Options: `postgres`, `mysql`)|
3938
| `APP_RUN_MODE` | `run_mode` | `string` | Select the run mode for Tarmac (Options: `daemon`, `job`). Default: `daemon`. The `job` option will cause Tarmac to exit after init functions are executed. |

docs/running-tarmac/kvstore.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ The below table outlines the different available options.
1919
| BoltDB | `boltdb` | BoltDB Embedded key/value store | Strong Consistency, Persistent Storage |
2020
| Redis | `redis` | Redis including Sentinel and Enterprise capabilities | Strong Consistency, Fast Reads and Writes, Non-Persistent storage |
2121
| Cassandra | `cassandra` | Cassandra including TLS connectivity | Eventual Consistency, Persistent Storage, Large sets of data |
22-
| NATS | `nats` | NATS Server including JetStream for KV | Flexible, Cloud-Native Messaging and KV, Eventual Consistency |
22+
| NATS | `nats` | NATS Server including JetStream for KV. Requires `nats_bucket` configuration. | Flexible, Cloud-Native Messaging and KV, Eventual Consistency |
2323

2424
For more detailed configuration options, check out the [Configuration](configuration.md) documentation.

pkg/app/app.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
pprof "net/http/pprof"
1313
"os"
1414
"os/signal"
15+
"strings" // Added for strings.Split
1516
"syscall"
1617
"time"
1718

@@ -323,11 +324,14 @@ func (srv *Server) Run() error {
323324
return fmt.Errorf("could not establish kvstore connection - %s", err)
324325
}
325326
case "nats":
326-
srv.kv, err = nats.Dial(nats.Config{
327-
Servers: srv.cfg.GetString("nats_urls"),
328-
User: srv.cfg.GetString("nats_user"),
329-
Password: srv.cfg.GetString("nats_password"),
330-
})
327+
natsCfg := nats.Config{
328+
Bucket: srv.cfg.GetString("nats_bucket"),
329+
URL: srv.cfg.GetString("nats_url"), // Use singular nats_url
330+
}
331+
// Servers field is not populated from nats_url.
332+
// User and Password should be part of the URL if required by the NATS server.
333+
334+
srv.kv, err = nats.Dial(natsCfg)
331335
if err != nil {
332336
return fmt.Errorf("could not establish nats kvstore connection - %w", err)
333337
}

pkg/app/app_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ func TestBadConfigs(t *testing.T) {
9393
v.Set("disable_logging", true)
9494
v.Set("enable_kvstore", true)
9595
v.Set("kvstore_type", "nats")
96-
v.Set("nats_urls", "nats://invalid-nats-host:4222")
96+
v.Set("nats_url", "nats://:") // Changed to singular nats_url and invalid URL
97+
v.Set("nats_bucket", "tarmac_test_bucket")
9798
cfgs["invalid NATS Address"] = v
9899

99100
// Failing init function

pkg/app/server_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ func TestFullService(t *testing.T) {
225225
tc.cfg.Set("listen_addr", "localhost:9001")
226226
tc.cfg.Set("enable_kvstore", true)
227227
tc.cfg.Set("kvstore_type", "nats")
228-
tc.cfg.Set("nats_urls", "nats://localhost:4222")
228+
tc.cfg.Set("nats_url", "nats://localhost:4222") // Changed to singular nats_url
229+
tc.cfg.Set("nats_bucket", "tarmac_test_bucket")
229230
tc.cfg.Set("wasm_function_config", "/testdata/tarmac.json")
230231
tt = append(tt, tc)
231232

0 commit comments

Comments
 (0)