Skip to content

Commit

Permalink
Remove outdated library for sets. (#1014)
Browse files Browse the repository at this point in the history
Remove dependency to archived `github.com/fatih/set`.
Add simple `Set` implementation instead.
  • Loading branch information
simitt committed Jul 4, 2018
1 parent d8c9493 commit 4a51de3
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 901 deletions.
27 changes: 0 additions & 27 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -435,33 +435,6 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------
Dependency: github.com/fatih/set
Revision: 27c40922c40b43fe04554d8223a402af3ea333f3
License type (autodetected): MIT
./vendor/github.com/fatih/set/LICENSE.md:
--------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2013 Fatih Arslan

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------
Dependency: github.com/garyburd/redigo
Revision: b8dc90050f24c1a73a52f107f3f575be67b21b7c
Expand Down
4 changes: 1 addition & 3 deletions processor/error/package_tests/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package package_tests
import (
"testing"

"github.com/fatih/set"

er "github.com/elastic/apm-server/processor/error"
"github.com/elastic/apm-server/tests"
)
Expand All @@ -33,7 +31,7 @@ func TestFields(t *testing.T) {
}
tests.TestEventAttrsDocumentedInFields(t, fieldsPaths, er.NewProcessor)

notInEvent := set.New(
notInEvent := tests.NewSet(
"context.db.instance",
"context.db.statement",
"context.db.user",
Expand Down
6 changes: 2 additions & 4 deletions processor/error/package_tests/json_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ package package_tests
import (
"testing"

"github.com/fatih/set"

er "github.com/elastic/apm-server/processor/error"
"github.com/elastic/apm-server/tests"
)

//Check whether attributes are added to the example payload but not to the schema
func TestPayloadAttributesInSchema(t *testing.T) {
//only add attributes that should not be documented by the schema
undocumented := set.New(
undocumented := tests.NewSet(
"errors.log.stacktrace.vars.key",
"errors.exception.stacktrace.vars.key",
"errors.exception.attributes.foo",
Expand All @@ -53,7 +51,7 @@ func TestJsonSchemaKeywordLimitation(t *testing.T) {
"./../../../_meta/fields.common.yml",
"./../_meta/fields.yml",
}
exceptions := set.New(
exceptions := tests.NewSet(
"processor.event",
"processor.name",
"error.id",
Expand Down
4 changes: 1 addition & 3 deletions processor/sourcemap/package_tests/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package package_tests
import (
"testing"

"github.com/fatih/set"

"github.com/elastic/apm-server/processor/sourcemap"
"github.com/elastic/apm-server/tests"
)
Expand All @@ -32,5 +30,5 @@ func TestEsDocumentation(t *testing.T) {
}
processorFn := sourcemap.NewProcessor
tests.TestEventAttrsDocumentedInFields(t, fieldsPaths, processorFn)
tests.TestDocumentedFieldsInEvent(t, fieldsPaths, processorFn, set.New())
tests.TestDocumentedFieldsInEvent(t, fieldsPaths, processorFn, tests.NewSet())
}
4 changes: 1 addition & 3 deletions processor/sourcemap/package_tests/json_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package package_tests
import (
"testing"

"github.com/fatih/set"

"github.com/elastic/apm-server/processor/sourcemap"
"github.com/elastic/apm-server/tests"
)
Expand All @@ -31,7 +29,7 @@ func TestPayloadAttributesInSchema(t *testing.T) {

tests.TestPayloadAttributesInSchema(t,
"sourcemap",
set.New("sourcemap", "sourcemap.file", "sourcemap.names", "sourcemap.sources", "sourcemap.sourceRoot",
tests.NewSet("sourcemap", "sourcemap.file", "sourcemap.names", "sourcemap.sources", "sourcemap.sourceRoot",
"sourcemap.mappings", "sourcemap.sourcesContent", "sourcemap.version"),
sourcemap.Schema())
}
Expand Down
4 changes: 1 addition & 3 deletions processor/transaction/package_tests/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package package_tests
import (
"testing"

"github.com/fatih/set"

"github.com/elastic/apm-server/processor/transaction"
"github.com/elastic/apm-server/tests"
)
Expand All @@ -35,5 +33,5 @@ func TestEsDocumentation(t *testing.T) {
tests.TestEventAttrsDocumentedInFields(t, fieldsPaths, processorFn)
// IP and user agent are generated in the server, so they do not come from a payload
tests.TestDocumentedFieldsInEvent(t, fieldsPaths, processorFn,
set.New("listening", "view spans", "context.user.user-agent", "context.user.ip", "context.system.ip"))
tests.NewSet("listening", "view spans", "context.user.user-agent", "context.user.ip", "context.system.ip"))
}
6 changes: 2 additions & 4 deletions processor/transaction/package_tests/json_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package package_tests
import (
"testing"

"github.com/fatih/set"

"github.com/elastic/apm-server/processor/transaction"
"github.com/elastic/apm-server/tests"
)
Expand All @@ -30,7 +28,7 @@ import (
func TestPayloadAttributesInSchema(t *testing.T) {

//only add attributes that should not be documented by the schema
undocumented := set.New(
undocumented := tests.NewSet(
"transactions.spans.stacktrace.vars.key",
"transactions.context.request.headers.some-other-header",
"transactions.context.request.headers.array",
Expand Down Expand Up @@ -67,7 +65,7 @@ func TestJsonSchemaKeywordLimitation(t *testing.T) {
"./../../../_meta/fields.common.yml",
"./../_meta/fields.yml",
}
exceptions := set.New("processor.event", "processor.name", "context.service.name", "transaction.id", "listening")
exceptions := tests.NewSet("processor.event", "processor.name", "context.service.name", "transaction.id", "listening")
tests.TestJsonSchemaKeywordLimitation(t, fieldsPaths, transaction.Schema(), exceptions)
}

Expand Down
37 changes: 19 additions & 18 deletions tests/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"strings"
"testing"

"github.com/fatih/set"
"github.com/stretchr/testify/assert"

"github.com/elastic/apm-server/config"
Expand All @@ -38,7 +37,7 @@ func TestEventAttrsDocumentedInFields(t *testing.T, fieldPaths []string, fn proc
assert.NoError(err)
disabledFieldNames, err := fetchFlattenedFieldNames(fieldPaths, addOnlyDisabledFields)
assert.NoError(err)
undocumentedFieldNames := set.New(
undocumentedFieldNames := NewSet(
"processor",
//dynamically indexed:
"context.tags.organization_uuid",
Expand Down Expand Up @@ -69,28 +68,30 @@ func TestEventAttrsDocumentedInFields(t *testing.T, fieldPaths []string, fn proc
"transaction.marks.navigationTiming.navigationStart",
"transaction.marks.navigationTiming.appBeforeBootstrap",
)
blacklistedFieldNames := set.Union(disabledFieldNames, undocumentedFieldNames).(*set.Set)
blacklistedFieldNames := Union(disabledFieldNames, undocumentedFieldNames)

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

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

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

eventNames, err := fetchEventNames(fn, set.New())
eventNames, err := fetchEventNames(fn, NewSet())
assert.NoError(err)

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

func fetchEventNames(fn processor.NewProcessor, blacklisted *set.Set) (*set.Set, error) {
func fetchEventNames(fn processor.NewProcessor, blacklisted *Set) (*Set, error) {
p := fn()
data, err := loader.LoadValidData(p.Name())
if err != nil {
Expand All @@ -107,7 +108,7 @@ func fetchEventNames(fn processor.NewProcessor, blacklisted *set.Set) (*set.Set,
}
events := payl.Transform(config.Config{})

eventNames := set.New()
eventNames := NewSet()
for _, event := range events {
for k, _ := range event.Fields {
if k == "@timestamp" {
Expand All @@ -120,7 +121,7 @@ func fetchEventNames(fn processor.NewProcessor, blacklisted *set.Set) (*set.Set,
return eventNames, nil
}

func flattenMapStr(m interface{}, prefix string, keysBlacklist *set.Set, flattened *set.Set) {
func flattenMapStr(m interface{}, prefix string, keysBlacklist *Set, flattened *Set) {
if commonMapStr, ok := m.(common.MapStr); ok {
for k, v := range commonMapStr {
flattenMapStrStr(k, v, prefix, keysBlacklist, flattened)
Expand All @@ -135,7 +136,7 @@ func flattenMapStr(m interface{}, prefix string, keysBlacklist *set.Set, flatten
}
}

func flattenMapStrStr(k string, v interface{}, prefix string, keysBlacklist *set.Set, flattened *set.Set) {
func flattenMapStrStr(k string, v interface{}, prefix string, keysBlacklist *Set, flattened *Set) {
flattenedKey := StrConcat(prefix, k, ".")
if !isBlacklistedKey(keysBlacklist, flattenedKey) {
flattened.Add(flattenedKey)
Expand All @@ -147,8 +148,8 @@ func flattenMapStrStr(k string, v interface{}, prefix string, keysBlacklist *set
}
}

func isBlacklistedKey(keysBlacklist *set.Set, key string) bool {
for _, disabledKey := range keysBlacklist.List() {
func isBlacklistedKey(keysBlacklist *Set, key string) bool {
for _, disabledKey := range keysBlacklist.Array() {
if strings.HasPrefix(key, disabledKey.(string)) {
return true

Expand All @@ -157,8 +158,8 @@ func isBlacklistedKey(keysBlacklist *set.Set, key string) bool {
return false
}

func fetchFlattenedFieldNames(paths []string, addFn addField) (*set.Set, error) {
fields := set.New()
func fetchFlattenedFieldNames(paths []string, addFn addField) (*Set, error) {
fields := NewSet()
for _, path := range paths {
f, err := loadFields(path)
if err != nil {
Expand All @@ -169,7 +170,7 @@ func fetchFlattenedFieldNames(paths []string, addFn addField) (*set.Set, error)
return fields, nil
}

func flattenFieldNames(fields []common.Field, prefix string, addFn addField, flattened *set.Set) {
func flattenFieldNames(fields []common.Field, prefix string, addFn addField, flattened *Set) {
for _, field := range fields {
flattenedKey := StrConcat(prefix, field.Name, ".")
if addFn(field) {
Expand Down
47 changes: 23 additions & 24 deletions tests/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"testing"

"github.com/fatih/set"
"github.com/stretchr/testify/assert"

"github.com/elastic/beats/libbeat/common"
Expand All @@ -34,32 +33,32 @@ const inputIdx = 3
const retValIdx = 4

func TestFlattenCommonMapStr(t *testing.T) {
emptyBlacklist := set.New()
blacklist := set.New("a.bMap", "f")
expectedAll := set.New("a", "a.bStr", "a.bMap", "a.bMap.cMap", "a.bMap.cMap.d", "a.bMap.cStr", "a.bAnotherMap", "a.bAnotherMap.e", "f")
expectedWoBlacklisted := set.New("a", "a.bStr", "a.bAnotherMap", "a.bAnotherMap.e")
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")
expectedWithFilledInput := set.New("prefilled", "a", "a.bStr", "a.bAnotherMap", "a.bAnotherMap.e")
emptyBlacklist := NewSet()
blacklist := NewSet("a.bMap", "f")
expectedAll := NewSet("a", "a.bStr", "a.bMap", "a.bMap.cMap", "a.bMap.cMap.d", "a.bMap.cStr", "a.bAnotherMap", "a.bAnotherMap.e", "f")
expectedWoBlacklisted := NewSet("a", "a.bStr", "a.bAnotherMap", "a.bAnotherMap.e")
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")
expectedWithFilledInput := NewSet("prefilled", "a", "a.bStr", "a.bAnotherMap", "a.bAnotherMap.e")
data := [][]interface{}{
[]interface{}{common.MapStr{}, "whatever", emptyBlacklist, set.New(), set.New("whatever")},
[]interface{}{common.MapStr{}, "", blacklist, set.New(), set.New()},
[]interface{}{commonMapStr(), "", emptyBlacklist, set.New(), expectedAll},
[]interface{}{commonMapStr(), "", blacklist, set.New(), expectedWoBlacklisted},
[]interface{}{commonMapStr(), "pre", emptyBlacklist, set.New(), expectedAllPrefixed},
[]interface{}{commonMapStr(), "", blacklist, set.New("prefilled"), expectedWithFilledInput},
[]interface{}{common.MapStr{}, "whatever", emptyBlacklist, NewSet(), NewSet("whatever")},
[]interface{}{common.MapStr{}, "", blacklist, NewSet(), NewSet()},
[]interface{}{commonMapStr(), "", emptyBlacklist, NewSet(), expectedAll},
[]interface{}{commonMapStr(), "", blacklist, NewSet(), expectedWoBlacklisted},
[]interface{}{commonMapStr(), "pre", emptyBlacklist, NewSet(), expectedAllPrefixed},
[]interface{}{commonMapStr(), "", blacklist, NewSet("prefilled"), expectedWithFilledInput},
}
for idx, dataRow := range data {
m := dataRow[mapDataIdx].(common.MapStr)
prefix := dataRow[prefixIdx].(string)
blacklist := dataRow[blacklistedIdx].(*set.Set)
flattened := dataRow[inputIdx].(*set.Set)
blacklist := dataRow[blacklistedIdx].(*Set)
flattened := dataRow[inputIdx].(*Set)

flattenMapStr(m, prefix, blacklist, flattened)
expected := dataRow[retValIdx].(*set.Set)
diff := set.SymmetricDifference(flattened, expected).(*set.Set)
expected := dataRow[retValIdx].(*Set)
diff := SymmDifference(flattened, expected)

errMsg := fmt.Sprintf("Failed for idx %v, diff: %v", idx, diff)
assert.Equal(t, 0, diff.Size(), errMsg)
assert.Equal(t, 0, diff.Len(), errMsg)
}
}

Expand Down Expand Up @@ -87,8 +86,8 @@ func TestLoadFields(t *testing.T) {

fields, err := loadFields("./_meta/fields.yml")
assert.Nil(t, err)
expected := set.New("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")
flattened := set.New()
expected := NewSet("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")
flattened := NewSet()
flattenFieldNames(fields, "", addAllFields, flattened)
assert.Equal(t, expected, flattened)
}
Expand All @@ -97,14 +96,14 @@ func TestFlattenFieldNames(t *testing.T) {

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

expected := set.New("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")
expected := NewSet("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")

flattened := set.New()
flattened := NewSet()
flattenFieldNames(fields, "", addAllFields, flattened)
assert.Equal(t, expected, flattened)

flattened = set.New()
flattened = NewSet()
flattenFieldNames(fields, "", addOnlyDisabledFields, flattened)
expected = set.New("transaction.context", "exception.stacktrace")
expected = NewSet("transaction.context", "exception.stacktrace")
assert.Equal(t, expected, flattened)
}
Loading

0 comments on commit 4a51de3

Please sign in to comment.