Skip to content

Commit

Permalink
feat: Remove NUMARY_ prefix on ledger and update operator (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored and flemzord committed May 12, 2023
1 parent dd6e368 commit c46ac79
Show file tree
Hide file tree
Showing 33 changed files with 136 additions and 283 deletions.
20 changes: 10 additions & 10 deletions components/ledger/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ tasks:
go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} -coverpkg {{.PKG}}
-coverprofile coverage.out -covermode atomic {{.PKG}}
env:
NUMARY_STORAGE_DRIVER: "postgres"
NUMARY_STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"
STORAGE_DRIVER: "postgres"
STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"

tests:local:
cmds:
Expand Down Expand Up @@ -68,8 +68,8 @@ tasks:
sed ''/RUN/s//$(printf "\033[34mRUN\033[0m")/''
- task: print:coverage
env:
NUMARY_STORAGE_DRIVER: "postgres"
NUMARY_STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"
STORAGE_DRIVER: "postgres"
STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"

print:coverage:
cmds:
Expand All @@ -91,8 +91,8 @@ tasks:
| tee {{.BENCH_RESULTS_FILE}}
- benchstat {{.BENCH_RESULTS_FILE}}
env:
NUMARY_STORAGE_DRIVER: "postgres"
NUMARY_STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"
STORAGE_DRIVER: "postgres"
STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"

bench:cpu:
cmds:
Expand Down Expand Up @@ -187,12 +187,12 @@ tasks:
vars:
Platform: "amd64"
Image: fedora
Cmd: "{{.rpm}} numary_*_linux_amd64.rpm"
Cmd: "{{.rpm}} *_linux_amd64.rpm"
- task: goreleaser:test:pkg
vars:
Platform: "arm64"
Image: fedora
Cmd: "{{.rpm}} numary_*_linux_arm64.rpm"
Cmd: "{{.rpm}} *_linux_arm64.rpm"

goreleaser:test:deb:
desc: Tests deb packages
Expand All @@ -203,12 +203,12 @@ tasks:
vars:
Platform: "amd64"
Image: ubuntu
Cmd: "{{.dpkg}} numary_*_linux_amd64.deb"
Cmd: "{{.dpkg}} *_linux_amd64.deb"
- task: goreleaser:test:pkg
vars:
Platform: "arm64"
Image: ubuntu
Cmd: "{{.dpkg}} numary_*_linux_arm64.deb"
Cmd: "{{.dpkg}} *_linux_arm64.deb"

