Skip to content

feat(postgres): Log table name with pg errors#5552

Merged
kodiakhq[bot] merged 3 commits intocloudquery:mainfrom
erezrokah:feat/log_table_name_error
Dec 12, 2022
Merged

feat(postgres): Log table name with pg errors#5552
kodiakhq[bot] merged 3 commits intocloudquery:mainfrom
erezrokah:feat/log_table_name_error

Conversation

@erezrokah
Copy link
Copy Markdown
Member

Summary

The Error() string method of PgError doesn't return the table name. This PR ensures we log the table name with the error reported:
https://github.com/jackc/pgconn/blob/4c048d40d859bbb702bff9b46cfefd44b89d82c1/errors.go#L52

@erezrokah erezrokah requested review from a team and hermanschaaf and removed request for a team December 12, 2022 15:44
@erezrokah erezrokah force-pushed the feat/log_table_name_error branch from 7a53bcc to f35d199 Compare December 12, 2022 15:48
}
atomic.AddUint64(&c.metrics.Errors, 1)
c.logger.Error().Err(err).Msgf("failed to execute batch with pgerror")
c.logger.Error().Err(&pgErrorWrap{PgError: pgErr}).Msg("failed to execute batch with pgerror")
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.

Suggested change
c.logger.Error().Err(&pgErrorWrap{PgError: pgErr}).Msg("failed to execute batch with pgerror")
c.logger.Error().Err(err).Str("table", table.Name).Msg("failed to execute batch with pgerror")

Would something like this not achieve the goal of adding the table name to the error log?

Copy link
Copy Markdown
Member Author

@erezrokah erezrokah Dec 12, 2022

Choose a reason for hiding this comment

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

I don't think so, as we only send the batch if batch.Len() >= c.batchSize so if we take the table name from the loop it will print the last table and not necessarily the one generated the error.

But I'll add the table name as a log field instead of a string

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.

Ah okay I see - but yeah having it as a log field sounds good 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 0eecc4a

@erezrokah erezrokah force-pushed the feat/log_table_name_error branch from f35d199 to 394f9cd Compare December 12, 2022 15:51
@erezrokah erezrokah added the automerge Automatically merge once required checks pass label Dec 12, 2022
@kodiakhq kodiakhq bot merged commit ee90823 into cloudquery:main Dec 12, 2022
kodiakhq bot pushed a commit that referenced this pull request Dec 13, 2022
🤖 I have created a release *beep* *boop*
---


## [1.8.0](plugins-destination-postgresql-v1.7.17...plugins-destination-postgresql-v1.8.0) (2022-12-13)


### Features

* **postgres:** Log table name with pg errors ([#5552](#5552)) ([ee90823](ee90823))


### Bug Fixes

* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.11.1 ([#5458](#5458)) ([58b7432](58b7432))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.11.2 ([#5497](#5497)) ([c1876cf](c1876cf))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.12.0 ([#5539](#5539)) ([fb71293](fb71293))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
yevgenypats pushed a commit that referenced this pull request Dec 13, 2022

#### Summary

The `Error() string` method of  `PgError` doesn't return the table name. This PR ensures we log the table name with the error reported:
https://github.com/jackc/pgconn/blob/4c048d40d859bbb702bff9b46cfefd44b89d82c1/errors.go#L52

<!--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Automatically merge once required checks pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants