Conversation
| break | ||
| } | ||
|
|
||
| pluginJsonBytes, _ := os.ReadFile(metadataPath) |
There was a problem hiding this comment.
At this stage, we know plugin.json file exists so no need to check for that.
There was a problem hiding this comment.
What if the file fails to open or to be read? I'd still keep the error check just in case
| for _, desc := range result.Errors() { | ||
| // we validate grafanaDependency at line 91-100, | ||
| // so we ignore the error from schema validation | ||
| if strings.Contains(desc.Field(), "grafanaDependency") { |
There was a problem hiding this comment.
I tried removing from the schema, but we have to read the schema and iterate through and find the grafanaDependency object and remove. Ignoring the returned error seemed simple so went with it.
| if err := json.Unmarshal(pluginJsonBytes, &data); err == nil { | ||
| fmt.Println(data.Dependencies.GrafanaDependency) | ||
| _, err = version.NewConstraint(data.Dependencies.GrafanaDependency) | ||
| fmt.Println(err) |
| if pluginJsonBytes != nil { | ||
| var data metadata.Metadata | ||
| if err := json.Unmarshal(pluginJsonBytes, &data); err == nil { | ||
| fmt.Println(data.Dependencies.GrafanaDependency) |
| _, err := Analyzer.Run(pass) | ||
| require.NoError(t, err) | ||
| require.Len(t, interceptor.Diagnostics, 2) | ||
| require.Equal( |
There was a problem hiding this comment.
nit: validate that the schema is not reporting grafanaDependency as it used to be.
There was a problem hiding this comment.
now the new error message is checked in the main_test.go
| ) | ||
| require.Equal( | ||
| t, | ||
| "plugin.json: (root): Additional property invalid is not allowed", |
There was a problem hiding this comment.
do we really need this validation here?
There was a problem hiding this comment.
It is to check combination of schema and grafanaDependency.
pkg/analysis/passes/metadatavalid/testdata/invalid/grafana-dep/plugin.json
Outdated
Show resolved
Hide resolved
a3f0e0a to
4734a26
Compare
xnyo
left a comment
There was a problem hiding this comment.
Some small comments but the rest LGTM to me. I don't think this will conflict with #513 as they currently do two different things, but since the analyzer in #513 is called grafanaDependency we can maybe move this check over there instead once merged? (before cutting a release because the analyzer name will change if we move a check from one analyzer to another)
| break | ||
| } | ||
|
|
||
| pluginJsonBytes, _ := os.ReadFile(metadataPath) |
There was a problem hiding this comment.
What if the file fails to open or to be read? I'd still keep the error check just in case
4734a26 to
ca6cf1b
Compare
xnyo
left a comment
There was a problem hiding this comment.
I went through this again considering also #513. I think we should merge this PR first, but we should make some changes before merging. My proposal is the following:
- Move the grafanaDependency check via the semver library in a separate
grafanadependencyanalyzer, similar to #513. I would be fine with keeping the semver range check in themetadatavalidanalyzer, but we need the extra checks in #513 (mostly just for our internal teams as sometimes they tend to forget the pre-release constraint -> deploy to cloud -> cause an incident because the version is "not supported". It never happens with community plugins since pretty much nobody uses on-prem "rolling" releases off main), so I think a dedicated analyzer is more suited, to keep those grafanaDependency-related checks close to each other - Since the proposal is to move those more robust checks with the semver library in a different analyzer, I think we should remove the grafanaDependency error filtering done here: , unless it will conflict with the semver library check. I don't know if they will conflict with each other, but ideally they shouldn't: I see the regex as a first level of validation (weaker), and the semver library as a second one (more robust). If for some reason there are instances where the regex/schema check fails, but it should pass when fed into the semver library, I think we should change the regex instead of filtering out the error. If we decide to move the semver check into a dedicated analyzer, the filtering done in metadatavalid (like in this PR) will become messy because it would reference checks done on a separate
plugin-validator/pkg/analysis/passes/metadatavalid/metadatavalid.go
Lines 122 to 127 in bbbfb76
grafanadependencyanalyzer. Moreover, if the user uses a config file that disablesgrafanadependencybut keepsmetadatavalid, the checks on the grafanaDependency field are skipped completely. I'd still keep a "simpler" check in metadatavalid and a proper one in a brand new analyzer
Once we merge this PR, I will rework #513 also considering your previous feedback (this PR is in a better state than #513, we're better off unblocking this one first)
|
I think the main problem with validating |
cfe2d0a to
79ae153
Compare
| name: "complex but valid grafanaDependency constraint", | ||
| pluginJSON: `{ | ||
| "id": "test-org-app", | ||
| "dependencies": { "grafanaDependency": ">=11.6.11 <12 || >=12.0.10 <12.1 || >=12.1.7 <12.2 || >=12.2.5" } |
There was a problem hiding this comment.
Using github.com/Masterminds/semver/v3 v3.4.0 cause hashicorp/go-version treats this as invalid. Grafana treats as valid -> grafana/grafana#118090
6fca874 to
71f0efe
Compare
71f0efe to
309ccac
Compare
xnyo
left a comment
There was a problem hiding this comment.
Just one small comment, the rest LGTM! Great job! 🙌
| ) | ||
|
|
||
| func TestGrafanaDependency(t *testing.T) { | ||
| for _, tc := range []struct { |
There was a problem hiding this comment.
Can you add test cases for:
- Empty grafanaDependency
- Missing grafanaDependency (if that makes sense, since there's also the schema validation)
There was a problem hiding this comment.
Got it. Added the tests. Unmarshal succeeds and NewConstraint returns error - improper constraint thus same title message is returned
* feat: validate grafanaDep with semver * test: add parent key * test: error msg change * ref: log the error * ref: extract to separate analyzer, use semver * test: empty or missing grafana dep * chore: retrigger ci
Validate plugin.json ->
dependencies.grafanaDependencyusing SemVer constraint.Ignores schema validation for
dependencies.grafanaDependency.