Skip to content

Commit

Permalink
integrate CTF TOML config for Loki (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Jan 17, 2024
1 parent 91bd1a1 commit 3ac842a
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions loki_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,9 @@ type LokiConfig struct {
MaxLineSizeTruncate bool
}

func NewEnvLokiConfig() *LokiConfig {
// DefaultLokiConfig is reasonable common settings for Loki batches
func DefaultLokiConfig() *LokiConfig {
return &LokiConfig{
TenantID: os.Getenv("LOKI_TENANT_ID"),
URL: os.Getenv("LOKI_URL"),
Token: os.Getenv("LOKI_TOKEN"),
BasicAuth: os.Getenv("LOKI_BASIC_AUTH"),
MaxErrors: 5,
BatchWait: 3 * time.Second,
BatchSize: 500 * 1024,
Expand All @@ -147,6 +144,34 @@ func NewEnvLokiConfig() *LokiConfig {
}
}

// NewEnvLokiConfig creates new config from connection params as env vars
func NewEnvLokiConfig() *LokiConfig {
d := DefaultLokiConfig()
d.TenantID = os.Getenv("LOKI_TENANT_ID")
d.URL = os.Getenv("LOKI_URL")
d.Token = os.Getenv("LOKI_TOKEN")
d.BasicAuth = os.Getenv("LOKI_BASIC_AUTH")
return d
}

// NewLokiConfig this is used when you have marshalled data from CTF
func NewLokiConfig(endpoint *string, tenant *string, basicAuth *string, token *string) *LokiConfig {
d := DefaultLokiConfig()
if endpoint != nil {
d.URL = *endpoint
}
if tenant != nil {
d.TenantID = *tenant
}
if basicAuth != nil {
d.BasicAuth = *basicAuth
}
if token != nil {
d.Token = *token
}
return d
}

// NewLokiClient creates a new Promtail client
func NewLokiClient(extCfg *LokiConfig) (*LokiClient, error) {
_, err := http.Get(extCfg.URL)
Expand Down

0 comments on commit 3ac842a

Please sign in to comment.