diff --git a/ddev/changelog.d/17521.added b/ddev/changelog.d/17521.added new file mode 100644 index 0000000000000..b3739fe2d2948 --- /dev/null +++ b/ddev/changelog.d/17521.added @@ -0,0 +1 @@ +Add sample_tags to metadata validation diff --git a/ddev/src/ddev/cli/validate/metadata.py b/ddev/src/ddev/cli/validate/metadata.py index f9a2b2b540559..89882ec043857 100644 --- a/ddev/src/ddev/cli/validate/metadata.py +++ b/ddev/src/ddev/cli/validate/metadata.py @@ -130,12 +130,17 @@ def metadata(app: Application, integrations: tuple[str, ...], check_duplicates: error_message += f"{current_check.name}:{line} Invalid column {invalid_headers}.\n" - missing_headers = metadata_utils.ALL_HEADERS.difference(all_keys) + missing_headers = metadata_utils.HEADERS_TO_CHECK.difference(all_keys) if missing_headers: errors = True error_message += f"{current_check.name}:{line} Missing columns {missing_headers}.\n" - continue + + if errors: + # There's now an optional sample_tag column that isn't added yet to the existing metadata.csv + # all_keys will not be same as ALL_HEADERS. But since that sample_tag column is optional and not + # inside HEADERS_TO_CHECK, we should only continue if there's an invalid header or missing_header. + continue # check duplicate metric name duplicate_metric_name = check_duplicate_values( diff --git a/ddev/src/ddev/cli/validate/metadata_utils.py b/ddev/src/ddev/cli/validate/metadata_utils.py index 16c33155ff34d..869211fdd5bb5 100644 --- a/ddev/src/ddev/cli/validate/metadata_utils.py +++ b/ddev/src/ddev/cli/validate/metadata_utils.py @@ -5,9 +5,18 @@ REQUIRED_HEADERS = {'metric_name', 'metric_type', 'orientation', 'integration'} -OPTIONAL_HEADERS = {'description', 'interval', 'unit_name', 'per_unit_name', 'short_name', 'curated_metric'} +OPTIONAL_HEADERS = { + 'description', + 'interval', + 'unit_name', + 'per_unit_name', + 'short_name', + 'curated_metric', +} -ALL_HEADERS = REQUIRED_HEADERS | OPTIONAL_HEADERS +EXPERIMENTAL_HEADER = {"sample_tags"} +ALL_HEADERS = REQUIRED_HEADERS | OPTIONAL_HEADERS | EXPERIMENTAL_HEADER +HEADERS_TO_CHECK = REQUIRED_HEADERS | OPTIONAL_HEADERS ORDERED_HEADERS = [ "metric_name", @@ -20,6 +29,7 @@ "integration", "short_name", "curated_metric", + "sample_tags", ] VALID_METRIC_TYPE = {'count', 'gauge', 'rate'} diff --git a/ddev/tests/cli/validate/test_metrics.py b/ddev/tests/cli/validate/test_metrics.py index 60831af9c3379..277d8e58615f6 100644 --- a/ddev/tests/cli/validate/test_metrics.py +++ b/ddev/tests/cli/validate/test_metrics.py @@ -715,6 +715,58 @@ def test_metrics_ordered(fake_repo, ddev, helpers): ) +def test_passing_with_experimental_column(fake_repo, ddev, helpers): + # Testing to ensure that experimental header sample_tags is allowed + write_file( + fake_repo.path / "metadata_integration", + 'metadata.csv', + """metric_name,metric_type,interval,unit_name,per_unit_name,description,orientation,integration,short_name,curated_metric,sample_tags +metadata_integration.metric_a,gauge,,,,My metric A,0,metadata_integration,,, +metadata_integration.metric_b,gauge,,,,My metric B,0,metadata_integration,,, +""", + ) + + result = ddev('validate', 'metadata', 'metadata_integration') + + assert result.exit_code == 0, result.output + assert helpers.remove_trailing_spaces(result.output) == helpers.dedent( + """ + Metrics validation + + Passed: 1 + """ + ) + + +def test_passing_invalid_experimental_column(fake_repo, ddev, helpers): + # Testing to ensure that experimental header sample_tags is allowed. But if other tags are added, + # it will be flagged as an error + write_file( + fake_repo.path / "metadata_integration", + 'metadata.csv', + """metric_name,metric_type,interval,unit_name,per_unit_name,description,orientation,integration,short_name,curated_metric,sample_tags,foo +metadata_integration.metric_a,gauge,,,,My metric A,0,metadata_integration,,,, +metadata_integration.metric_b,gauge,,,,My metric B,0,metadata_integration,,,, +""", + ) + outfile = os.path.join('metadata_integration', 'metadata.csv') + result = ddev('validate', 'metadata', 'metadata_integration') + + assert result.exit_code == 1, result.output + assert helpers.remove_trailing_spaces(result.output) == helpers.dedent( + f""" + Metrics validation + └── metadata_integration + └── {outfile} + + metadata_integration:2 Invalid column {{'foo'}}. + metadata_integration:3 Invalid column {{'foo'}}. + + Errors: 1 + """ + ) + + def test_metrics_not_ordered(fake_repo, ddev, helpers): outfile = os.path.join('metadata_integration', 'metadata.csv') result = ddev('validate', 'metadata', 'metadata_integration')