Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 911f24a

Browse files
authored
Configuration clean up (#823)
`QuesmaConfiguration` is a configuration intermediate representation now. We can remove `koanf` annotations here to avoid any confusion.
1 parent b4eefa7 commit 911f24a

File tree

3 files changed

+44
-74
lines changed

3 files changed

+44
-74
lines changed

quesma/quesma/config/config.go

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import (
66
"fmt"
77
"github.com/hashicorp/go-multierror"
88
"github.com/knadh/koanf/parsers/yaml"
9-
"github.com/knadh/koanf/providers/env"
109
"github.com/knadh/koanf/providers/file"
1110
"github.com/knadh/koanf/v2"
12-
"github.com/rs/zerolog"
1311
"log"
1412
"os"
1513
"quesma/elasticsearch/elasticsearch_field_types"
@@ -29,58 +27,27 @@ var (
2927

3028
type QuesmaConfiguration struct {
3129
// both clickhouse and hydrolix connections are going to be deprecated and everything is going to live under connector
32-
Connectors map[string]RelationalDbConfiguration `koanf:"connectors"`
33-
TransparentProxy bool `koanf:"transparentProxy"`
34-
InstallationId string `koanf:"installationId"`
35-
LicenseKey string `koanf:"licenseKey"`
30+
Connectors map[string]RelationalDbConfiguration
31+
TransparentProxy bool
32+
InstallationId string
33+
LicenseKey string
3634
//deprecated
37-
ClickHouse RelationalDbConfiguration `koanf:"clickhouse"`
35+
ClickHouse RelationalDbConfiguration
3836
//deprecated
39-
Hydrolix RelationalDbConfiguration `koanf:"hydrolix"`
40-
Elasticsearch ElasticsearchConfiguration `koanf:"elasticsearch"`
41-
IndexConfig map[string]IndexConfiguration `koanf:"indexes"`
42-
Logging LoggingConfiguration `koanf:"logging"`
43-
PublicTcpPort network.Port `koanf:"port"`
44-
IngestStatistics bool `koanf:"ingestStatistics"`
45-
QuesmaInternalTelemetryUrl *Url `koanf:"internalTelemetryUrl"`
46-
DisableAuth bool `koanf:"disableAuth"`
37+
Hydrolix RelationalDbConfiguration
38+
Elasticsearch ElasticsearchConfiguration
39+
IndexConfig map[string]IndexConfiguration
40+
Logging LoggingConfiguration
41+
PublicTcpPort network.Port
42+
IngestStatistics bool
43+
QuesmaInternalTelemetryUrl *Url
44+
DisableAuth bool
4745
AutodiscoveryEnabled bool
4846

4947
EnableIngest bool // this is computed from the configuration 2.0
5048
CreateCommonTable bool
5149
}
5250

53-
type LoggingConfiguration struct {
54-
Path string `koanf:"path"`
55-
Level *zerolog.Level `koanf:"level"`
56-
RemoteLogDrainUrl *Url `koanf:"remoteUrl"`
57-
FileLogging bool `koanf:"fileLogging"`
58-
}
59-
60-
type RelationalDbConfiguration struct {
61-
//ConnectorName string `koanf:"name"`
62-
ConnectorType string `koanf:"type"`
63-
Url *Url `koanf:"url"`
64-
User string `koanf:"user"`
65-
Password string `koanf:"password"`
66-
Database string `koanf:"database"`
67-
AdminUrl *Url `koanf:"adminUrl"`
68-
DisableTLS bool `koanf:"disableTLS"`
69-
}
70-
71-
type OptimizerConfiguration struct {
72-
Disabled bool `koanf:"disabled"`
73-
Properties map[string]string `koanf:"properties"`
74-
}
75-
76-
func (c *RelationalDbConfiguration) IsEmpty() bool {
77-
return c != nil && c.Url == nil && c.User == "" && c.Password == "" && c.Database == ""
78-
}
79-
80-
func (c *RelationalDbConfiguration) IsNonEmpty() bool {
81-
return !c.IsEmpty()
82-
}
83-
8451
func (c *QuesmaConfiguration) AliasFields(indexName string) map[string]string {
8552
aliases := make(map[string]string)
8653
if indexConfig, found := c.IndexConfig[indexName]; found {
@@ -99,34 +66,6 @@ func MatchName(pattern, name string) bool {
9966

10067
var k = koanf.New(".")
10168

102-
func Load() QuesmaConfiguration {
103-
var config QuesmaConfiguration
104-
105-
loadConfigFile()
106-
if err := k.Load(env.Provider("QUESMA_", ".", func(s string) string {
107-
// This enables overriding config values with environment variables. It's case-sensitive, just like the YAML.
108-
// Examples:
109-
// `QUESMA_logging_level=debug` overrides `logging.level` in the config file
110-
// `QUESMA_licenseKey=arbitrary-license-key` overrides `licenseKey` in the config file
111-
return strings.Replace(strings.TrimPrefix(s, "QUESMA_"), "_", ".", -1)
112-
}), nil); err != nil {
113-
log.Fatalf("error loading config form supplied env vars: %v", err)
114-
}
115-
if err := k.Unmarshal("", &config); err != nil {
116-
log.Fatalf("error unmarshalling config: %v", err)
117-
}
118-
for name, idxConfig := range config.IndexConfig {
119-
idxConfig.Name = name
120-
config.IndexConfig[name] = idxConfig
121-
if idxConfig.SchemaOverrides != nil {
122-
for fieldName, configuration := range idxConfig.SchemaOverrides.Fields {
123-
idxConfig.SchemaOverrides.Fields[fieldName] = configuration
124-
}
125-
}
126-
}
127-
return config
128-
}
129-
13069
func loadConfigFile() {
13170
var configPath string
13271
if configFileName, isSet := os.LookupEnv(configFileLocationEnvVar); isSet {

quesma/quesma/config/config_v2.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ type QuesmaNewConfiguration struct {
5151
DisableTelemetry bool `koanf:"disableTelemetry"`
5252
}
5353

54+
type LoggingConfiguration struct {
55+
Path string `koanf:"path"`
56+
Level *zerolog.Level `koanf:"level"`
57+
RemoteLogDrainUrl *Url `koanf:"remoteUrl"`
58+
FileLogging bool `koanf:"fileLogging"`
59+
}
60+
5461
type Pipeline struct {
5562
Name string `koanf:"name"`
5663
FrontendConnectors []string `koanf:"frontendConnectors"`
@@ -75,6 +82,25 @@ type BackendConnector struct {
7582
Config RelationalDbConfiguration `koanf:"config"`
7683
}
7784

85+
type RelationalDbConfiguration struct {
86+
//ConnectorName string `koanf:"name"`
87+
ConnectorType string `koanf:"type"`
88+
Url *Url `koanf:"url"`
89+
User string `koanf:"user"`
90+
Password string `koanf:"password"`
91+
Database string `koanf:"database"`
92+
AdminUrl *Url `koanf:"adminUrl"`
93+
DisableTLS bool `koanf:"disableTLS"`
94+
}
95+
96+
func (c *RelationalDbConfiguration) IsEmpty() bool {
97+
return c != nil && c.Url == nil && c.User == "" && c.Password == "" && c.Database == ""
98+
}
99+
100+
func (c *RelationalDbConfiguration) IsNonEmpty() bool {
101+
return !c.IsEmpty()
102+
}
103+
78104
type Processor struct {
79105
Name string `koanf:"name"`
80106
Type ProcessorType `koanf:"type"`

quesma/quesma/config/index_config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ type IndexConfiguration struct {
2626
IngestTarget []string
2727
}
2828

29+
type OptimizerConfiguration struct {
30+
Disabled bool `koanf:"disabled"`
31+
Properties map[string]string `koanf:"properties"`
32+
}
33+
2934
func (c IndexConfiguration) String() string {
3035
var builder strings.Builder
3136

0 commit comments

Comments
 (0)