Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f5d9620
Add fields into the search response
mrodm May 18, 2023
9d5a6c5
Test with fields
mrodm May 22, 2023
fd4074b
Request whether or not synthetics mode is enabled
mrodm May 30, 2023
2c41de3
Add option to disable normalization if synthetics enabled
mrodm May 30, 2023
59b1252
add struct for hits source and fields
mrodm May 30, 2023
abfd266
Add some tests for mapstr
mrodm May 30, 2023
6e5bd94
Add helper to get string slice
mrodm May 30, 2023
d3d7177
Remove debug
mrodm May 30, 2023
f52a36d
check dataset value if disabled normalization
mrodm May 30, 2023
5cbf156
Remove usages of errors.Wrap
mrodm May 30, 2023
abb0666
Fix condition
mrodm May 30, 2023
3a4faca
Add license header
mrodm May 30, 2023
5cec1e6
Add testdata folder
mrodm May 30, 2023
fd482c0
Remove unused test data file
mrodm May 30, 2023
6396fd7
Add condition for no component template
mrodm May 30, 2023
63dc94b
fix log message
mrodm May 30, 2023
bfdb279
Show status
mrodm May 30, 2023
d981f9c
Add test package for synthetic
mrodm May 31, 2023
3bd4cf1
Add sample_event
mrodm Jun 1, 2023
4468413
Merge remote-tracking branch 'upstream/main' into use_fields_synthetics
mrodm Jun 1, 2023
1a319cc
update settings test package
mrodm Jun 2, 2023
e3c0a6d
Sanitize docs when synthetic mode is enabled
mrodm Jun 2, 2023
6afdeb2
comment debug messages
mrodm Jun 2, 2023
bf55234
Solve redundant break statement
mrodm Jun 2, 2023
14179f6
Fix lint
mrodm Jun 2, 2023
597d17c
Rename function
mrodm Jun 5, 2023
8aacea2
Merge remote-tracking branch 'upstream/main' into use_fields_synthetics
mrodm Jun 5, 2023
538c1c2
Extract function
mrodm Jun 6, 2023
abe7a0f
Extract function
mrodm Jun 6, 2023
e669293
Rename
mrodm Jun 6, 2023
e3003d2
Move to a constant all fields body
mrodm Jun 6, 2023
935beb5
Add context to error
mrodm Jun 6, 2023
b1d4921
Add more context to some erros
mrodm Jun 6, 2023
4855ce2
Expand objects in the docs retrieved from Elasticsearch
mrodm Jun 7, 2023
5a1cc24
Fix lint
mrodm Jun 7, 2023
c3f1a30
Remove array for those fields without definition
mrodm Jun 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion internal/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package common

import "strings"
import (
"fmt"
"strings"
)

// TrimStringSlice removes whitespace from the beginning and end of the contents of a []string.
func TrimStringSlice(slice []string) {
Expand Down Expand Up @@ -36,3 +39,21 @@ func StringSlicesUnion(slices ...[]string) (result []string) {
}
return
}

// ToStringSlice returns the list of strings from an interface variable
func ToStringSlice(val interface{}) ([]string, error) {
vals, ok := val.([]interface{})
if !ok {
return nil, fmt.Errorf("conversion error")
}

var s []string
for _, v := range vals {
str, ok := v.(string)
if !ok {
return nil, fmt.Errorf("conversion error")
}
s = append(s, str)
}
return s, nil
}
64 changes: 64 additions & 0 deletions internal/common/mapstr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package common

import (
"encoding/json"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestMapStrGetValue(t *testing.T) {

cases := []struct {
title string
testFile string
fieldKey string
expectedValue interface{}
}{
{
title: "string value",
testFile: "./testdata/source.json",
fieldKey: "host.architecture",
expectedValue: "x86_64",
},
{
title: "float64 value",
testFile: "./testdata/source.json",
fieldKey: "metricset.period",
expectedValue: float64(10000),
},
{
title: "slice value",
testFile: "./testdata/source.json",
fieldKey: "tags",
expectedValue: []interface{}{"apache_tomcat-cache", "forwarded"},
},
{
title: "map value",
testFile: "./testdata/source.json",
fieldKey: "data_stream",
expectedValue: map[string]interface{}{"dataset": "apache_tomcat.cache", "namespace": "ep", "type": "metrics"},
},
}

for _, c := range cases {
t.Run(c.title, func(t *testing.T) {
b, err := os.ReadFile("./testdata/source.json")
require.NoError(t, err)

var given MapStr
err = json.Unmarshal(b, &given)
require.NoError(t, err)

val, err := given.GetValue(c.fieldKey)
assert.NoError(t, err)
assert.Equal(t, c.expectedValue, val)
})
}
}
92 changes: 92 additions & 0 deletions internal/common/testdata/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"@timestamp": "2023-05-30T11:42:07.923Z",
"agent": {
"ephemeral_id": "7dd994f8-d866-4068-9f29-d6c90a28738e",
"id": "5cad1bda-ddc8-4333-8d88-333b6ef311b5",
"name": "docker-fleet-agent",
"type": "metricbeat",
"version": "8.8.0"
},
"apache_tomcat": {
"cache": {
"application_name": "/",
"hit": {
"count": 15.0
},
"lookup": {
"count": 30.0
},
"object": {
"size": {
"max": {
"kb": 512.0
}
}
},
"size": {
"current": {
"kb": 19.0
},
"max": {
"kb": 10240.0
}
},
"ttl": {
"ms": 5000.0
}
}
},
"data_stream": {
"dataset": "apache_tomcat.cache",
"namespace": "ep",
"type": "metrics"
},
"ecs": {
"version": "8.7.0"
},
"elastic_agent": {
"id": "5cad1bda-ddc8-4333-8d88-333b6ef311b5",
"snapshot": true,
"version": "8.8.0"
},
"event": {
"agent_id_status": "verified",
"category": "web",
"dataset": "apache_tomcat.cache",
"duration": 136411023,
"ingested": "2023-05-30T11:42:09Z",
"kind": "metric",
"module": "apache_tomcat",
"type": "info"
},
"host": {
"architecture": "x86_64",
"containerized": false,
"hostname": "docker-fleet-agent",
"id": "4e0d02de87bd4101b7215d3aaf5f623b",
"ip": "172.23.0.7",
"mac": "02-42-AC-17-00-07",
"name": "docker-fleet-agent",
"os": {
"codename": "focal",
"family": "debian",
"kernel": "5.19.0-42-generic",
"name": "Ubuntu",
"platform": "ubuntu",
"type": "linux",
"version": "20.04.6 LTS (Focal Fossa)"
}
},
"metricset": {
"name": "collector",
"period": 10000
},
"service": {
"address": "http://elastic-package-service-apache_tomcat-1:9090/metrics",
"type": "prometheus"
},
"tags": [
"apache_tomcat-cache",
"forwarded"
]
}
Loading