Repository navigation
feat(sinks): Add on-conflict config support to postgres sink - #26628
vaughnw128 wants to merge 6 commits into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3316fcec6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .context(PostgresSnafu)?; | ||
|
|
||
| if service.on_conflict == OnConflict::DoNothing { | ||
| let skipped = event_count.saturating_sub(result.rows_affected() as usize); |
There was a problem hiding this comment.
Exclude skipped rows from sent-event telemetry
Whenever do_nothing skips a row, this records it as discarded but leaves the original request metadata unchanged; the returned PostgresResponse consequently makes DriverResponse::events_sent increment component_sent_events_total for every input event. A four-event batch with two conflicts therefore reports four sent and two discarded even though only two rows were inserted, corrupting the sink's delivery/drop accounting; construct the response telemetry from the rows actually inserted rather than the full batch.
AGENTS.md reference: AGENTS.md:L210-L210
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed this behavior with my debugging tests
There was a problem hiding this comment.
Useful comment, but I think it doesn't make much of an impact given the reporting provided by other similar sinks. A similar behavior can be seen in the New Relic sink:
vector/src/sinks/new_relic/model.rs
Lines 115 to 118 in 5606b68
…tor into postgres-sink-on-conflict
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f4f4a127a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
thank you chibi robo |
Summary
This PR aims to allow Vector's Postgres sink to gracefully handle inserts of duplicate keys. Currently, this creates an error and creates difficult failure cases where entire batches error and we lose events. We heavily use Vector to ingest S3 data through SQS into Postgres, but are somewhat unable to properly use Vector's end-to-end acknowledgements as this would re-trigger on inserts that we want to disregard. Since Vector's use of (and Postgres's limitations around jsonb_populate_recordset don't allow for automatic ID population, we have to insert these earlier in the process which causes the conflict issues.
I understand this enhancement may be rejected as I'm unsure whether it's an intentional limitation or not. I checked existing issues and PRs and could not find anything!
References
Related: #26304
Vector configuration
To debug these changes, this config can be used:
events.jsonl:
{"id": 1, "message": "already in the table, conflicts with the row from setup.sql"} {"id": 2, "message": "new row in the same batch as a conflict"} {"id": 3, "message": "new row"} {"id": 3, "message": "in-batch duplicate of the previous line"} {"id": 4, "message": "second batch, no conflicts"} {"id": 5, "message": "second batch, no conflicts"} {"id": 6, "message": "second batch, no conflicts"} {"id": 7, "message": "second batch, no conflicts"}config.yaml:
db.sql:
How did you test this PR?
This PR was tested by building the diff in CI as an image and using it in our testing pipelines to ensure the feature was functional and stable. It was built with the isolated change off of the base at 0.59.0, and was run in Kubernetes via a custom helm chart. The vector config used transforms unformatted JSON into a "pg" Json blob and then assigns it to the database column names. These rows are then inserted with the following sink config:
Does this PR include user facing changes?
no-changeloglabel to this PR.