Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ [klogs] Use maps instead of columns for custom fields #437

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

ricoberger
Copy link
Member

@ricoberger ricoberger commented Oct 11, 2022

This is a follow up for kobsio/klogs#34 were we changed the database schema for klogs to use maps instead of arrays for custom fields.

To be able to query the data ingested by the klogs plugin we had to adjust the queries to also use maps instead of columns for these fields.

// to render the distribution chart, which shows how many documents/rows are available within a bucket.
sqlQueryBuckets := fmt.Sprintf(`SELECT toStartOfInterval(timestamp, INTERVAL %d second) AS interval_data, count(*) AS count_data FROM %s.logs WHERE timestamp >= FROM_UNIXTIME(%d) AND timestamp <= FROM_UNIXTIME(%d) %s GROUP BY interval_data ORDER BY interval_data WITH FILL FROM toStartOfInterval(FROM_UNIXTIME(%d), INTERVAL %d second) TO toStartOfInterval(FROM_UNIXTIME(%d), INTERVAL %d second) STEP %d SETTINGS skip_unavailable_shards = 1`, interval, i.database, timeStart, timeEnd, conditions, timeStart, interval, timeEnd, interval, interval)
log.Debug(ctx, "SQL query buckets", zap.String("query", sqlQueryBuckets))
rowsBuckets, err := i.client.QueryContext(ctx, sqlQueryBuckets)

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources

This query depends on a [user-provided value](1). This query depends on a [user-provided value](2). This query depends on a [user-provided value](3). This query depends on a [user-provided value](4). This query depends on a [user-provided value](5). This query depends on a [user-provided value](6).
// timestamp field and limiting the results / using a offset for pagination.
sqlQueryRawLogs := fmt.Sprintf("SELECT %s FROM %s.logs WHERE (%s) %s ORDER BY %s LIMIT %d SETTINGS skip_unavailable_shards = 1", defaultColumns, i.database, timeConditions, conditions, parsedOrder, limit)
log.Debug(ctx, "SQL query raw logs", zap.String("query", sqlQueryRawLogs))
rowsRawLogs, err := i.client.QueryContext(ctx, sqlQueryRawLogs)

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources

This query depends on a [user-provided value](1). This query depends on a [user-provided value](2). This query depends on a [user-provided value](3). This query depends on a [user-provided value](4). This query depends on a [user-provided value](5). This query depends on a [user-provided value](6). This query depends on a [user-provided value](7).
@ricoberger ricoberger force-pushed the klogs-use-maps-instead-of-arrays-for-custom-fields branch 2 times, most recently from ebef360 to a128579 Compare October 12, 2022 06:08
@ricoberger ricoberger added the changelog: changed Something was changed or updated label Oct 12, 2022
@ricoberger ricoberger changed the title [klogs] Use maps instead of columns for custom fields ⚠️ [klogs] Use maps instead of columns for custom fields Oct 12, 2022
@ricoberger ricoberger marked this pull request as ready for review October 17, 2022 08:20
This is a follow up for kobsio/klogs#34 were we
changed the database schema for klogs to use maps instead of arrays for
custom fields.

To be able to query the data ingested by the klogs plugin we had to
adjust the queries to also use maps instead of columns for these fields.
@ricoberger ricoberger force-pushed the klogs-use-maps-instead-of-arrays-for-custom-fields branch from a128579 to 3c0377b Compare October 17, 2022 09:01
@ricoberger ricoberger merged commit c6edeb6 into main Oct 17, 2022
@ricoberger ricoberger deleted the klogs-use-maps-instead-of-arrays-for-custom-fields branch October 17, 2022 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: changed Something was changed or updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant