Skip to content

fix(database_observability.postgres): Use of defer in explain_plans collector - #6819

Open
cristiangreco wants to merge 2 commits into
mainfrom
cristian/dbo11y-pg-explainplan-fix-defer
Open

fix(database_observability.postgres): Use of defer in explain_plans collector#6819
cristiangreco wants to merge 2 commits into
mainfrom
cristian/dbo11y-pg-explainplan-fix-defer

Conversation

@cristiangreco

@cristiangreco cristiangreco commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Brief description of Pull Request

Fix explain_plans collector so that a cached query is finalised immediately instead of being deferred (which prevented correct update of processedCount and thus made batch-size limit ineffective).

Pull Request Details

Followup from #6804 (comment)

Issue(s) fixed by this Pull Request

n.a.

Notes to the Reviewer

PR Checklist

  • Documentation added
  • Tests updated
  • Config converters updated
  • This pull request was substantially generated with AI assistance (see the GenAI policy)

…tgres

Fix `explain_plans` collector so that a cached query is finalised
immediately instead of being deferred (which prevented correct update
of processedCount and thus made batch-size limit ineffective).
Copilot AI lite review requested due to automatic review settings August 4, 2026 13:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes database_observability.postgres explain plan collection so the batch-size limit is enforced correctly by finalizing each cached query immediately (instead of deferring cache cleanup / accounting until the end of fetchExplainPlans).

Changes:

  • Replace per-iteration defer cleanup with immediate per-query finalization and processedCount increment.
  • Extract per-query processing logic into processExplainPlan and return a denylist decision to the caller.

Comment thread internal/component/database_observability/postgres/collector/explain_plans.go Outdated
Comment thread internal/component/database_observability/postgres/collector/explain_plans.go Outdated
Copilot AI review requested due to automatic review settings August 4, 2026 14:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

internal/component/database_observability/postgres/collector/explain_plans.go:626

  • This error log uses c.logger, which drops the per-query context (query_id/datname) already attached to the local logger. Logging via logger helps operational debugging when Loki output emission fails.
	if err := c.sendExplainPlansOutput(
		qi.datname,
		qi.queryId,
		generatedAt,
		database_observability.ExplainProcessingResultSuccess,
		"",
		explainPlanOutput,
	); err != nil {
		c.logger.Error("failed to send explain plan output", "err", err)
	}

internal/component/database_observability/postgres/collector/explain_plans.go:538

  • This log line uses c.logger even though a request-scoped logger with query_id context is already available. Using logger here makes the error easier to correlate to the specific query being processed.

This issue also appears on line 617 of the same file.

	if strings.HasSuffix(qi.queryText, "...") {
		err := c.sendExplainPlansOutput(
			qi.datname,
			qi.queryId,
			generatedAt,
			database_observability.ExplainProcessingResultSkipped,
			"query is truncated",
			nil,
		)
		if err != nil {
			c.logger.Error("failed to send truncated query skip explain plan output", "err", err)
		}

@cristiangreco
cristiangreco marked this pull request as ready for review August 5, 2026 09:54
@cristiangreco
cristiangreco requested a review from a team as a code owner August 5, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants