|
1 | 1 | # mypy: ignore-errors
|
2 | 2 | import copy
|
| 3 | +import json |
3 | 4 | import logging
|
4 | 5 | import os
|
5 | 6 | import re
|
|
22 | 23 | from pydantic import field_validator
|
23 | 24 | from pydantic.dataclasses import dataclass, rebuild_dataclass
|
24 | 25 |
|
| 26 | +from ert.config.parsing.context_values import ContextBoolEncoder |
25 | 27 | from ert.plugins import ErtPluginManager
|
26 | 28 | from ert.substitutions import Substitutions
|
27 | 29 |
|
@@ -911,14 +913,31 @@ def _log_config_file(cls, config_file: str, config_file_contents: str) -> None:
|
911 | 913 |
|
912 | 914 | @classmethod
|
913 | 915 | def _log_config_dict(cls, content_dict: dict[str, Any]) -> None:
|
914 |
| - tmp_dict = content_dict.copy() |
915 |
| - tmp_dict.pop("FORWARD_MODEL", None) |
916 |
| - tmp_dict.pop("LOAD_WORKFLOW", None) |
917 |
| - tmp_dict.pop("LOAD_WORKFLOW_JOB", None) |
918 |
| - tmp_dict.pop("HOOK_WORKFLOW", None) |
919 |
| - tmp_dict.pop("WORKFLOW_JOB_DIRECTORY", None) |
920 |
| - |
921 |
| - logger.info(f"Content of the config_dict: {tmp_dict}") |
| 916 | + # The content of the message is sanitized before beeing sendt to App Insigths to make sure GDPR-rules are not violated. |
| 917 | + # In doing do, the message lenght will typically increase a bit. To Avoid hiting the App Insights' hard limit of message length, the limit is set to 80% |
| 918 | + # of MAX_MESSAGE_LENGTH_APP_INSIGHTS = 32768 |
| 919 | + SAFE_MESSAGE_LENGTH_LIMIT = 26214 # <= MAX_MESSAGE_LENGTH_APP_INSIGHTS * 0.8 |
| 920 | + try: |
| 921 | + config_dict_content = json.dumps( |
| 922 | + content_dict, indent=2, cls=ContextBoolEncoder |
| 923 | + ) |
| 924 | + except Exception as err: |
| 925 | + config_dict_content = str(content_dict) |
| 926 | + logger.warning( |
| 927 | + f"Logging of config dict could not be formatted for enhanced readability. {err}" |
| 928 | + ) |
| 929 | + config_dict_content_length = len(config_dict_content) |
| 930 | + if config_dict_content_length > SAFE_MESSAGE_LENGTH_LIMIT: |
| 931 | + config_sections = _split_string_into_sections( |
| 932 | + config_dict_content, SAFE_MESSAGE_LENGTH_LIMIT |
| 933 | + ) |
| 934 | + section_count = len(config_sections) |
| 935 | + for i, section in enumerate(config_sections): |
| 936 | + logger.info( |
| 937 | + f"Content of the config_dict (part {i + 1}/{section_count}): {section}" |
| 938 | + ) |
| 939 | + else: |
| 940 | + logger.info(f"Content of the config_dict: {config_dict_content}") |
922 | 941 |
|
923 | 942 | @classmethod
|
924 | 943 | def _log_custom_forward_model_steps(cls, user_config: ConfigDict) -> None:
|
@@ -1089,6 +1108,19 @@ def _create_observations(
|
1089 | 1108 | return EnkfObs(obs_vectors, obs_time_list)
|
1090 | 1109 |
|
1091 | 1110 |
|
| 1111 | +def _split_string_into_sections(input: str, section_length: int) -> list[str]: |
| 1112 | + """ |
| 1113 | + Splits a string into sections of length section_length |
| 1114 | + and returns it as a list. |
| 1115 | +
|
| 1116 | + If section_length is set to 0 or less, no sectioning is performed and the entire input string |
| 1117 | + is returned as one section in a list |
| 1118 | + """ |
| 1119 | + if section_length < 1: |
| 1120 | + return [input] |
| 1121 | + return [input[i : i + section_length] for i in range(0, len(input), section_length)] |
| 1122 | + |
| 1123 | + |
1092 | 1124 | def _get_files_in_directory(job_path, errors):
|
1093 | 1125 | if not path.isdir(job_path):
|
1094 | 1126 | errors.append(
|
|
0 commit comments