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

[Fixes #10537] Improve rules creation using GeoFence batch - more imp… #10585

Merged
merged 3 commits into from
Jan 26, 2023

Conversation

etj
Copy link
Contributor

@etj etj commented Jan 25, 2023

A continuation of #10538.
Replaces #10556 since it had too many conflicts.


Batch creation have been moved to caller methods (wrt previous refactoring), in order to have a single Batch containing all the operations needed for a full perm syncronization.

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

For all pull requests:

  • Confirm you have read the contribution guidelines
  • You have sent a Contribution Licence Agreement (CLA) as necessary (not required for small changes, e.g., fixing typos in the documentation)
  • Make sure the first PR targets the master branch, eventual backports will be managed later. This can be ignored if the PR is fixing an issue that only happens in a specific branch, but not in newer ones.

The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):

  • There is a ticket in https://github.com/GeoNode/geonode/issues describing the issue/improvement/feature (a notable exemption is, changes not visible to end-users)
  • The issue connected to the PR must have Labels and Milestone assigned
  • PR for bug fixes and small new features are presented as a single commit
  • Commit message must be in the form "[Fixes #<issue_number>] Title of the Issue"
  • New unit tests have been added covering the changes, unless there is an explanation on why the tests are not necessary/implemented
  • This PR passes all existing unit tests (test results will be reported by travis-ci after opening this PR)
  • This PR passes the QA checks: flake8 geonode
  • Commits changing the settings, UI, existing user workflows, or adding new functionality, need to include documentation updates
  • Commits adding new texts do use gettext and have updated .po / .mo files (without location infos)

Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.

@cla-bot cla-bot bot added the cla-signed CLA Bot: community license agreement signed label Jan 25, 2023
@etj etj self-assigned this Jan 25, 2023
@etj etj requested a review from mattiagiupponi January 25, 2023 18:39
@etj etj force-pushed the 10537-geofence-batch-advanced-2 branch from a172525 to 1263da5 Compare January 26, 2023 10:01
@etj etj force-pushed the 10537-geofence-batch-advanced-2 branch 2 times, most recently from 83f00ff to f18221d Compare January 26, 2023 11:43
@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Merging #10585 (a2c766b) into master (e440111) will increase coverage by 0.01%.
The diff coverage is 84.25%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10585      +/-   ##
==========================================
+ Coverage   62.11%   62.13%   +0.01%     
==========================================
  Files         828      828              
  Lines       51144    51174      +30     
  Branches     6554     6554              
==========================================
+ Hits        31768    31795      +27     
+ Misses      17695    17694       -1     
- Partials     1681     1685       +4     

@etj etj force-pushed the 10537-geofence-batch-advanced-2 branch from f18221d to a2c766b Compare January 26, 2023 12:43
self.api_client.client.login(username=self.user, password=self.passwd)
resp = self.api_client.get(f"{list_url + str(layer.id)}/")
self.assertValidJSONResponse(resp)
resp = self.client.get(list_url)
Copy link
Contributor

Choose a reason for hiding this comment

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

We are not performing anymore the login, is something wanted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The login is on line 157, these are some more tests as unauth user

verify=False,
)

if r.status_code not in (200, 201):
logger.debug(f"Could not insert rule: [{r.status_code}] - {r.content}")
raise GeofenceException(f"Could not insert rule: [{r.status_code}]")
logger.debug(f"Could not insert rule: [{r.status_code}] - {r.text}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since its raising an exception, it might be better to increase this log level from debug or remove it since is raising the exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually the detailed information should be logged when debugging.
It's not said that the exception message is displayed at higher level.

@@ -203,38 +207,64 @@ def add_insert_rule(self, rule: Rule):
operation.update(rule.get_object())
self.operations.append(operation)

def get_batch_length(self):
def length(self) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this a property more than a method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By leaving it as a method, it can be extended by filtering only certain types of operations

verify=False,
)

