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

Commit 70a4dc4

Browse files
authored
Old admin console in v2 api (#1224)
Another round of v2 efforts. This time the only "invasive" part is commenting out one validation which is incompatible with v2 realm. --------- Signed-off-by: Przemysław Hejman <[email protected]>
1 parent 2611770 commit 70a4dc4

File tree

13 files changed

+361
-250
lines changed

13 files changed

+361
-250
lines changed

quesma/backend_connectors/basic_sql_backend_connector.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package backend_connectors
66
import (
77
"context"
88
"database/sql"
9+
"github.com/QuesmaOrg/quesma/quesma/quesma/config"
910
quesma_api "github.com/QuesmaOrg/quesma/quesma/v2/core"
1011
)
1112

@@ -15,6 +16,7 @@ type SqlBackendConnector interface {
1516

1617
type BasicSqlBackendConnector struct {
1718
connection *sql.DB
19+
cfg *config.RelationalDbConfiguration
1820
}
1921

2022
type SqlRows struct {
@@ -37,6 +39,15 @@ func (p *SqlRows) Err() error {
3739
return p.rows.Err()
3840
}
3941

42+
func (p *BasicSqlBackendConnector) Open() error {
43+
conn, err := initDBConnection(p.cfg)
44+
if err != nil {
45+
return err
46+
}
47+
p.connection = conn
48+
return nil
49+
}
50+
4051
func (p *BasicSqlBackendConnector) GetDB() *sql.DB {
4152
return p.connection
4253
}

quesma/backend_connectors/clickhouse_backend_connector.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
44
package backend_connectors
55

66
import (
7+
"crypto/tls"
78
"database/sql"
89
"github.com/ClickHouse/clickhouse-go/v2"
10+
"github.com/QuesmaOrg/quesma/quesma/buildinfo"
11+
"github.com/QuesmaOrg/quesma/quesma/quesma/config"
912

1013
quesma_api "github.com/QuesmaOrg/quesma/quesma/v2/core"
1114
)
1215

1316
type ClickHouseBackendConnector struct {
1417
BasicSqlBackendConnector
15-
Endpoint string
18+
cfg *config.RelationalDbConfiguration
1619
}
1720

1821
func (p *ClickHouseBackendConnector) GetId() quesma_api.BackendConnectorType {
1922
return quesma_api.ClickHouseSQLBackend
2023
}
2124

2225
func (p *ClickHouseBackendConnector) Open() error {
23-
conn, err := initDBConnection()
26+
conn, err := initDBConnection(p.cfg)
2427
if err != nil {
2528
return err
2629
}
@@ -29,34 +32,46 @@ func (p *ClickHouseBackendConnector) Open() error {
2932
}
3033

3134
// func initDBConnection(c *config.QuesmaConfiguration, tlsConfig *tls.Config) *sql.DB {
32-
func initDBConnection() (*sql.DB, error) {
33-
options := clickhouse.Options{Addr: []string{"localhost:9000"}}
35+
func initDBConnection(c *config.RelationalDbConfiguration) (*sql.DB, error) {
36+
options := clickhouse.Options{Addr: []string{c.Url.Host}}
37+
if c.User != "" || c.Password != "" || c.Database != "" {
38+
39+
options.Auth = clickhouse.Auth{
40+
Username: c.User,
41+
Password: c.Password,
42+
Database: c.Database,
43+
}
44+
}
45+
if !c.DisableTLS {
46+
options.TLS = &tls.Config{InsecureSkipVerify: true} // TODO this should be changed according to `connection.go` (more or less)
47+
}
48+
3449
info := struct {
3550
Name string
3651
Version string
3752
}{
3853
Name: "quesma",
39-
Version: "NEW ODD VERSION", //buildinfo.Version,
54+
Version: buildinfo.Version,
4055
}
56+
4157
options.ClientInfo.Products = append(options.ClientInfo.Products, info)
4258
return clickhouse.OpenDB(&options), nil
4359

4460
}
4561

46-
func NewClickHouseBackendConnector(endpoint string) *ClickHouseBackendConnector {
62+
func NewClickHouseBackendConnector(configuration *config.RelationalDbConfiguration) *ClickHouseBackendConnector {
4763
return &ClickHouseBackendConnector{
48-
Endpoint: endpoint,
64+
cfg: configuration,
4965
}
5066
}
5167

5268
// NewClickHouseBackendConnectorWithConnection bridges the gap between the ClickHouseBackendConnector and the sql.DB
5369
// so that it is can be used in pre-v2 code. Should be removed when moving forwards.
54-
func NewClickHouseBackendConnectorWithConnection(endpoint string, conn *sql.DB) *ClickHouseBackendConnector {
70+
func NewClickHouseBackendConnectorWithConnection(_ string, conn *sql.DB) *ClickHouseBackendConnector {
5571
return &ClickHouseBackendConnector{
5672
BasicSqlBackendConnector: BasicSqlBackendConnector{
5773
connection: conn,
5874
},
59-
Endpoint: endpoint,
6075
}
6176
}
6277

quesma/backend_connectors/elasticsearch_backend_connector.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ElasticsearchBackendConnector struct {
2828
config config.ElasticsearchConfiguration
2929
}
3030

31+
// NewElasticsearchBackendConnector is a constructor which uses old (v1) configuration object
3132
func NewElasticsearchBackendConnector(cfg config.ElasticsearchConfiguration) *ElasticsearchBackendConnector {
3233
conn := &ElasticsearchBackendConnector{
3334
config: cfg,
@@ -41,6 +42,24 @@ func NewElasticsearchBackendConnector(cfg config.ElasticsearchConfiguration) *El
4142
return conn
4243
}
4344

45+
// NewElasticsearchBackendConnectorFromDbConfig is an alternative constructor which uses the generic database configuration object
46+
func NewElasticsearchBackendConnectorFromDbConfig(cfg config.RelationalDbConfiguration) *ElasticsearchBackendConnector {
47+
conn := &ElasticsearchBackendConnector{
48+
config: config.ElasticsearchConfiguration{
49+
Url: cfg.Url,
50+
User: cfg.User,
51+
Password: cfg.Password,
52+
},
53+
client: &http.Client{
54+
Transport: &http.Transport{
55+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
56+
},
57+
Timeout: esRequestTimeout,
58+
},
59+
}
60+
return conn
61+
}
62+
4463
func (e *ElasticsearchBackendConnector) InstanceName() string {
4564
return "elasticsearch" // TODO return name from config
4665
}
@@ -84,8 +103,12 @@ func (e *ElasticsearchBackendConnector) Send(r *http.Request) (*http.Response, e
84103
r.URL.Host = e.config.Url.Host
85104
r.URL.Scheme = e.config.Url.Scheme
86105
r.RequestURI = "" // this is important for the request to be sent correctly to a different host
87-
maybeAuthdReq := elasticsearch.AddBasicAuthIfNeeded(r, e.config.User, e.config.Password)
88-
return e.client.Do(maybeAuthdReq)
106+
if r.Header.Get("Authorization") == "" {
107+
maybeAuthdReq := elasticsearch.AddBasicAuthIfNeeded(r, e.config.User, e.config.Password)
108+
return e.client.Do(maybeAuthdReq)
109+
} else { // request already came with auth header so just forward these credentials
110+
return e.client.Do(r)
111+
}
89112
}
90113

91114
func (e *ElasticsearchBackendConnector) GetId() quesma_api.BackendConnectorType {

quesma/clickhouse/table_discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (td *tableDiscovery) notifyObservers() {
155155

156156
msg := types.ReloadMessage{Timestamp: time.Now()}
157157
for _, observer := range td.reloadObservers {
158-
fmt.Println("Sending message to observer", observer)
158+
logger.Info().Msgf("Sending message to observer %v", observer)
159159
go func() {
160160
observer <- msg
161161
}()

quesma/frontend_connectors/elasticsearch_ingest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ type ElasticsearchIngestFrontendConnector struct {
1515
*BasicHTTPFrontendConnector
1616
}
1717

18-
func NewElasticsearchIngestFrontendConnector(endpoint string, cfg *config.QuesmaConfiguration) *ElasticsearchIngestFrontendConnector {
18+
func NewElasticsearchIngestFrontendConnector(endpoint string, esCfg config.ElasticsearchConfiguration, disableAuth bool) *ElasticsearchIngestFrontendConnector {
1919

20-
basicHttpFrontendConnector := NewBasicHTTPFrontendConnector(endpoint, cfg)
20+
basicHttpFrontendConnector := NewBasicHTTPFrontendConnector(endpoint, &config.QuesmaConfiguration{Elasticsearch: esCfg, DisableAuth: disableAuth})
2121
basicHttpFrontendConnector.responseMutator = func(w http.ResponseWriter) http.ResponseWriter {
2222
w.Header().Set("Content-Type", "application/json")
2323
return w

quesma/frontend_connectors/elasticsearch_query.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ type ElasticsearchQueryFrontendConnector struct {
1515
*BasicHTTPFrontendConnector
1616
}
1717

18-
func NewElasticsearchQueryFrontendConnector(endpoint string, cfg *config.QuesmaConfiguration) *ElasticsearchQueryFrontendConnector {
19-
20-
basicHttpFrontendConnector := NewBasicHTTPFrontendConnector(endpoint, cfg)
18+
func NewElasticsearchQueryFrontendConnector(endpoint string, esCfg config.ElasticsearchConfiguration, disableAuth bool) *ElasticsearchQueryFrontendConnector {
19+
// The esCfg is here only for F/E auth purposes and should probably not be wrapped againa in `config.QuesmaConfiguration`
20+
basicHttpFrontendConnector := NewBasicHTTPFrontendConnector(endpoint, &config.QuesmaConfiguration{Elasticsearch: esCfg, DisableAuth: disableAuth})
2121
basicHttpFrontendConnector.responseMutator = func(w http.ResponseWriter) http.ResponseWriter {
2222
w.Header().Set("Content-Type", "application/json")
2323
return w

quesma/processors/es_to_ch_common/common.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"github.com/QuesmaOrg/quesma/quesma/clickhouse"
99
"github.com/QuesmaOrg/quesma/quesma/common_table"
1010
"github.com/QuesmaOrg/quesma/quesma/ingest"
11+
"github.com/QuesmaOrg/quesma/quesma/logger"
1112
"github.com/QuesmaOrg/quesma/quesma/persistence"
1213
"github.com/QuesmaOrg/quesma/quesma/quesma/config"
1314
"github.com/QuesmaOrg/quesma/quesma/quesma/ui"
1415
"github.com/QuesmaOrg/quesma/quesma/schema"
1516
"github.com/QuesmaOrg/quesma/quesma/table_resolver"
17+
"github.com/QuesmaOrg/quesma/quesma/telemetry"
1618
quesma_api "github.com/QuesmaOrg/quesma/quesma/v2/core"
1719
"github.com/ucarion/urlpath"
1820
"net/http"
@@ -98,9 +100,11 @@ type LegacyQuesmaDependencies struct {
98100
TableDiscovery clickhouse.TableDiscovery
99101
SchemaRegistry schema.Registry
100102
TableResolver table_resolver.TableResolver
101-
Adminconsole *ui.QuesmaManagementConsole
103+
UIConsole *ui.QuesmaManagementConsole
102104
AbTestingController *sender.SenderCoordinator
103105
IngestProcessor *ingest.IngestProcessor
106+
LogManager clickhouse.LogManagerIFace
107+
LogChan <-chan logger.LogWithLevel
104108
}
105109

106110
func newLegacyQuesmaDependencies(
@@ -113,6 +117,9 @@ func newLegacyQuesmaDependencies(
113117
tableResolver table_resolver.TableResolver,
114118
abTestingController *sender.SenderCoordinator,
115119
ingestProcessor *ingest.IngestProcessor,
120+
logManager clickhouse.LogManagerIFace,
121+
logChan <-chan logger.LogWithLevel,
122+
uiConsole *ui.QuesmaManagementConsole,
116123
) *LegacyQuesmaDependencies {
117124
return &LegacyQuesmaDependencies{
118125
DependenciesImpl: baseDependencies,
@@ -124,21 +131,27 @@ func newLegacyQuesmaDependencies(
124131
TableResolver: tableResolver,
125132
AbTestingController: abTestingController,
126133
IngestProcessor: ingestProcessor,
134+
LogManager: logManager,
135+
LogChan: logChan,
136+
UIConsole: uiConsole,
127137
}
128138
}
129139

130-
func InitializeLegacyQuesmaDependencies(baseDeps *quesma_api.DependenciesImpl, oldQuesmaConfig *config.QuesmaConfiguration) *LegacyQuesmaDependencies {
140+
func InitializeLegacyQuesmaDependencies(baseDeps *quesma_api.DependenciesImpl, oldQuesmaConfig *config.QuesmaConfiguration, logChan <-chan logger.LogWithLevel) *LegacyQuesmaDependencies {
131141
connectionPool := clickhouse.InitDBConnectionPool(oldQuesmaConfig)
132142
virtualTableStorage := persistence.NewElasticJSONDatabase(oldQuesmaConfig.Elasticsearch, common_table.VirtualTableElasticIndexName)
133143
tableDisco := clickhouse.NewTableDiscovery(oldQuesmaConfig, connectionPool, virtualTableStorage)
134144
schemaRegistry := schema.NewSchemaRegistry(clickhouse.TableDiscoveryTableProviderAdapter{TableDiscovery: tableDisco}, oldQuesmaConfig, clickhouse.SchemaTypeAdapter{})
135145
schemaRegistry.Start()
136146
dummyTableResolver := table_resolver.NewDummyTableResolver(oldQuesmaConfig.IndexConfig, oldQuesmaConfig.UseCommonTableForWildcard)
147+
//phoneHomeAgent := baseDeps.PhoneHomeAgent() //TODO perhaps remove? we could get away with Client if not the UI console. Because of that we have to use Agent
148+
phoneHomeAgent := telemetry.NewPhoneHomeAgent(oldQuesmaConfig, connectionPool, "DuMMY_CLIENT_ID")
149+
phoneHomeAgent.Start()
137150

138151
ingestProcessor := ingest.NewIngestProcessor(
139152
oldQuesmaConfig,
140153
connectionPool,
141-
baseDeps.PhoneHomeAgent(),
154+
phoneHomeAgent,
142155
tableDisco,
143156
schemaRegistry,
144157
virtualTableStorage,
@@ -149,6 +162,12 @@ func InitializeLegacyQuesmaDependencies(baseDeps *quesma_api.DependenciesImpl, o
149162
abTestingController := sender.NewSenderCoordinator(oldQuesmaConfig, ingestProcessor)
150163
abTestingController.Start()
151164

152-
legacyDependencies := newLegacyQuesmaDependencies(*baseDeps, oldQuesmaConfig, connectionPool, *virtualTableStorage, tableDisco, schemaRegistry, dummyTableResolver, abTestingController, ingestProcessor)
165+
logManager := clickhouse.NewEmptyLogManager(oldQuesmaConfig, connectionPool, phoneHomeAgent, tableDisco)
166+
logManager.Start()
167+
168+
quesmaManagementConsole := ui.NewQuesmaManagementConsole(oldQuesmaConfig, logManager, logChan, phoneHomeAgent, schemaRegistry, dummyTableResolver)
169+
go quesmaManagementConsole.Run()
170+
171+
legacyDependencies := newLegacyQuesmaDependencies(*baseDeps, oldQuesmaConfig, connectionPool, *virtualTableStorage, tableDisco, schemaRegistry, dummyTableResolver, abTestingController, ingestProcessor, logManager, logChan, quesmaManagementConsole)
153172
return legacyDependencies
154173
}

quesma/processors/es_to_ch_query/elasticsearch_to_clickhouse_query_processor.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"github.com/QuesmaOrg/quesma/quesma/backend_connectors"
11-
"github.com/QuesmaOrg/quesma/quesma/clickhouse"
1211
"github.com/QuesmaOrg/quesma/quesma/elasticsearch"
1312
"github.com/QuesmaOrg/quesma/quesma/logger"
1413
"github.com/QuesmaOrg/quesma/quesma/processors"
@@ -70,12 +69,10 @@ func (p *ElasticsearchToClickHouseQueryProcessor) GetId() string {
7069
// which uses `quesma_api.BackendConnector` instead of `*sql.DB` for the database connection.
7170
func (p *ElasticsearchToClickHouseQueryProcessor) prepareTemporaryQueryProcessor() *quesm.QueryRunner {
7271

73-
logManager := clickhouse.NewEmptyLogManager(p.legacyDependencies.OldQuesmaConfig, p.legacyDependencies.ConnectionPool, p.legacyDependencies.PhoneHomeAgent(), p.legacyDependencies.TableDiscovery)
74-
logManager.Start()
75-
76-
queryRunner := quesm.NewQueryRunner(logManager,
72+
queryRunner := quesm.NewQueryRunner(
73+
p.legacyDependencies.LogManager,
7774
p.legacyDependencies.OldQuesmaConfig,
78-
nil,
75+
p.legacyDependencies.UIConsole,
7976
p.legacyDependencies.SchemaRegistry,
8077
p.legacyDependencies.AbTestingController.GetSender(),
8178
p.legacyDependencies.TableResolver,
@@ -270,20 +267,9 @@ func (p *ElasticsearchToClickHouseQueryProcessor) GetSupportedBackendConnectors(
270267
}
271268

272269
func findQueryTarget(index string, processorConfig config.QuesmaProcessorConfig) string {
273-
var defaultTargetFromConfig string
274-
wildcardConfig, ok := processorConfig.IndexConfig["*"]
275-
if !ok {
276-
logger.Warn().Msgf("No wildcard index config found in processor config!!")
277-
return config.ClickhouseTarget
278-
}
279-
if len(wildcardConfig.QueryTarget) == 0 {
280-
logger.Warn().Msgf("wildcard index has no target!!")
281-
return config.ClickhouseTarget
282-
}
283-
defaultTargetFromConfig = wildcardConfig.QueryTarget[0]
284270
_, found := processorConfig.IndexConfig[index]
285271
if !found {
286-
return defaultTargetFromConfig
272+
return processorConfig.DefaultTargetConnectorType
287273
} else { // per legacy syntax, if present means it's a clickhouse target
288274
return config.ClickhouseTarget
289275
}

quesma/quesma/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var (
2424
telemetryUrl = &Url{Scheme: "https", Host: "api.quesma.com", Path: "/phone-home"}
2525
)
2626

27+
func DefaultTelemetryUrl() *Url {
28+
return telemetryUrl
29+
}
30+
2731
type QuesmaConfiguration struct {
2832
// both clickhouse and hydrolix connections are going to be deprecated and everything is going to live under connector
2933
Connectors map[string]RelationalDbConfiguration

0 commit comments

Comments
 (0)