Skip to content

Commit

Permalink
Disable logging of SQL queries (#981)
Browse files Browse the repository at this point in the history
Logging every SQL query that is executed or transformer has some
performance penalty. This PR adds a flag to enable it. We should not log
queries by default.

Tracing can be enabled via conf:
```
logging:
  enableSQLTracing: true
```
  • Loading branch information
nablaone authored Nov 14, 2024
1 parent c250a90 commit d7ac5fa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 5 additions & 5 deletions quesma/ingest/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,10 @@ func (ip *IngestProcessor) execute(ctx context.Context, query string) error {
span := ip.phoneHomeAgent.ClickHouseInsertDuration().Begin()

// We log every DDL query
if strings.HasPrefix(query, "ALTER") || strings.HasPrefix(query, "CREATE") {
logger.InfoWithCtx(ctx).Msgf("DDL query execution: %s", query)
if ip.cfg.Logging.EnableSQLTracing {
if strings.HasPrefix(query, "ALTER") || strings.HasPrefix(query, "CREATE") {
logger.InfoWithCtx(ctx).Msgf("DDL query execution: %s", query)
}
}

_, err := ip.chDb.ExecContext(ctx, query)
Expand All @@ -831,9 +833,7 @@ func (ip *IngestProcessor) execute(ctx context.Context, query string) error {

func (ip *IngestProcessor) executeStatements(ctx context.Context, queries []string) error {
for _, q := range queries {
if strings.HasPrefix("ALTER", q) || strings.HasPrefix("CREATE", q) {
logger.InfoWithCtx(ctx).Msgf("DDL query execution: %s", q)
}

err := ip.execute(ctx, q)
if err != nil {
logger.ErrorWithCtx(ctx).Msgf("error executing query: %v", err)
Expand Down
1 change: 1 addition & 0 deletions quesma/quesma/config/config_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type LoggingConfiguration struct {
Level *zerolog.Level `koanf:"level"`
FileLogging bool `koanf:"fileLogging"`
RemoteLogDrainUrl *Url
EnableSQLTracing bool `koanf:"enableSQLTracing"`
}

type Pipeline struct {
Expand Down
6 changes: 4 additions & 2 deletions quesma/quesma/schema_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,10 @@ func (s *SchemaCheckPass) Transform(queries []*model.Query) ([]*model.Query, err

query.TransformationHistory.SchemaTransformers = append(query.TransformationHistory.SchemaTransformers, transformation.TransformationName)

logger.Info().Msgf(transformation.TransformationName+" triggered, input query: %s", inputQuery)
logger.Info().Msgf(transformation.TransformationName+" triggered, output query: %s", query.SelectCommand.String())
if s.cfg.Logging.EnableSQLTracing {
logger.Info().Msgf(transformation.TransformationName+" triggered, input query: %s", inputQuery)
logger.Info().Msgf(transformation.TransformationName+" triggered, output query: %s", query.SelectCommand.String())
}
}

}
Expand Down
6 changes: 5 additions & 1 deletion quesma/quesma/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,11 @@ func (q *QueryRunner) searchWorkerCommon(

for i, query := range queries {
sql := query.SelectCommand.String()
logger.InfoWithCtx(ctx).Msgf("SQL: %s", sql)

if q.cfg.Logging.EnableSQLTracing {
logger.InfoWithCtx(ctx).Msgf("SQL: %s", sql)
}

translatedQueryBody[i].Query = []byte(sql)
if query.OptimizeHints != nil {
translatedQueryBody[i].PerformedOptimizations = query.OptimizeHints.OptimizationsPerformed
Expand Down

0 comments on commit d7ac5fa

Please sign in to comment.