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

[DPE-3593] Only check config values against the DB in on_config_changed #395

Merged
merged 4 commits into from
Mar 14, 2024

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Mar 11, 2024

_validate_config_options connecting to the database will be done only in on_config_changed

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 81.06%. Comparing base (1bc4f24) to head (8c68612).

Files Patch % Lines
src/charm.py 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #395      +/-   ##
==========================================
+ Coverage   80.83%   81.06%   +0.22%     
==========================================
  Files          10       10              
  Lines        2244     2250       +6     
  Branches      362      362              
==========================================
+ Hits         1814     1824      +10     
+ Misses        356      351       -5     
- Partials       74       75       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/charm.py Outdated Show resolved Hide resolved
@dragomirp dragomirp marked this pull request as ready for review March 12, 2024 04:00
Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

I believe idea of hardcoding option values in charm code is a bad idea, but it is a Marcelo call as PostgreSQL Lead here. I believe it is to create a quick fix for the customer and find a time to invent the proper fix.

BTW, I believe we should check them on config_update event only and defer if PostgreSQL is not running.

@dragomirp dragomirp marked this pull request as draft March 13, 2024 12:57
Comment on lines +869 to +870
logger.debug("Defer on_config_changed: cluster not initialised yet")
event.defer()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deferring, because otherwise we'll never validate the config.

Copy link
Contributor

Choose a reason for hiding this comment

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

Curiosity question to simplify the code:
can we improve the ops lib to print DEBUG message if defer() got comment?
It will be only:

event.defer("Defer on_config_changed: cluster not initialized yet")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A reason message could potentially be added in https://github.com/canonical/operator/blob/main/ops/framework.py#L244.

Comment on lines +881 to +884
except psycopg2.OperationalError:
logger.debug("Defer on_config_changed: Cannot connect to database")
event.defer()
return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If can't connect, defer

not in self.postgresql.get_postgresql_text_search_configs()
):
raise Exception(
raise ValueError(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switching to ValueError to resuse the handler for config blocking

@dragomirp dragomirp marked this pull request as ready for review March 13, 2024 23:18
@dragomirp dragomirp changed the title [DPE-3593] Don't check the DB if config values are the defaults [DPE-3593] Only check config values against the DB in on_config_changed Mar 13, 2024
Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

I like it. The final works to Marcelo. Tnx!

Comment on lines +869 to +870
logger.debug("Defer on_config_changed: cluster not initialised yet")
event.defer()
Copy link
Contributor

Choose a reason for hiding this comment

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

Curiosity question to simplify the code:
can we improve the ops lib to print DEBUG message if defer() got comment?
It will be only:

event.defer("Defer on_config_changed: cluster not initialized yet")

Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

LGTM!

@dragomirp dragomirp merged commit 3091be5 into main Mar 14, 2024
49 checks passed
@dragomirp dragomirp deleted the dpe-3593-reduce-config-queries branch March 14, 2024 17:56
BON4 pushed a commit to BON4/postgresql-operator that referenced this pull request Apr 23, 2024
…ed (canonical#395)

* Don't check the DB if config values are the defaults

* Unit test

* Move config DB validation in _on_config_changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants