Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions docs/setting-up/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,24 @@ Real time logs of authorization. Permify uses [zerolog] as a logger.
```
├── logger
├── level
├── service_name
```

#### Glossary

| Required | Argument | Default | Description |
|----------|----------|---------|--------------------------------------------------|
| [x] | level | info | logger levels: `error`, `warn`, `info` , `debug` |
| [x] | output | text | logger output: `json`, `text` |
| Required | Argument | Default | Description |
|----------|--------------|---------|----------------------------------------------------------|
| [x] | level | info | logger levels: `error`, `warn`, `info` , `debug` |
| [x] | output | text | logger output: `json`, `text` |
| [ ] | service_name | permify | Override the service name reported by the log exporter. |

#### ENV

| Argument | ENV | Type |
|------------|--------------------|--------|
| log-level | PERMIFY_LOG_LEVEL | string |
| log-output | PERMIFY_LOG_OUTPUT | string |
| Argument | ENV | Type |
|-------------------|---------------------------|--------|
| log-level | PERMIFY_LOG_LEVEL | string |
| log-output | PERMIFY_LOG_OUTPUT | string |
| log-service-name | PERMIFY_LOG_SERVICE_NAME | string |

</Accordion>

Expand Down Expand Up @@ -330,6 +333,7 @@ authorization when using Permify.
| ├── enabled
| ├── insecure
| ├── urlpath
| ├── service_name
```

#### Glossary
Expand All @@ -340,17 +344,19 @@ authorization when using Permify.
| [x] | endpoint | - | export uri for tracing data. |
| [ ] | enabled | false | switch option for tracing. |
| [ ] | urlpath | | allows one to override the default URL path for otlp, used for sending traces. If unset, default ("/v1/traces") will be used. |
| [ ] | insecure | false | Whether to use HTTP instead of HTTPs for exporting the traces. |
| [ ] | insecure | false | Whether to use HTTP instead of HTTPs for exporting the traces. |
| [ ] | service_name | permify | Override the service name reported by the tracing exporter. |

#### ENV

| Argument | ENV | Type |
|-----------------|-------------------------|---------|
| tracer-enabled | PERMIFY_TRACER_ENABLED | boolean |
| tracer-exporter | PERMIFY_TRACER_EXPORTER | string |
| tracer-endpoint | PERMIFY_TRACER_ENDPOINT | string |
| tracer-urlpath | PERMIFY_TRACER_URL_PATH | string |
| tracer-insecure | PERMIFY_TRACER_INSECURE | boolean |
| Argument | ENV | Type |
|----------------------|------------------------------|---------|
| tracer-enabled | PERMIFY_TRACER_ENABLED | boolean |
| tracer-exporter | PERMIFY_TRACER_EXPORTER | string |
| tracer-endpoint | PERMIFY_TRACER_ENDPOINT | string |
| tracer-urlpath | PERMIFY_TRACER_URL_PATH | string |
| tracer-insecure | PERMIFY_TRACER_INSECURE | boolean |
| tracer-service-name | PERMIFY_TRACER_SERVICE_NAME | string |

</Accordion>

Expand All @@ -370,25 +376,28 @@ os, arch.
| ├── enabled
| ├── insecure
| ├── urlpath
| ├── service_name
```

#### Glossary

| Required | Argument | Default | Description |
|----------|----------|---------|--------------------------------------------------------------|
| [x] | exporter | - | [otlp](https://opentelemetry.io/docs/collector/) is default. |
| [x] | endpoint | - | export uri for metric observation |
| [ ] | enabled | true | switch option for meter tracing. |
| [x] | endpoint | - | export uri for metric observation |
| [ ] | enabled | true | switch option for meter tracing. |
| [ ] | service_name | permify | Override the service name reported by the metrics exporter. |

#### ENV

| Argument | ENV | Type |
|----------------|------------------------|---------|
| meter-enabled | PERMIFY_METER_ENABLED | boolean |
| meter-exporter | PERMIFY_METER_EXPORTER | string |
| meter-endpoint | PERMIFY_METER_ENDPOINT | string |
| meter-urlpath | PERMIFY_METER_URL_PATH | string |
| meter-insecure | PERMIFY_METER_INSECURE | boolean |
| Argument | ENV | Type |
|---------------------|-----------------------------|---------|
| meter-enabled | PERMIFY_METER_ENABLED | boolean |
| meter-exporter | PERMIFY_METER_EXPORTER | string |
| meter-endpoint | PERMIFY_METER_ENDPOINT | string |
| meter-urlpath | PERMIFY_METER_URL_PATH | string |
| meter-insecure | PERMIFY_METER_INSECURE | boolean |
| meter-service-name | PERMIFY_METER_SERVICE_NAME | string |

</Accordion>

Expand Down
18 changes: 10 additions & 8 deletions example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ tracer:
exporter: zipkin
endpoint: http://localhost:9411/api/v2/spans
enabled: false
service_name: permify

# The meter section enables or disables metrics collection and sets the
# exporter and endpoint for the collected metrics.
meter:
exporter: otlp
endpoint: localhost:4318
enabled: false
service_name: permify

# The service section sets various service-level settings, including whether
# or not to use a circuit breaker, and cache sizes for schema, permission,
Expand Down Expand Up @@ -79,16 +81,16 @@ database:
engine: postgres
uri: postgres://user:password@host:5432/db_name
auto_migrate: false
max_connections: 20 # Maximum number of connections in the pool (maps to pgxpool MaxConns)
max_open_connections: 20 # Deprecated: use max_connections instead. Kept for backward compatibility.
max_idle_connections: 1 # Deprecated: use min_connections instead. Kept for backward compatibility (maps to MinConnections if min_connections is not set).
min_connections: 0 # Minimum number of connections in the pool (maps to pgxpool MinConns). If 0 and max_idle_connections is set, max_idle_connections will be used.
min_idle_connections: 0 # Minimum idle connections (maps to pgxpool MinIdleConns). Must be explicitly set if needed (not set in old code).
max_connections: 20 # Maximum number of connections in the pool (maps to pgxpool MaxConns)
max_open_connections: 20 # Deprecated: use max_connections instead. Kept for backward compatibility.
max_idle_connections: 1 # Deprecated: use min_connections instead. Kept for backward compatibility (maps to MinConnections if min_connections is not set).
min_connections: 0 # Minimum number of connections in the pool (maps to pgxpool MinConns). If 0 and max_idle_connections is set, max_idle_connections will be used.
min_idle_connections: 0 # Minimum idle connections (maps to pgxpool MinIdleConns). Must be explicitly set if needed (not set in old code).
max_connection_lifetime: 300s
max_connection_idle_time: 60s
health_check_period: 0s # Use pgxpool default (1 minute) if 0
max_connection_lifetime_jitter: 0s # Will default to 20% of max_connection_lifetime if 0
connect_timeout: 0s # Use pgx default (no timeout) if 0
health_check_period: 0s # Use pgxpool default (1 minute) if 0
max_connection_lifetime_jitter: 0s # Will default to 20% of max_connection_lifetime if 0
connect_timeout: 0s # Use pgx default (no timeout) if 0
max_data_per_write: 1_000
max_retries: 10
watch_buffer_size: 100
Expand Down
82 changes: 44 additions & 38 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,41 @@ type (

// Log contains configuration for logging.
Log struct {
Level string `mapstructure:"level"` // Logging level
Output string `mapstructure:"output"` // Logging output format, e.g., text, json
Enabled bool `mapstructure:"enabled"` // Whether logging collection is enabled
Exporter string `mapstructure:"exporter"` // Exporter for log data
Endpoint string `mapstructure:"endpoint"` // Endpoint for the log exporter
Insecure bool `mapstructure:"insecure"` // Connect to the collector using the HTTP scheme, instead of HTTPS.
Urlpath string `mapstructure:"urlpath"` // Path for the log exporter, if not defined /v1/logs will be used
Headers []string `mapstructure:"headers"`
Protocol string `mapstructure:"protocol"` // Protocol for the log exporter, http or grpc
Level string `mapstructure:"level"` // Logging level
Output string `mapstructure:"output"` // Logging output format, e.g., text, json
Enabled bool `mapstructure:"enabled"` // Whether logging collection is enabled
Exporter string `mapstructure:"exporter"` // Exporter for log data
Endpoint string `mapstructure:"endpoint"` // Endpoint for the log exporter
Insecure bool `mapstructure:"insecure"` // Connect to the collector using the HTTP scheme, instead of HTTPS.
Urlpath string `mapstructure:"urlpath"` // Path for the log exporter, if not defined /v1/logs will be used
Headers []string `mapstructure:"headers"`
Protocol string `mapstructure:"protocol"` // Protocol for the log exporter, http or grpc
ServiceName string `mapstructure:"service_name"` // Override the service name reported by the exporter (default: "permify")
}

// Tracer contains configuration for distributed tracing.
Tracer struct {
Enabled bool `mapstructure:"enabled"` // Whether tracing collection is enabled
Exporter string `mapstructure:"exporter"` // Exporter for tracing data
Endpoint string `mapstructure:"endpoint"` // Endpoint for the tracing exporter
Insecure bool `mapstructure:"insecure"` // Connect to the collector using the HTTP scheme, instead of HTTPS.
Urlpath string `mapstructure:"urlpath"` // Path for the tracing exporter, if not defined /v1/trace will be used
Headers []string `mapstructure:"headers"`
Protocol string `mapstructure:"protocol"` // Protocol for the tracing exporter, http or grpc
Enabled bool `mapstructure:"enabled"` // Whether tracing collection is enabled
Exporter string `mapstructure:"exporter"` // Exporter for tracing data
Endpoint string `mapstructure:"endpoint"` // Endpoint for the tracing exporter
Insecure bool `mapstructure:"insecure"` // Connect to the collector using the HTTP scheme, instead of HTTPS.
Urlpath string `mapstructure:"urlpath"` // Path for the tracing exporter, if not defined /v1/trace will be used
Headers []string `mapstructure:"headers"`
Protocol string `mapstructure:"protocol"` // Protocol for the tracing exporter, http or grpc
ServiceName string `mapstructure:"service_name"` // Override the service name reported by the exporter (default: "permify")
}

// Meter contains configuration for metrics collection and reporting.
Meter struct {
Enabled bool `mapstructure:"enabled"` // Whether metrics collection is enabled
Exporter string `mapstructure:"exporter"` // Exporter for metrics data
Endpoint string `mapstructure:"endpoint"` // Endpoint for the metrics exporter
Insecure bool `mapstructure:"insecure"` // Connect to the collector using the HTTP scheme, instead of HTTPS.
Urlpath string `mapstructure:"urlpath"` // Path for the metrics exporter, if not defined /v1/metrics will be used
Headers []string `mapstructure:"headers"`
Interval int `mapstructure:"interval"`
Protocol string `mapstructure:"protocol"` // Protocol for the metrics exporter, http or grpc
Enabled bool `mapstructure:"enabled"` // Whether metrics collection is enabled
Exporter string `mapstructure:"exporter"` // Exporter for metrics data
Endpoint string `mapstructure:"endpoint"` // Endpoint for the metrics exporter
Insecure bool `mapstructure:"insecure"` // Connect to the collector using the HTTP scheme, instead of HTTPS.
Urlpath string `mapstructure:"urlpath"` // Path for the metrics exporter, if not defined /v1/metrics will be used
Headers []string `mapstructure:"headers"`
Interval int `mapstructure:"interval"`
Protocol string `mapstructure:"protocol"` // Protocol for the metrics exporter, http or grpc
ServiceName string `mapstructure:"service_name"` // Override the service name reported by the exporter (default: "permify")
}

// Service contains configuration for various service-level features.
Expand Down Expand Up @@ -308,24 +311,27 @@ func DefaultConfig() *Config {
Enabled: false,
},
Log: Log{
Level: "info",
Enabled: false,
Exporter: "otlp",
Headers: []string{},
Protocol: "http",
Level: "info",
Enabled: false,
Exporter: "otlp",
Headers: []string{},
Protocol: "http",
ServiceName: "permify",
},
Tracer: Tracer{
Enabled: false,
Headers: []string{},
Protocol: "http",
Enabled: false,
Headers: []string{},
Protocol: "http",
ServiceName: "permify",
},
Meter: Meter{
Enabled: false,
Exporter: "otlp",
Endpoint: "telemetry.permify.co",
Headers: []string{},
Interval: 300,
Protocol: "http",
Enabled: false,
Exporter: "otlp",
Endpoint: "telemetry.permify.co",
Headers: []string{},
Interval: 300,
Protocol: "http",
ServiceName: "permify",
},
Service: Service{
CircuitBreaker: false,
Expand Down
33 changes: 33 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,39 @@ logger:
assert.Equal(t, "debug", cfg.Log.Level) // Log level
}

func TestDefaultConfig_ServiceName(t *testing.T) {
cfg := DefaultConfig()
assert.Equal(t, "permify", cfg.Tracer.ServiceName)
assert.Equal(t, "permify", cfg.Meter.ServiceName)
assert.Equal(t, "permify", cfg.Log.ServiceName)
}

func TestNewConfigWithFile_ServiceName(t *testing.T) {
configContent := []byte(`
tracer:
service_name: "new-service-name"
meter:
service_name: "new-service-name"
logger:
service_name: "new-service-name"
`)

tmpDir, err := os.MkdirTemp("", "service-name-config-test")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)

tmpFile := filepath.Join(tmpDir, "config.yaml")
err = os.WriteFile(tmpFile, configContent, 0o666)
require.NoError(t, err)

cfg, err := NewConfigWithFile(tmpFile)
assert.NoError(t, err)
assert.NotNil(t, cfg)
assert.Equal(t, "new-service-name", cfg.Tracer.ServiceName)
assert.Equal(t, "new-service-name", cfg.Meter.ServiceName)
assert.Equal(t, "new-service-name", cfg.Log.ServiceName)
}

// TestNewConfigWithFile_InvalidConfig tests invalid config handling
func TestNewConfigWithFile_InvalidConfig(t *testing.T) { // Test invalid config
configContent := []byte(`
Expand Down
Loading
Loading