Skip to content

Commit 367f2a7

Browse files
authored
Remove outdated library for sets. (#1014)
Remove dependency to archived `github.com/fatih/set`. Add simple `Set` implementation instead.
1 parent 0b122a0 commit 367f2a7

File tree

19 files changed

+299
-901
lines changed

19 files changed

+299
-901
lines changed

NOTICE.txt

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -434,33 +434,6 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
434434
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
435435
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
436436

437-
--------------------------------------------------------------------
438-
Dependency: github.com/fatih/set
439-
Revision: 27c40922c40b43fe04554d8223a402af3ea333f3
440-
License type (autodetected): MIT
441-
./vendor/github.com/fatih/set/LICENSE.md:
442-
--------------------------------------------------------------------
443-
The MIT License (MIT)
444-
445-
Copyright (c) 2013 Fatih Arslan
446-
447-
Permission is hereby granted, free of charge, to any person obtaining a copy of
448-
this software and associated documentation files (the "Software"), to deal in
449-
the Software without restriction, including without limitation the rights to
450-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
451-
the Software, and to permit persons to whom the Software is furnished to do so,
452-
subject to the following conditions:
453-
454-
The above copyright notice and this permission notice shall be included in all
455-
copies or substantial portions of the Software.
456-
457-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
458-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
459-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
460-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
461-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
462-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
463-
464437
--------------------------------------------------------------------
465438
Dependency: github.com/garyburd/redigo
466439
Revision: b8dc90050f24c1a73a52f107f3f575be67b21b7c

processor/error/package_tests/fields_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package package_tests
33
import (
44
"testing"
55

6-
"github.com/fatih/set"
7-
86
er "github.com/elastic/apm-server/processor/error"
97
"github.com/elastic/apm-server/tests"
108
)
@@ -16,7 +14,7 @@ func TestFields(t *testing.T) {
1614
}
1715
tests.TestEventAttrsDocumentedInFields(t, fieldsPaths, er.NewProcessor)
1816

19-
notInEvent := set.New(
17+
notInEvent := tests.NewSet(
2018
"context.db.instance",
2119
"context.db.statement",
2220
"context.db.user",

processor/error/package_tests/json_schema_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ package package_tests
33
import (
44
"testing"
55

6-
"github.com/fatih/set"
7-
86
er "github.com/elastic/apm-server/processor/error"
97
"github.com/elastic/apm-server/tests"
108
)
119

1210
//Check whether attributes are added to the example payload but not to the schema
1311
func TestPayloadAttributesInSchema(t *testing.T) {
1412
//only add attributes that should not be documented by the schema
15-
undocumented := set.New(
13+
undocumented := tests.NewSet(
1614
"errors.log.stacktrace.vars.key",
1715
"errors.exception.stacktrace.vars.key",
1816
"errors.exception.attributes.foo",
@@ -36,7 +34,7 @@ func TestJsonSchemaKeywordLimitation(t *testing.T) {
3634
"./../../../_meta/fields.common.yml",
3735
"./../_meta/fields.yml",
3836
}
39-
exceptions := set.New(
37+
exceptions := tests.NewSet(
4038
"processor.event",
4139
"processor.name",
4240
"error.id",

processor/sourcemap/package_tests/fields_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package package_tests
33
import (
44
"testing"
55

6-
"github.com/fatih/set"
7-
86
"github.com/elastic/apm-server/processor/sourcemap"
97
"github.com/elastic/apm-server/tests"
108
)
@@ -15,5 +13,5 @@ func TestEsDocumentation(t *testing.T) {
1513
}
1614
processorFn := sourcemap.NewProcessor
1715
tests.TestEventAttrsDocumentedInFields(t, fieldsPaths, processorFn)
18-
tests.TestDocumentedFieldsInEvent(t, fieldsPaths, processorFn, set.New())
16+
tests.TestDocumentedFieldsInEvent(t, fieldsPaths, processorFn, tests.NewSet())
1917
}

processor/sourcemap/package_tests/json_schema_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package package_tests
33
import (
44
"testing"
55

6-
"github.com/fatih/set"
7-
86
"github.com/elastic/apm-server/processor/sourcemap"
97
"github.com/elastic/apm-server/tests"
108
)
@@ -14,7 +12,7 @@ func TestPayloadAttributesInSchema(t *testing.T) {
1412

1513
tests.TestPayloadAttributesInSchema(t,
1614
"sourcemap",
17-
set.New("sourcemap", "sourcemap.file", "sourcemap.names", "sourcemap.sources", "sourcemap.sourceRoot",
15+
tests.NewSet("sourcemap", "sourcemap.file", "sourcemap.names", "sourcemap.sources", "sourcemap.sourceRoot",
1816
"sourcemap.mappings", "sourcemap.sourcesContent", "sourcemap.version"),
1917
sourcemap.Schema())
2018
}

processor/transaction/package_tests/fields_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package package_tests
33
import (
44
"testing"
55

6-
"github.com/fatih/set"
7-
86
"github.com/elastic/apm-server/processor/transaction"
97
"github.com/elastic/apm-server/tests"
108
)
@@ -18,5 +16,5 @@ func TestEsDocumentation(t *testing.T) {
1816
tests.TestEventAttrsDocumentedInFields(t, fieldsPaths, processorFn)
1917
// IP and user agent are generated in the server, so they do not come from a payload
2018
tests.TestDocumentedFieldsInEvent(t, fieldsPaths, processorFn,
21-
set.New("listening", "view spans", "context.user.user-agent", "context.user.ip", "context.system.ip"))
19+
tests.NewSet("listening", "view spans", "context.user.user-agent", "context.user.ip", "context.system.ip"))
2220
}

processor/transaction/package_tests/json_schema_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package package_tests
33
import (
44
"testing"
55

6-
"github.com/fatih/set"
7-
86
"github.com/elastic/apm-server/processor/transaction"
97
"github.com/elastic/apm-server/tests"
108
)
@@ -13,7 +11,7 @@ import (
1311
func TestPayloadAttributesInSchema(t *testing.T) {
1412

1513
//only add attributes that should not be documented by the schema
16-
undocumented := set.New(
14+
undocumented := tests.NewSet(
1715
"transactions.spans.stacktrace.vars.key",
1816
"transactions.context.request.headers.some-other-header",
1917
"transactions.context.request.headers.array",
@@ -50,7 +48,7 @@ func TestJsonSchemaKeywordLimitation(t *testing.T) {
5048
"./../../../_meta/fields.common.yml",
5149
"./../_meta/fields.yml",
5250
}
53-
exceptions := set.New("processor.event", "processor.name", "context.service.name", "transaction.id", "listening")
51+
exceptions := tests.NewSet("processor.event", "processor.name", "context.service.name", "transaction.id", "listening")
5452
tests.TestJsonSchemaKeywordLimitation(t, fieldsPaths, transaction.Schema(), exceptions)
5553
}
5654

tests/fields.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strings"
77
"testing"
88

9-
"github.com/fatih/set"
109
"github.com/stretchr/testify/assert"
1110

1211
"github.com/elastic/apm-server/config"
@@ -21,7 +20,7 @@ func TestEventAttrsDocumentedInFields(t *testing.T, fieldPaths []string, fn proc
2120
assert.NoError(err)
2221
disabledFieldNames, err := fetchFlattenedFieldNames(fieldPaths, addOnlyDisabledFields)
2322
assert.NoError(err)
24-
undocumentedFieldNames := set.New(
23+
undocumentedFieldNames := NewSet(
2524
"processor",
2625
//dynamically indexed:
2726
"context.tags.organization_uuid",
@@ -52,28 +51,30 @@ func TestEventAttrsDocumentedInFields(t *testing.T, fieldPaths []string, fn proc
5251
"transaction.marks.navigationTiming.navigationStart",
5352
"transaction.marks.navigationTiming.appBeforeBootstrap",
5453
)
55-
blacklistedFieldNames := set.Union(disabledFieldNames, undocumentedFieldNames).(*set.Set)
54+
blacklistedFieldNames := Union(disabledFieldNames, undocumentedFieldNames)
5655

5756
eventNames, err := fetchEventNames(fn, blacklistedFieldNames)
5857
assert.NoError(err)
5958

60-
undocumentedNames := set.Difference(eventNames, fieldNames, blacklistedFieldNames)
61-
assert.Equal(0, undocumentedNames.Size(), fmt.Sprintf("Event attributes not documented in fields.yml: %v", undocumentedNames))
59+
undocumentedNames := Difference(eventNames, fieldNames)
60+
undocumentedNames = Difference(undocumentedNames, blacklistedFieldNames)
61+
assert.Equal(0, undocumentedNames.Len(), fmt.Sprintf("Event attributes not documented in fields.yml: %v", undocumentedNames))
6262
}
6363

64-
func TestDocumentedFieldsInEvent(t *testing.T, fieldPaths []string, fn processor.NewProcessor, exceptions *set.Set) {
64+
func TestDocumentedFieldsInEvent(t *testing.T, fieldPaths []string, fn processor.NewProcessor, exceptions *Set) {
6565
assert := assert.New(t)
6666
fieldNames, err := fetchFlattenedFieldNames(fieldPaths, addAllFields)
6767
assert.NoError(err)
6868

69-
eventNames, err := fetchEventNames(fn, set.New())
69+
eventNames, err := fetchEventNames(fn, NewSet())
7070
assert.NoError(err)
7171

72-
unusedNames := set.Difference(fieldNames, eventNames, exceptions)
73-
assert.Equal(0, unusedNames.Size(), fmt.Sprintf("Documented Fields missing in event: %v", unusedNames))
72+
unusedNames := Difference(fieldNames, eventNames)
73+
unusedNames = Difference(unusedNames, exceptions)
74+
assert.Equal(0, unusedNames.Len(), fmt.Sprintf("Documented Fields missing in event: %v", unusedNames))
7475
}
7576

76-
func fetchEventNames(fn processor.NewProcessor, blacklisted *set.Set) (*set.Set, error) {
77+
func fetchEventNames(fn processor.NewProcessor, blacklisted *Set) (*Set, error) {
7778
p := fn()
7879
data, err := loader.LoadValidData(p.Name())
7980
if err != nil {
@@ -90,7 +91,7 @@ func fetchEventNames(fn processor.NewProcessor, blacklisted *set.Set) (*set.Set,
9091
}
9192
events := payl.Transform(config.Config{})
9293

93-
eventNames := set.New()
94+
eventNames := NewSet()
9495
for _, event := range events {
9596
for k, _ := range event.Fields {
9697
if k == "@timestamp" {
@@ -103,7 +104,7 @@ func fetchEventNames(fn processor.NewProcessor, blacklisted *set.Set) (*set.Set,
103104
return eventNames, nil
104105
}
105106

106-
func flattenMapStr(m interface{}, prefix string, keysBlacklist *set.Set, flattened *set.Set) {
107+
func flattenMapStr(m interface{}, prefix string, keysBlacklist *Set, flattened *Set) {
107108
if commonMapStr, ok := m.(common.MapStr); ok {
108109
for k, v := range commonMapStr {
109110
flattenMapStrStr(k, v, prefix, keysBlacklist, flattened)
@@ -118,7 +119,7 @@ func flattenMapStr(m interface{}, prefix string, keysBlacklist *set.Set, flatten
118119
}
119120
}
120121

121-
func flattenMapStrStr(k string, v interface{}, prefix string, keysBlacklist *set.Set, flattened *set.Set) {
122+
func flattenMapStrStr(k string, v interface{}, prefix string, keysBlacklist *Set, flattened *Set) {
122123
flattenedKey := StrConcat(prefix, k, ".")
123124
if !isBlacklistedKey(keysBlacklist, flattenedKey) {
124125
flattened.Add(flattenedKey)
@@ -130,8 +131,8 @@ func flattenMapStrStr(k string, v interface{}, prefix string, keysBlacklist *set
130131
}
131132
}
132133

133-
func isBlacklistedKey(keysBlacklist *set.Set, key string) bool {
134-
for _, disabledKey := range keysBlacklist.List() {
134+
func isBlacklistedKey(keysBlacklist *Set, key string) bool {
135+
for _, disabledKey := range keysBlacklist.Array() {
135136
if strings.HasPrefix(key, disabledKey.(string)) {
136137
return true
137138

@@ -140,8 +141,8 @@ func isBlacklistedKey(keysBlacklist *set.Set, key string) bool {
140141
return false
141142
}
142143

143-
func fetchFlattenedFieldNames(paths []string, addFn addField) (*set.Set, error) {
144-
fields := set.New()
144+
func fetchFlattenedFieldNames(paths []string, addFn addField) (*Set, error) {
145+
fields := NewSet()
145146
for _, path := range paths {
146147
f, err := loadFields(path)
147148
if err != nil {
@@ -152,7 +153,7 @@ func fetchFlattenedFieldNames(paths []string, addFn addField) (*set.Set, error)
152153
return fields, nil
153154
}
154155

155-
func flattenFieldNames(fields []common.Field, prefix string, addFn addField, flattened *set.Set) {
156+
func flattenFieldNames(fields []common.Field, prefix string, addFn addField, flattened *Set) {
156157
for _, field := range fields {
157158
flattenedKey := StrConcat(prefix, field.Name, ".")
158159
if addFn(field) {

tests/fields_test.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/fatih/set"
87
"github.com/stretchr/testify/assert"
98

109
"github.com/elastic/beats/libbeat/common"
@@ -17,32 +16,32 @@ const inputIdx = 3
1716
const retValIdx = 4
1817

1918
func TestFlattenCommonMapStr(t *testing.T) {
20-
emptyBlacklist := set.New()
21-
blacklist := set.New("a.bMap", "f")
22-
expectedAll := set.New("a", "a.bStr", "a.bMap", "a.bMap.cMap", "a.bMap.cMap.d", "a.bMap.cStr", "a.bAnotherMap", "a.bAnotherMap.e", "f")
23-
expectedWoBlacklisted := set.New("a", "a.bStr", "a.bAnotherMap", "a.bAnotherMap.e")
24-
expectedAllPrefixed := set.New("pre", "pre.a", "pre.a.bStr", "pre.a.bMap", "pre.a.bMap.cMap", "pre.a.bMap.cMap.d", "pre.a.bMap.cStr", "pre.a.bAnotherMap", "pre.a.bAnotherMap.e", "pre.f")
25-
expectedWithFilledInput := set.New("prefilled", "a", "a.bStr", "a.bAnotherMap", "a.bAnotherMap.e")
19+
emptyBlacklist := NewSet()
20+
blacklist := NewSet("a.bMap", "f")
21+
expectedAll := NewSet("a", "a.bStr", "a.bMap", "a.bMap.cMap", "a.bMap.cMap.d", "a.bMap.cStr", "a.bAnotherMap", "a.bAnotherMap.e", "f")
22+
expectedWoBlacklisted := NewSet("a", "a.bStr", "a.bAnotherMap", "a.bAnotherMap.e")
23+
expectedAllPrefixed := NewSet("pre", "pre.a", "pre.a.bStr", "pre.a.bMap", "pre.a.bMap.cMap", "pre.a.bMap.cMap.d", "pre.a.bMap.cStr", "pre.a.bAnotherMap", "pre.a.bAnotherMap.e", "pre.f")
24+
expectedWithFilledInput := NewSet("prefilled", "a", "a.bStr", "a.bAnotherMap", "a.bAnotherMap.e")
2625
data := [][]interface{}{
27-
[]interface{}{common.MapStr{}, "whatever", emptyBlacklist, set.New(), set.New("whatever")},
28-
[]interface{}{common.MapStr{}, "", blacklist, set.New(), set.New()},
29-
[]interface{}{commonMapStr(), "", emptyBlacklist, set.New(), expectedAll},
30-
[]interface{}{commonMapStr(), "", blacklist, set.New(), expectedWoBlacklisted},
31-
[]interface{}{commonMapStr(), "pre", emptyBlacklist, set.New(), expectedAllPrefixed},
32-
[]interface{}{commonMapStr(), "", blacklist, set.New("prefilled"), expectedWithFilledInput},
26+
[]interface{}{common.MapStr{}, "whatever", emptyBlacklist, NewSet(), NewSet("whatever")},
27+
[]interface{}{common.MapStr{}, "", blacklist, NewSet(), NewSet()},
28+
[]interface{}{commonMapStr(), "", emptyBlacklist, NewSet(), expectedAll},
29+
[]interface{}{commonMapStr(), "", blacklist, NewSet(), expectedWoBlacklisted},
30+
[]interface{}{commonMapStr(), "pre", emptyBlacklist, NewSet(), expectedAllPrefixed},
31+
[]interface{}{commonMapStr(), "", blacklist, NewSet("prefilled"), expectedWithFilledInput},
3332
}
3433
for idx, dataRow := range data {
3534
m := dataRow[mapDataIdx].(common.MapStr)
3635
prefix := dataRow[prefixIdx].(string)
37-
blacklist := dataRow[blacklistedIdx].(*set.Set)
38-
flattened := dataRow[inputIdx].(*set.Set)
36+
blacklist := dataRow[blacklistedIdx].(*Set)
37+
flattened := dataRow[inputIdx].(*Set)
3938

4039
flattenMapStr(m, prefix, blacklist, flattened)
41-
expected := dataRow[retValIdx].(*set.Set)
42-
diff := set.SymmetricDifference(flattened, expected).(*set.Set)
40+
expected := dataRow[retValIdx].(*Set)
41+
diff := SymmDifference(flattened, expected)
4342

4443
errMsg := fmt.Sprintf("Failed for idx %v, diff: %v", idx, diff)
45-
assert.Equal(t, 0, diff.Size(), errMsg)
44+
assert.Equal(t, 0, diff.Len(), errMsg)
4645
}
4746
}
4847

@@ -70,8 +69,8 @@ func TestLoadFields(t *testing.T) {
7069

7170
fields, err := loadFields("./_meta/fields.yml")
7271
assert.Nil(t, err)
73-
expected := set.New("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")
74-
flattened := set.New()
72+
expected := NewSet("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")
73+
flattened := NewSet()
7574
flattenFieldNames(fields, "", addAllFields, flattened)
7675
assert.Equal(t, expected, flattened)
7776
}
@@ -80,14 +79,14 @@ func TestFlattenFieldNames(t *testing.T) {
8079

8180
fields, _ := loadFields("./_meta/fields.yml")
8281

83-
expected := set.New("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")
82+
expected := NewSet("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")
8483

85-
flattened := set.New()
84+
flattened := NewSet()
8685
flattenFieldNames(fields, "", addAllFields, flattened)
8786
assert.Equal(t, expected, flattened)
8887

89-
flattened = set.New()
88+
flattened = NewSet()
9089
flattenFieldNames(fields, "", addOnlyDisabledFields, flattened)
91-
expected = set.New("transaction.context", "exception.stacktrace")
90+
expected = NewSet("transaction.context", "exception.stacktrace")
9291
assert.Equal(t, expected, flattened)
9392
}

0 commit comments

Comments
 (0)