From 207a604c9bb7240defb539332d9bbfa91e03bcbc Mon Sep 17 00:00:00 2001 From: Runar Ask Johannessen <89020325+equinor-ruaj@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:33:13 +0200 Subject: [PATCH] Remove verbose logging (#96) --- src/fmu/sumo/uploader/_sumofile.py | 15 ++++++++++----- src/fmu/sumo/uploader/_upload_files.py | 17 +++++------------ src/fmu/sumo/uploader/caseondisk.py | 6 +----- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/fmu/sumo/uploader/_sumofile.py b/src/fmu/sumo/uploader/_sumofile.py index fe4963d..ec46dbe 100644 --- a/src/fmu/sumo/uploader/_sumofile.py +++ b/src/fmu/sumo/uploader/_sumofile.py @@ -85,8 +85,16 @@ def _upload_metadata(self, sumoclient, sumo_parent_id): def _upload_byte_string(self, sumoclient, object_id, blob_url): blobclient = BlobClient.from_blob_url(blob_url) - content_settings = ContentSettings(content_type="application/octet-stream") - response = blobclient.upload_blob(self.byte_string, blob_type="BlockBlob", length=len(self.byte_string), overwrite=True, content_settings=content_settings) + content_settings = ContentSettings( + content_type="application/octet-stream" + ) + response = blobclient.upload_blob( + self.byte_string, + blob_type="BlockBlob", + length=len(self.byte_string), + overwrite=True, + content_settings=content_settings, + ) # response has the form {'etag': '"0x8DCDC8EED1510CC"', 'last_modified': datetime.datetime(2024, 9, 24, 11, 49, 20, tzinfo=datetime.timezone.utc), 'content_md5': bytearray(b'\x1bPM3(\xe1o\xdf(\x1d\x1f\xb9Qm\xd9\x0b'), 'client_request_id': '08c962a4-7a6b-11ef-8710-acde48001122', 'request_id': 'f459ad2b-801e-007d-1977-0ef6ee000000', 'version': '2024-11-04', 'version_id': None, 'date': datetime.datetime(2024, 9, 24, 11, 49, 19, tzinfo=datetime.timezone.utc), 'request_server_encrypted': True, 'encryption_key_sha256': None, 'encryption_scope': None} # ... which is not what the caller expects, so we return something reasonable. return httpx.Response(201) @@ -99,9 +107,6 @@ def _delete_metadata(self, sumoclient, object_id): def upload_to_sumo(self, sumo_parent_id, sumoclient, sumo_mode): """Upload this file to Sumo""" - - logger.debug("Starting upload_to_sumo()") - # We need these included even if returning before blob upload result = {"blob_file_path": self.path, "blob_file_size": self._size} diff --git a/src/fmu/sumo/uploader/_upload_files.py b/src/fmu/sumo/uploader/_upload_files.py index 711b180..e95da02 100644 --- a/src/fmu/sumo/uploader/_upload_files.py +++ b/src/fmu/sumo/uploader/_upload_files.py @@ -47,10 +47,8 @@ def create_parameter_file( search_res = sumoclient.get("/search", {"$query": query}).json() if search_res["hits"]["total"]["value"] > 0: - logger.info("Parameters already uploaded") return None - logger.info("Trying to read parameters at %s", parameters_path) try: with open(config_path, "r", encoding="utf-8") as variables_yml: global_config = yaml.safe_load(variables_yml) @@ -76,14 +74,14 @@ def create_parameter_file( metadata = exd.generate_metadata(parameters) if "fmu" not in metadata: - logger.warning("No fmu section upload will fail..") + logger.warning("No fmu section in metadata. Cannot upload parameters.") + return None bytestring = json.dumps(parameters).encode("utf-8") paramfile = FileOnJob(bytestring, metadata) paramfile.metadata_path = "" paramfile.path = "" paramfile.size = len(bytestring) - logger.info("Parameters will be uploaded") return paramfile @@ -120,9 +118,7 @@ def maybe_upload_realization_and_iteration(sumoclient, base_metadata): f"/objects('{case_uuid}')", json=iteration_metadata ) - sumoclient.post( - f"/objects('{case_uuid}')", json=realization_metadata - ) + sumoclient.post(f"/objects('{case_uuid}')", json=realization_metadata) def _upload_files( @@ -149,7 +145,7 @@ def _upload_files( except Exception as e: logger.error( "Failed to upload realization and iteration objects: %s", - e.with_traceback(None) + e.with_traceback(None), ) paramfile = create_parameter_file( @@ -167,10 +163,7 @@ def _upload_files( with ThreadPoolExecutor(threads) as executor: results = executor.map( _upload_file, - [ - (file, sumoclient, sumo_parent_id, sumo_mode) - for file in files - ], + [(file, sumoclient, sumo_parent_id, sumo_mode) for file in files], ) return results diff --git a/src/fmu/sumo/uploader/caseondisk.py b/src/fmu/sumo/uploader/caseondisk.py index 21f1b2f..5cb728d 100644 --- a/src/fmu/sumo/uploader/caseondisk.py +++ b/src/fmu/sumo/uploader/caseondisk.py @@ -153,8 +153,6 @@ def register(self): sumo_parent_id (uuid4): Unique ID for this case on Sumo """ - logger.info("About to register case on Sumo") - try: sumo_parent_id = self._upload_case_metadata(self.case_metadata) self._sumo_parent_id = sumo_parent_id @@ -194,9 +192,7 @@ def register(self): def _upload_case_metadata(self, case_metadata: dict): """Upload case metadata to Sumo.""" - response = self.sumoclient.post( - path="/objects", json=case_metadata - ) + response = self.sumoclient.post(path="/objects", json=case_metadata) returned_object_id = response.json().get("objectid")