Skip to content

Commit e611a59

Browse files
committed
Assign error code to path_match in manifests
1 parent 4846157 commit e611a59

17 files changed

Lines changed: 322 additions & 20 deletions

File tree

code/go/internal/validator/spec.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io/fs"
1111
"log"
12+
"regexp"
1213
"strings"
1314

1415
"github.com/Masterminds/semver/v3"
@@ -106,7 +107,19 @@ func processErrors(errs specerrors.ValidationErrors) specerrors.ValidationErrors
106107
original string
107108
new string
108109
}{
109-
{"Must not validate the schema (not)", "Must not be present"},
110+
{
111+
original: "Must not validate the schema (not)",
112+
new: "Must not be present",
113+
},
114+
}
115+
addErrorCode := []struct {
116+
matcher *regexp.Regexp
117+
code string
118+
}{
119+
{
120+
matcher: regexp.MustCompile(`field elasticsearch\.index_template\.mappings\.dynamic_templates\..*: Additional property path_match is not allowed$`),
121+
code: specerrors.CodePathMatchNotAllowedInManifest,
122+
},
110123
}
111124
redundant := []string{
112125
"Must validate \"then\" as \"if\" was valid",
@@ -115,21 +128,24 @@ func processErrors(errs specerrors.ValidationErrors) specerrors.ValidationErrors
115128
"Must validate at least one schema (anyOf)",
116129
"Must validate one and only one schema (oneOf)",
117130
}
131+
118132
for _, e := range errs {
119133
for _, msg := range msgTransforms {
120134
if strings.Contains(e.Error(), msg.original) {
121-
processedErrs = append(processedErrs,
122-
specerrors.NewStructuredError(
123-
errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1)),
124-
specerrors.UnassignedCode),
125-
)
126-
continue
135+
e = specerrors.NewStructuredError(
136+
errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1)),
137+
specerrors.UnassignedCode)
127138
}
128-
if substringInSlice(e.Error(), redundant) {
129-
continue
139+
}
140+
for _, transform := range addErrorCode {
141+
if transform.matcher.MatchString(e.Error()) {
142+
e = specerrors.NewStructuredError(e, transform.code)
130143
}
131-
processedErrs = append(processedErrs, e)
132144
}
145+
if substringInSlice(e.Error(), redundant) {
146+
continue
147+
}
148+
processedErrs = append(processedErrs, e)
133149
}
134150

135151
return processedErrs

code/go/pkg/specerrors/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ package specerrors
88
const (
99
UnassignedCode = ""
1010

11+
// JSE - JSON Schema Errors that can be skipped
12+
CodePathMatchNotAllowedInManifest = "JSE00001"
13+
1114
// PSR - Package Spec [General] Rule
1215
CodeNonGASpecOnGAPackage = "PSR00001"
1316
CodePrereleaseFeatureOnGAPackage = "PSR00002"

code/go/pkg/validator/validator_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package validator
66

77
import (
8+
"errors"
89
"fmt"
910
"os"
1011
"path"
@@ -42,6 +43,7 @@ func TestValidateFile(t *testing.T) {
4243
"ignored_malformed": {},
4344
"custom_ilm_policy": {},
4445
"profiling_symbolizer": {},
46+
"skip_path_match_in_data_stream": {},
4547
"bad_additional_content": {
4648
"bad-bad",
4749
[]string{
@@ -242,23 +244,20 @@ func TestValidateFile(t *testing.T) {
242244
},
243245
}
244246

245-
filter := specerrors.NewFilter(&specerrors.ConfigFilter{
246-
Errors: specerrors.Processors{
247-
// TODO: Actually fix the references instead of ignoring the error.
248-
ExcludeChecks: []string{"SVR00004"},
249-
},
250-
})
251-
252247
for pkgName, test := range tests {
253248
t.Run(pkgName, func(t *testing.T) {
254249
pkgRootPath := filepath.Join("..", "..", "..", "..", "test", "packages", pkgName)
255250
errPrefix := fmt.Sprintf("file \"%s/%s\" is invalid: ", pkgRootPath, test.invalidPkgFilePath)
256251

257252
errs := ValidateFromPath(pkgRootPath)
258253
if verrs, ok := errs.(specerrors.ValidationErrors); ok {
259-
result, err := filter.Run(verrs)
260-
require.NoError(t, err)
261-
errs = result.Processed
254+
filterConfig, err := specerrors.LoadConfigFilter(os.DirFS(pkgRootPath))
255+
if !errors.Is(err, os.ErrNotExist) {
256+
filter := specerrors.NewFilter(filterConfig)
257+
result, err := filter.Run(verrs)
258+
require.NoError(t, err)
259+
errs = result.Processed
260+
}
262261
}
263262

264263
if test.expectedErrContains == nil {

spec/changelog.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
- description: 'Allow to set index: false in dynamic templates defined in data stream manifests'
1111
type: enhancement
1212
link: https://github.com/elastic/package-spec/issues/650
13+
- description: Assign error code to definition of dynamic mappings found in data stream manifests
14+
type: enhancement
15+
link: https://github.com/elastic/package-spec/issues/654
1316
- version: 3.0.0
1417
changes:
1518
- description: Validate processors used in ingest pipelines
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
errors:
2+
exclude_checks:
3+
- SVR00004 # References in dashboards.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
errors:
2+
exclude_checks:
3+
- SVR00004 # References in dashboards.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Elastic License 2.0
2+
3+
URL: https://www.elastic.co/licensing/elastic-license
4+
5+
## Acceptance
6+
7+
By using the software, you agree to all of the terms and conditions below.
8+
9+
## Copyright License
10+
11+
The licensor grants you a non-exclusive, royalty-free, worldwide,
12+
non-sublicensable, non-transferable license to use, copy, distribute, make
13+
available, and prepare derivative works of the software, in each case subject to
14+
the limitations and conditions below.
15+
16+
## Limitations
17+
18+
You may not provide the software to third parties as a hosted or managed
19+
service, where the service provides users with access to any substantial set of
20+
the features or functionality of the software.
21+
22+
You may not move, change, disable, or circumvent the license key functionality
23+
in the software, and you may not remove or obscure any functionality in the
24+
software that is protected by the license key.
25+
26+
You may not alter, remove, or obscure any licensing, copyright, or other notices
27+
of the licensor in the software. Any use of the licensor’s trademarks is subject
28+
to applicable law.
29+
30+
## Patents
31+
32+
The licensor grants you a license, under any patent claims the licensor can
33+
license, or becomes able to license, to make, have made, use, sell, offer for
34+
sale, import and have imported the software, in each case subject to the
35+
limitations and conditions in this license. This license does not cover any
36+
patent claims that you cause to be infringed by modifications or additions to
37+
the software. If you or your company make any written claim that the software
38+
infringes or contributes to infringement of any patent, your patent license for
39+
the software granted under these terms ends immediately. If your company makes
40+
such a claim, your patent license ends immediately for work on behalf of your
41+
company.
42+
43+
## Notices
44+
45+
You must ensure that anyone who gets a copy of any part of the software from you
46+
also gets a copy of these terms.
47+
48+
If you modify the software, you must include in any modified copies of the
49+
software prominent notices stating that you have modified the software.
50+
51+
## No Other Rights
52+
53+
These terms do not imply any licenses other than those expressly granted in
54+
these terms.
55+
56+
## Termination
57+
58+
If you use the software in violation of these terms, such use is not licensed,
59+
and your licenses will automatically terminate. If the licensor provides you
60+
with a notice of your violation, and you cease all violation of this license no
61+
later than 30 days after you receive that notice, your licenses will be
62+
reinstated retroactively. However, if you violate these terms after such
63+
reinstatement, any additional violation of these terms will cause your licenses
64+
to terminate automatically and permanently.
65+
66+
## No Liability
67+
68+
*As far as the law allows, the software comes as is, without any warranty or
69+
condition, and the licensor will not be liable to you for any damages arising
70+
out of these terms or the use or nature of the software, under any kind of
71+
legal claim.*
72+
73+
## Definitions
74+
75+
The **licensor** is the entity offering these terms, and the **software** is the
76+
software the licensor makes available under these terms, including any portion
77+
of it.
78+
79+
**you** refers to the individual or entity agreeing to these terms.
80+
81+
**your company** is any legal entity, sole proprietorship, or other kind of
82+
organization that you work for, plus all organizations that have control over,
83+
are under the control of, or are under common control with that
84+
organization. **control** means ownership of substantially all the assets of an
85+
entity, or the power to direct its management and policies by vote, contract, or
86+
otherwise. Control can be direct or indirect.
87+
88+
**your licenses** are all the licenses granted to you for the software under
89+
these terms.
90+
91+
**use** means anything you do with the software requiring one of your licenses.
92+
93+
**trademark** means trademarks, service marks, and similar rights.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# newer versions go on top
2+
- version: "1.0.0"
3+
changes:
4+
- description: Initial draft of the package
5+
type: enhancement
6+
link: https://github.com/elastic/integrations/pull/1 # FIXME Replace with the real PR link
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
paths:
2+
{{#each paths as |path i|}}
3+
- {{path}}
4+
{{/each}}
5+
exclude_files: [".gz$"]
6+
processors:
7+
- add_locale: ~
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
description: Pipeline for processing sample logs
3+
processors:
4+
- set:
5+
field: sample_field
6+
value: "1"
7+
on_failure:
8+
- set:
9+
field: error.message
10+
value: '{{ _ingest.on_failure_message }}'

0 commit comments

Comments
 (0)