Skip to content

Commit

Permalink
database_observability: pass op and instance as labels in loki.En…
Browse files Browse the repository at this point in the history
…try (#2647)

database_observability: pass `op` and `instance` as labels in loki.Entry

Move these fields to labels in loki.Entry, to allow indexing and
relabeling.
  • Loading branch information
cristiangreco authored Feb 10, 2025
1 parent 6366c18 commit 10a61cb
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 161 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Main (unreleased)
- Added table columns parsing (@cristiagreco)
- Add enable/disable collector configurability to `database_observability.mysql`. This removes the `query_samples_enabled` argument, now configurable via enable/disable collector. (@fridgepoet)
- Refactor cache config in schema_table collector (@cristiangreco)
- Use labels for some indexed logs elements (@cristiangreco)

### Bugfixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,33 @@ func (c *QuerySample) fetchQuerySamples(ctx context.Context) error {
}

c.entryHandler.Chan() <- loki.Entry{
Labels: model.LabelSet{"job": database_observability.JobName},
Labels: model.LabelSet{
"job": database_observability.JobName,
"op": OP_QUERY_SAMPLE,
"instance": model.LabelValue(c.instanceKey),
},
Entry: logproto.Entry{
Timestamp: time.Unix(0, time.Now().UnixNano()),
Line: fmt.Sprintf(
`level=info msg="query samples fetched" op="%s" instance="%s" schema="%s" digest="%s" query_type="%s" query_sample_seen="%s" query_sample_timer_wait="%s" query_sample_redacted="%s"`,
OP_QUERY_SAMPLE, c.instanceKey, schemaName, digest, c.stmtType(stmt), sampleSeen, sampleTimerWait, sampleRedactedText,
`level=info msg="query samples fetched" schema="%s" digest="%s" query_type="%s" query_sample_seen="%s" query_sample_timer_wait="%s" query_sample_redacted="%s"`,
schemaName, digest, c.stmtType(stmt), sampleSeen, sampleTimerWait, sampleRedactedText,
),
},
}

tables := c.tablesFromQuery(digest, stmt)
for _, table := range tables {
c.entryHandler.Chan() <- loki.Entry{
Labels: model.LabelSet{"job": database_observability.JobName},
Labels: model.LabelSet{
"job": database_observability.JobName,
"op": OP_QUERY_PARSED_TABLE_NAME,
"instance": model.LabelValue(c.instanceKey),
},
Entry: logproto.Entry{
Timestamp: time.Unix(0, time.Now().UnixNano()),
Line: fmt.Sprintf(
`level=info msg="table name parsed" op="%s" instance="%s" schema="%s" digest="%s" table="%s"`,
OP_QUERY_PARSED_TABLE_NAME, c.instanceKey, schemaName, digest, table,
`level=info msg="table name parsed" schema="%s" digest="%s" table="%s"`,
schemaName, digest, table,
),
},
}
Expand Down
Loading

0 comments on commit 10a61cb

Please sign in to comment.