-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add validation rule to disallow dangling object IDs #589
Conversation
Update error message to follow the same pattern as other validation errors
test integrations |
Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#7758 |
Is it possible that it is ok to reference these fleet managed tags? |
@@ -133,6 +133,7 @@ func (s Spec) rules(pkgType string, rootSpec spectypes.ItemSpec) validationRules | |||
{fn: semantic.ValidateProfilingNonGA, types: []string{"integration"}}, | |||
{fn: semantic.ValidateKibanaObjectIDs, types: []string{"integration"}}, | |||
{fn: semantic.ValidateRoutingRulesAndDataset, types: []string{"integration"}, since: semver.MustParse("2.9.0")}, | |||
{fn: semantic.ValidateKibanaNoDanglingObjectIDs, since: semver.MustParse("3.0.0")}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be applied since v3.0.0
@jsoriano Not sure about this, in case of elastic-package when it exports dashboards it was set to remove those references from the dashboard too in this PR elastic/elastic-package#1206. Currently, if it is tried to export those dashboards (for instance from airflow package), it is raised this error (as a note the installation does not fail): $ elastic-package-v0.86.1 export dashboards --allow-snapshot
Export Kibana dashboards
Warning: exporting dashboards from a SNAPSHOT version of Kibana (8.10.0-SNAPSHOT) is discouraged. It could lead to invalid dashboards (for example if they use features that are reverted or modified before the final release)
? Which dashboards would you like to export? [Metrics Airflow] Overview (ID: airflow-a3aa42d0-a465-11ed-9ff0-ab4dd59e4c75)
Error: dashboards export failed: exporting dashboards using Kibana client failed: at least Kibana object returned an error: [0] Saved object [tag/airflow-fleet-managed-default] not found
[1] Saved object [tag/airflow-fleet-pkg-airflow-default] not found Probably because elastic-package also adds the package name as part of one of their transform operations: https://github.com/elastic/elastic-package/blob/e1157add2447f28f135fdb055aa396fce8f9c3b5/internal/export/transform_standardize.go#L128-L141 Those fleet tags are always created when the package is installed ("managed" and "<package_name>"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
found := false | ||
for _, installed := range installedIDs { | ||
if reference.objectID != installed.objectID { | ||
continue | ||
} | ||
if reference.objectType != installed.objectType { | ||
continue | ||
} | ||
|
||
found = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, as the struct seems to be comparable, maybe you can use slices.Contains
.
found := false | |
for _, installed := range installedIDs { | |
if reference.objectID != installed.objectID { | |
continue | |
} | |
if reference.objectType != installed.objectType { | |
continue | |
} | |
found = true | |
} | |
found := slices.Contains(installedIDs, reference) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check it, but there is a third parameter filePath
in the struct that has not the same value between installedIDs and referencedIDs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use slice.ContainsFunc
to use those specific conditions.
Using slice.Conditions
make the tests fail.
} | ||
|
||
var references []reference | ||
for _, reference := range allReferences { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. Also here maybe you can use some slices
helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use slices.Contains
👍
@@ -1,3 +1,4 @@ | |||
{ | |||
"id": "good-dashboard-abc-1" | |||
"id": "good-dashboard-abc-1", | |||
"type": "dashboard" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these files didn't have type
s? Were they crafted files for tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think those assets were crafted with the minimum values for the tests. At that moment, it was just the id
field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
code/go/internal/validator/semantic/validate_kibana_no_dangling_object_ids.go
Outdated
Show resolved
Hide resolved
💚 Build Succeeded
History
cc @mrodm |
What does this PR do?
This PR adds a new validation rule to be applied in v3 to check dangling object IDs.
Why is it important?
This new validation rule ensures that all references listed in dashboards or other assets are valid ones. That means that there is an asset file with the same ID and type in the package.
Example of the error reported using
elastic-package
:$ elastic-package check Format the package Done Lint the package 2023/09/11 16:40:52 Warning: package using an unreleased version of the spec (3.0.0-next) Error: checking package failed: linting package failed: found 1 validation error: 1. file "/home/user/Coding/work/package-spec/test/packages/bad_dangling_object_ids/kibana/dashboard/bad_dangling_object_ids-82273ffe-6acc-4f2f-bbee-c1004abba63d.json" is invalid: dangling reference found: bad_dangling_object_ids-8287a5d5-1576-4f3a-83c4-444e9058439c (search)
IMPORTANT: Excluded
index-pattern
references from this check.Errors found if this validation rule would be applied to all packages (mainly dangling reference of tags):
gcp
:istio
:system
:airflow
:Checklist
test/packages
that prove my change is effective.spec/changelog.yml
.Related issues