Skip to content

Commit 45d72bf

Browse files
committed
Reintroduce insensitive useful logs
We have removed logging of observations and shapes, but we are still interested in what summary keywords are being used and what shape configs are being used. This change will log the keywords without logging wellnames or other attributes from the observations. Also split logs into multiple logs and improve formatting to make logs easier to query. (cherry picked from commit 8e32696)
1 parent 99655cf commit 45d72bf

3 files changed

Lines changed: 82 additions & 10 deletions

File tree

src/ert/config/ert_config.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,13 @@ def create_list_of_forward_model_steps_to_run(
772772
return fm_steps
773773

774774

775+
def log_shape_registry(shape_registry: ShapeRegistry) -> None:
776+
shape_count = Counter(
777+
type(shape).__name__ for shape in shape_registry.shapes.values()
778+
)
779+
logger.info(f"Count of shapes in ShapeRegistry: {dict(shape_count)}")
780+
781+
775782
def log_observation_keys(
776783
observations: list[ObservationDict],
777784
) -> None:
@@ -782,12 +789,14 @@ def log_observation_keys(
782789
for key in o
783790
if key not in {"name", "type"}
784791
)
785-
786-
logger.info(
787-
f"Count of observation types:\n\t{dict(observation_type_counts)}\n"
788-
f"Count of observation keywords:\n\t{dict(observation_keyword_counts)}"
792+
observation_summary_keys = Counter(
793+
o["KEY"].split(":")[0] for o in observations if "KEY" in o
789794
)
790795

796+
logger.info(f"Count of observation types: {dict(observation_type_counts)}")
797+
logger.info(f"Count of observation keywords: {dict(observation_keyword_counts)}")
798+
logger.info(f"Count of summary keywords: {dict(observation_summary_keys)}")
799+
791800

792801
RESERVED_KEYWORDS = ["realization", "IENS", "ITER"]
793802

@@ -1093,6 +1102,7 @@ def from_dict(cls, config_dict: ConfigDict) -> Self:
10931102
obs_config_input,
10941103
shape_registry=shape_registry,
10951104
)
1105+
log_shape_registry(shape_registry)
10961106
if not obs_configs:
10971107
raise ObservationConfigError.with_context(
10981108
f"Empty observations file: {obs_config_file}",

tests/ert/unit_tests/config/test_ert_config.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@
1919

2020
from ert import ErtScript, ErtScriptWorkflow
2121
from ert.config import (
22+
CircleShapeConfig,
2223
ConfigValidationError,
2324
ErtConfig,
2425
ESSettings,
2526
HookRuntime,
2627
QueueSystem,
2728
RFTConfig,
29+
ShapeRegistry,
2830
)
2931
from ert.config._create_observation_dataframes import create_observation_dataframes
3032
from ert.config.ert_config import (
3133
RandomSeedGenerator,
3234
_split_string_into_sections,
3335
create_forward_model_json,
36+
log_observation_keys,
37+
log_shape_registry,
3438
)
3539
from ert.config.forward_model_step import (
3640
ForwardModelStepPlugin,
@@ -3183,3 +3187,44 @@ def test_that_gen_kw_defaults_to_none_with_update_false(change_to_tmpdir):
31833187
ert_config = ErtConfig.from_file("config.ert")
31843188
param = ert_config.ensemble_config.parameter_configs["MY_PARAM"]
31853189
assert param.update_strategy is None
3190+
3191+
3192+
def test_that_log_observation_keys_logs_count_of_summary_keys(caplog):
3193+
caplog.set_level(logging.INFO)
3194+
wopr_count = 5
3195+
bpr_count = 3
3196+
mock_type = MagicMock(value="summary")
3197+
observations = [
3198+
*[{"type": mock_type, "KEY": "WOPR:FOO"}] * wopr_count,
3199+
*[{"type": mock_type, "KEY": "BPR:1,1,1"}] * bpr_count,
3200+
]
3201+
log_observation_keys(observations)
3202+
assert "Count of summary keywords:" in caplog.text
3203+
assert f"'WOPR': {wopr_count}" in caplog.text
3204+
assert f"'BPR': {bpr_count}" in caplog.text
3205+
3206+
3207+
def test_that_log_observation_keys_doesnt_fail_given_misconfigured_summarykey():
3208+
well_summary_missing_well = "WOPR"
3209+
block_summary_missing_indices = "BPR"
3210+
observations = [
3211+
{"type": MagicMock(value="summary"), "KEY": well_summary_missing_well},
3212+
{"type": MagicMock(value="summary"), "KEY": block_summary_missing_indices},
3213+
]
3214+
log_observation_keys(observations)
3215+
3216+
3217+
def test_that_log_observation_keys_doesnt_fail_given_no_keys(caplog):
3218+
caplog.set_level(logging.INFO)
3219+
observations = [{"type": MagicMock(value="summary")}]
3220+
log_observation_keys(observations)
3221+
assert "Count of summary keywords: {}" in caplog.text
3222+
3223+
3224+
def test_that_log_shape_registry_logs_count_of_shapes(caplog):
3225+
caplog.set_level(logging.INFO)
3226+
shape_registry = ShapeRegistry()
3227+
for i in range(10):
3228+
shape_registry.register(CircleShapeConfig(north=i, east=i, radius=i))
3229+
log_shape_registry(shape_registry)
3230+
assert "Count of shapes in ShapeRegistry: {'CircleShapeConfig': 10}" in caplog.text

tests/ert/unit_tests/run_models/test_base_run_model.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from _ert.events import EESnapshotUpdate
1616
from ert.config import (
17+
CircleShapeConfig,
1718
ErtConfig,
1819
ModelConfig,
1920
ObservationType,
@@ -820,10 +821,7 @@ def failing_persist(self, *args, **kwargs):
820821
assert "Failed to persist status snapshot" in caplog.text
821822

822823

823-
def test_that_ert_config_and_run_model_gets_serialized_observations_and_shape_registry_redacted( # noqa: E501
824-
caplog,
825-
):
826-
caplog.set_level(logging.INFO)
824+
def _ert_config_dict():
827825
summary_obs_dict = ObservationDict(
828826
{
829827
"type": ObservationType.SUMMARY,
@@ -840,16 +838,22 @@ def test_that_ert_config_and_run_model_gets_serialized_observations_and_shape_re
840838
},
841839
context=MagicMock(),
842840
)
843-
config_dict = {
841+
return {
844842
"NUM_REALIZATIONS": 1,
845843
"ECLBASE": "ECLIPSE_CASE",
846844
"OBS_CONFIG": (
847845
"obs_config",
848846
[summary_obs_dict],
849847
),
850848
}
851-
ert_config = ErtConfig.from_dict(config_dict)
852849

850+
851+
def test_that_ert_config_and_run_model_does_not_log_sensitive_information(
852+
caplog, use_tmpdir
853+
):
854+
caplog.set_level(logging.INFO)
855+
config_dict = _ert_config_dict()
856+
ert_config = ErtConfig.from_dict(config_dict)
853857
ert_config._log_config_dict(config_dict)
854858
assert "'OBS_CONFIG': '<REDACTED>'" in caplog.text
855859

@@ -863,3 +867,16 @@ def test_that_ert_config_and_run_model_gets_serialized_observations_and_shape_re
863867
model.log_at_startup()
864868
assert "'observations': '<REDACTED>'" in caplog.text
865869
assert "'shape_registry': '<REDACTED>'" in caplog.text
870+
871+
872+
def test_that_ert_config_logs_insensitive_information_about_observations_and_shapes(
873+
caplog,
874+
):
875+
caplog.set_level(logging.INFO)
876+
config_dict = _ert_config_dict()
877+
ErtConfig.from_dict(config_dict)
878+
assert "Count of summary keywords: {'FOPR': 1}" in caplog.text
879+
assert (
880+
f"Count of shapes in ShapeRegistry: {{'{CircleShapeConfig.__name__}': 1}}"
881+
in caplog.text
882+
)

0 commit comments

Comments
 (0)