run:
cmds:
Expand Down
4 changes: 2 additions & 2 deletions components/ledger/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
}
],
"env": {
"NUMARY_AUTH_BASIC_ENABLED": {
"AUTH_BASIC_ENABLED": {
"description": "Enable basic auth. (true or false)",
"required": true,
"value": "true"
},
"NUMARY_AUTH_BASIC_CREDENTIALS": {
"AUTH_BASIC_CREDENTIALS": {
"description": "HTTP basic auth credentials (<username>:<password>)",
"required": false
}
Expand Down
5 changes: 0 additions & 5 deletions components/ledger/cmd/internal/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ import (
"github.com/spf13/viper"
)

const (
envPrefix = "numary"
)

var EnvVarReplacer = strings.NewReplacer(".", "_", "-", "_")

func BindEnv(v *viper.Viper) {
v.SetEnvPrefix(envPrefix)
v.SetEnvKeyReplacer(EnvVarReplacer)
v.AutomaticEnv()
}
13 changes: 4 additions & 9 deletions components/ledger/cmd/internal/utils.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package internal

import (
"fmt"
"net/http"
"os"
"strings"
)

func withPrefix(flag string) string {
return strings.ToUpper(fmt.Sprintf("%s_%s", envPrefix, EnvVarReplacer.Replace(flag)))
}

func setEnvVar(key, value string) func() {
prefixedFlag := withPrefix(key)
oldEnv := os.Getenv(prefixedFlag)
os.Setenv(prefixedFlag, value)
flag := strings.ToUpper(EnvVarReplacer.Replace(key))
oldEnv := os.Getenv(flag)
os.Setenv(flag, value)
return func() {
os.Setenv(prefixedFlag, oldEnv)
os.Setenv(flag, oldEnv)
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/ledger/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestServer(t *testing.T) {
name: "default",
env: []env{
{
key: "NUMARY_STORAGE_DRIVER",
key: "STORAGE_DRIVER",
value: "sqlite",
},
},
Expand All @@ -48,11 +48,11 @@ func TestServer(t *testing.T) {
name: "pg-with-env-var",
env: []env{
{
key: "NUMARY_STORAGE_DRIVER",
key: "STORAGE_DRIVER",
value: "postgres",
},
{
key: "NUMARY_STORAGE_POSTGRES_CONN_STRING",
key: "STORAGE_POSTGRES_CONN_STRING",
value: db.ConnString(),
},
},
Expand Down
12 changes: 6 additions & 6 deletions components/ledger/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ services:
working_dir: /src
environment:
CGO_ENABLED: 0
NUMARY_DEBUG: "true"
NUMARY_OTEL_TRACES: "true"
NUMARY_OTEL_TRACES_EXPORTER: jaeger
NUMARY_OTEL_TRACES_EXPORTER_JAEGER_ENDPOINT: http://jaeger:14268/api/traces
NUMARY_OTEL_TRACES_EXPORTER_JAEGER_INSECURE: "true"
NUMARY_OTEL_METRICS: "false"
DEBUG: "true"
OTEL_TRACES: "true"
OTEL_TRACES_EXPORTER: jaeger
OTEL_TRACES_EXPORTER_JAEGER_ENDPOINT: http://jaeger:14268/api/traces
OTEL_TRACES_EXPORTER_JAEGER_INSECURE: "true"
OTEL_METRICS: "false"
depends_on:
- jaeger

Expand Down
8 changes: 4 additions & 4 deletions components/ledger/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ services:
postgres:
condition: service_healthy
environment:
NUMARY_STORAGE_DRIVER: "postgres"
NUMARY_STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:ledger@postgres/ledger"
NUMARY_SERVER_HTTP_BIND_ADDRESS: "0.0.0.0:3068"
STORAGE_DRIVER: "postgres"
STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:ledger@postgres/ledger"
SERVER_HTTP_BIND_ADDRESS: "0.0.0.0:3068"

proxy:
image: caddy:2
Expand All @@ -51,4 +51,4 @@ services:
ports:
- "3078:3078"
environment:
NUMARY_UI_HTTP_BIND_ADDRESS: "0.0.0.0:3078"
UI_HTTP_BIND_ADDRESS: "0.0.0.0:3078"
6 changes: 3 additions & 3 deletions components/ledger/examples/basic-auth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ services:
working_dir: /src
environment:
CGO_ENABLED: 0
NUMARY_DEBUG: "true"
NUMARY_AUTH_BASIC_ENABLED: "true"
NUMARY_AUTH_BASIC_CREDENTIALS: "user:password"
DEBUG: "true"
AUTH_BASIC_ENABLED: "true"
AUTH_BASIC_CREDENTIALS: "user:password"
10 changes: 5 additions & 5 deletions components/ledger/examples/jaeger-exporter/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ services:
- "3068:3068/tcp"
environment:
CGO_ENABLED: 0
NUMARY_DEBUG: "true"
NUMARY_OTEL_TRACES: "true"
NUMARY_OTEL_TRACES_EXPORTER: jaeger
NUMARY_OTEL_TRACES_EXPORTER_JAEGER_ENDPOINT: http://jaeger:14268/api/traces
NUMARY_OTEL_SERVICE_NAME: ledger
DEBUG: "true"
OTEL_TRACES: "true"
OTEL_TRACES_EXPORTER: jaeger
OTEL_TRACES_EXPORTER_JAEGER_ENDPOINT: http://jaeger:14268/api/traces
OTEL_SERVICE_NAME: ledger
14 changes: 7 additions & 7 deletions components/ledger/examples/multi-node/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ services:
working_dir: /src
environment:
CGO_ENABLED: 0
NUMARY_DEBUG: "true"
NUMARY_LOCK_STRATEGY: redis
NUMARY_LOCK_STRATEGY_REDIS_URL: redis://redis:6379
NUMARY_LOCK_STRATEGY_REDIS_DURATION: 60s # Default value
NUMARY_LOCK_STRATEGY_REDIS_RETRY: 1s # Default value
NUMARY_LOCK_STRATEGY_REDIS_TLS_ENABLED: false
NUMARY_LOCK_STRATEGY_REDIS_TLS_INSECURE: false
DEBUG: "true"
LOCK_STRATEGY: redis
LOCK_STRATEGY_REDIS_URL: redis://redis:6379
LOCK_STRATEGY_REDIS_DURATION: 60s # Default value
LOCK_STRATEGY_REDIS_RETRY: 1s # Default value
LOCK_STRATEGY_REDIS_TLS_ENABLED: false
LOCK_STRATEGY_REDIS_TLS_INSECURE: false

proxy:
extends:
Expand Down
18 changes: 9 additions & 9 deletions components/ledger/examples/otlp-exporter/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ services:
working_dir: /src
environment:
CGO_ENABLED: 0
NUMARY_DEBUG: "true"
NUMARY_OTEL_TRACES: "true"
NUMARY_OTEL_TRACES_EXPORTER: otlp
NUMARY_OTEL_TRACES_EXPORTER_OTLP_ENDPOINT: otlp-exporter:4317
NUMARY_OTEL_TRACES_EXPORTER_OTLP_INSECURE: "true"
NUMARY_OTEL_METRICS: "true"
NUMARY_OTEL_METRICS_EXPORTER: otlp
NUMARY_OTEL_METRICS_EXPORTER_OTLP_ENDPOINT: otlp-exporter:4317
NUMARY_OTEL_METRICS_EXPORTER_OTLP_INSECURE: "true"
DEBUG: "true"
OTEL_TRACES: "true"
OTEL_TRACES_EXPORTER: otlp
OTEL_TRACES_EXPORTER_OTLP_ENDPOINT: otlp-exporter:4317
OTEL_TRACES_EXPORTER_OTLP_INSECURE: "true"
OTEL_METRICS: "true"
OTEL_METRICS_EXPORTER: otlp
OTEL_METRICS_EXPORTER_OTLP_ENDPOINT: otlp-exporter:4317
OTEL_METRICS_EXPORTER_OTLP_INSECURE: "true"
6 changes: 3 additions & 3 deletions components/ledger/examples/publisher-http/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ services:
working_dir: /src
environment:
CGO_ENABLED: 0
NUMARY_DEBUG: "true"
NUMARY_PUBLISHER_HTTP_ENABLED: "true"
NUMARY_PUBLISHER_TOPIC_MAPPING: "*:http://listener:8080"
DEBUG: "true"
PUBLISHER_HTTP_ENABLED: "true"
PUBLISHER_TOPIC_MAPPING: "*:http://listener:8080"
8 changes: 4 additions & 4 deletions components/ledger/examples/publisher-kafka/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
working_dir: /src
environment:
CGO_ENABLED: 0
NUMARY_DEBUG: "true"
NUMARY_PUBLISHER_KAFKA_ENABLED: "true"
NUMARY_PUBLISHER_KAFKA_BROKER: "kafka:9092"
NUMARY_PUBLISHER_TOPIC_MAPPING: "*:default" # Send all to 'default' topic
DEBUG: "true"
PUBLISHER_KAFKA_ENABLED: "true"
PUBLISHER_KAFKA_BROKER: "kafka:9092"
PUBLISHER_TOPIC_MAPPING: "*:default" # Send all to 'default' topic
2 changes: 1 addition & 1 deletion components/ledger/internal/pgtesting/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const MaxConnections = 3

func PostgresServer() (*PGServer, error) {

externalConnectionString := os.Getenv("NUMARY_STORAGE_POSTGRES_CONN_STRING")
externalConnectionString := os.Getenv("STORAGE_POSTGRES_CONN_STRING")
if externalConnectionString != "" {
return &PGServer{
url: externalConnectionString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ func TestTooManyClient(t *testing.T) {
if ledgertesting.StorageDriverName() != "postgres" {
return nil
}
if os.Getenv("NUMARY_STORAGE_POSTGRES_CONN_STRING") != "" { // Use of external server, ignore this test
if os.Getenv("STORAGE_POSTGRES_CONN_STRING") != "" { // Use of external server, ignore this test
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion components/ledger/pkg/ledgertesting/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func StorageDriverName() string {
fromEnv := os.Getenv("NUMARY_STORAGE_DRIVER")
fromEnv := os.Getenv("STORAGE_DRIVER")
if fromEnv != "" {
return fromEnv
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ func testGetTransaction(t *testing.T, store *sqlstorage.Store) {

func testTooManyClient(t *testing.T, store *sqlstorage.Store) {
// Use of external server, ignore this test
if os.Getenv("NUMARY_STORAGE_POSTGRES_CONN_STRING") != "" ||
if os.Getenv("STORAGE_POSTGRES_CONN_STRING") != "" ||
ledgertesting.StorageDriverName() != "postgres" {
return
}
Expand Down
2 changes: 1 addition & 1 deletion components/ledger/sdk/templates/go/Taskfile.yml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tasks:
docker run -d
--name ledger
--rm
-e NUMARY_SERVER_HTTP_BIND_ADDRESS=0.0.0.0:3068
-e SERVER_HTTP_BIND_ADDRESS=0.0.0.0:3068
-p 3068:3068
ghcr.io/formancehq/ledger:{{appVersion}}

Expand Down
2 changes: 1 addition & 1 deletion components/ledger/sdk/templates/php/Taskfile.yml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tasks:
docker run -d
--name ledger
--rm
-e NUMARY_SERVER_HTTP_BIND_ADDRESS=0.0.0.0:3068
-e SERVER_HTTP_BIND_ADDRESS=0.0.0.0:3068
-p 3068:3068
ghcr.io/formancehq/ledger:{{appVersion}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tasks:
docker run -d
--name ledger
--rm
-e NUMARY_SERVER_HTTP_BIND_ADDRESS=0.0.0.0:3068
-e SERVER_HTTP_BIND_ADDRESS=0.0.0.0:3068
-p 3068:3068
ghcr.io/formancehq/ledger:{{appVersion}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tasks:
docker run -d
--name ledger
--rm
-e NUMARY_SERVER_HTTP_BIND_ADDRESS=0.0.0.0:3068
-e SERVER_HTTP_BIND_ADDRESS=0.0.0.0:3068
-p 3068:3068
ghcr.io/formancehq/ledger:{{appVersion}}

Expand Down
40 changes: 0 additions & 40 deletions components/operator/internal/common/broker.go

This file was deleted.

1 change: 0 additions & 1 deletion components/operator/internal/common/image.go

This file was deleted.

Loading

0 comments on commit c46ac79

Please sign in to comment.