if r.status_code != 200:
logger.debug(f"Error while running batch {batch.log_name}: [{r.status_code}] - {r.content}")
logger.debug(
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be useful to increase this log level if it shows additional information than the Exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually the detailed information should be logged only when debugging


except Exception as e:
logger.debug(f"Error while requesting batch execution {batch.log_name}", exc_info=e)
logger.info(f"Error while requesting batch exec {batch.log_name}")
logger.debug(f"Error while requesting batch exec {batch.log_name} --> {batch.get_object()}", exc_info=e)
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be useful to increase this log level if it shows additional information than the Exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually the detailed information should be logged only when debugging

for r in gs_rules["rules"]:
if r["layer"] and r["layer"] == layer_name:
batch.add_delete_rule(r["id"])
cnt += 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the count provided by the batch.length() as soon as all the rules are added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No: if the delete operations are collected in an existing batch, lenght would be > than the delete operations inserted

if isinstance(_resource, Dataset):
if settings.OGC_SERVER["default"].get("GEOFENCE_SECURITY_ENABLED", False):
if settings.OGC_SERVER["default"].get("GEOFENCE_SECURITY_ENABLED", False) or getattr(
settings, "GEOFENCE_SECURITY_ENABLED", False
Copy link
Contributor

Choose a reason for hiding this comment

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

This is redundant. The GEOFENCE_SECURITY_ENABLED in the settings is used to populate the OGC_SERVER["default"]["GEOFENCE_SECURITY_ENABLED"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, tests are only setting the GEOFENCE_SECURITY_ENABLED entry, not the other one

if not created:
gf_utils.collect_delete_layer_rules(workspace, _resource.name, batch)

exist_geolimits = None
Copy link
Contributor

Choose a reason for hiding this comment

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

i would suggest to have it as "False" and not None since the name say "exists"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need the 3 different values:

  • true -> limit exists
  • false -> limit does not exist
  • None -> not computed

@etj etj marked this pull request as ready for review January 26, 2023 15:07
@afabiani afabiani merged commit 36f414d into master Jan 26, 2023
@afabiani afabiani deleted the 10537-geofence-batch-advanced-2 branch January 26, 2023 15:32
@afabiani afabiani added this to the 4.1.0 milestone Jan 26, 2023
github-actions bot pushed a commit that referenced this pull request Jan 26, 2023
#10585)

* [Code Formatting] Revert formatting on conflicting files

* [Fixes #10537] Improve rules creation using GeoFence batch - more improvements

* [#10574] Align code formatting with black

Co-authored-by: afabiani <alessio.fabiani@geosolutionsgroup.com>
(cherry picked from commit 36f414d)
afabiani pushed a commit that referenced this pull request Jan 26, 2023
#10585) (#10588)

* [Code Formatting] Revert formatting on conflicting files

* [Fixes #10537] Improve rules creation using GeoFence batch - more improvements

* [#10574] Align code formatting with black

Co-authored-by: afabiani <alessio.fabiani@geosolutionsgroup.com>
(cherry picked from commit 36f414d)

Co-authored-by: Emanuele Tajariol <etj@geo-solutions.it>
ridoo pushed a commit to Thuenen-GeoNode-Development/geonode that referenced this pull request Sep 18, 2023
…ore imp… (GeoNode#10585) (GeoNode#10588)

* [Code Formatting] Revert formatting on conflicting files

* [Fixes GeoNode#10537] Improve rules creation using GeoFence batch - more improvements

* [GeoNode#10574] Align code formatting with black

Co-authored-by: afabiani <alessio.fabiani@geosolutionsgroup.com>
(cherry picked from commit 36f414d)

Co-authored-by: Emanuele Tajariol <etj@geo-solutions.it>
ridoo pushed a commit to Thuenen-GeoNode-Development/geonode that referenced this pull request Feb 22, 2024
…ore imp… (GeoNode#10585) (GeoNode#10588)

* [Code Formatting] Revert formatting on conflicting files

* [Fixes GeoNode#10537] Improve rules creation using GeoFence batch - more improvements

* [GeoNode#10574] Align code formatting with black

Co-authored-by: afabiani <alessio.fabiani@geosolutionsgroup.com>
(cherry picked from commit 36f414d)

Co-authored-by: Emanuele Tajariol <etj@geo-solutions.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 4.1.x cla-signed CLA Bot: community license agreement signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants