Skip to content

Commit

Permalink
test error.id under ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
graphaelli committed Nov 19, 2018
1 parent 61571c3 commit 04ecd59
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 42 deletions.
2 changes: 1 addition & 1 deletion processor/error/package_tests/attrs_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func condRequiredKeys(c map[string]tests.Condition) map[string]tests.Condition {
func keywordExceptionKeys(s *tests.Set) *tests.Set {
return tests.Union(s, tests.NewSet(
"processor.event", "processor.name", "listening", "error.grouping_key",
"error.id", "transaction.id", "context.tags", "parent.id", "trace.id",
"transaction.id", "context.tags", "parent.id", "trace.id",
"view errors", "error id icon"))
}

Expand Down
13 changes: 9 additions & 4 deletions tests/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (ps *ProcessorSetup) PayloadAttrsMatchFields(t *testing.T, payloadAttrsNotI
Group("context.request.body"),
Group("context.response.headers"),
"context.process.argv",
//ecs provided fields
"error.id",
))
events := fetchFields(t, ps.Proc, ps.FullPayloadPath, notInFields)
ps.EventFieldsInTemplateFields(t, events, notInFields)
Expand Down Expand Up @@ -160,7 +162,7 @@ func isBlacklistedKey(keysBlacklist *Set, key string) bool {
func fetchFlattenedFieldNames(paths []string, fn func(common.Field) bool) (*Set, error) {
fields := NewSet()
for _, path := range paths {
f, err := loadFields(path)
f, err := loadFieldsFile(path)
if err != nil {
return nil, err
}
Expand All @@ -179,13 +181,16 @@ func flattenFieldNames(fields []common.Field, prefix string, fn func(common.Fiel
}
}

func loadFields(yamlPath string) ([]common.Field, error) {
fields := []common.Field{}

func loadFieldsFile(yamlPath string) (common.Fields, error) {
yaml, err := ioutil.ReadFile(yamlPath)
if err != nil {
return nil, err
}
return loadFields(yaml)
}

func loadFields(yaml []byte) (common.Fields, error){
var fields []common.Field
cfg, err := common.NewConfigWithYAML(yaml, "")
if err != nil {
return nil, err
Expand Down
20 changes: 16 additions & 4 deletions tests/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package tests

import (
"fmt"
"github.com/elastic/apm-server/cmd"
"github.com/elastic/beats/libbeat/asset"
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -75,10 +78,10 @@ func commonMapStr() common.MapStr {
}

func TestLoadFields(t *testing.T) {
_, err := loadFields("non-existing")
_, err := loadFieldsFile("non-existing")
assert.NotNil(t, err)

fields, err := loadFields("./_meta/fields.yml")
fields, err := loadFieldsFile("./_meta/fields.yml")
assert.Nil(t, err)
expected := NewSet("transaction", "transaction.id", "transaction.context", "exception", "exception.http", "exception.http.url", "exception.http.meta", "exception.stacktrace")
flattened := NewSet()
Expand All @@ -87,8 +90,7 @@ func TestLoadFields(t *testing.T) {
}

func TestFlattenFieldNames(t *testing.T) {

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

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

Expand All @@ -101,3 +103,13 @@ func TestFlattenFieldNames(t *testing.T) {
expected = NewSet("transaction.context", "exception.stacktrace")
assert.Equal(t, expected, flattened)
}


// TestECSPresence ensures that fields moved to ECS and relied on by apm-server are present
func TestECSPresence(t *testing.T) {
yaml, err := asset.GetFields(cmd.Name)
require.NoError(t, err)
fields, err := loadFields(yaml)
require.NoError(t, err)
assert.Contains(t, fields.GetKeys(), "error.id")
}
33 changes: 0 additions & 33 deletions vendor/github.com/elastic/beats/libbeat/plugin/load.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04ecd59

Please sign in to comment.