-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidy up model to resembles ECS more closely (#5785)
* model: move agent/container/kubernetes/network up Tidy up the model so it resembles ECS more closely: - Move Agent out of Service - Move Container, Kubernetes, and Network out of System * Rename model.System to model.Host Again, rename System to Host to resemble ECS more closely, and rename hostname fields. Move host.os fields into a separate "OS" type and introduce OS as a field of Host. (cherry picked from commit 3fe235c)
- Loading branch information
Showing
42 changed files
with
578 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package model | ||
|
||
import ( | ||
"github.com/elastic/beats/v7/libbeat/common" | ||
) | ||
|
||
// Agent describes an Elastic APM agent. | ||
type Agent struct { | ||
Name string | ||
Version string | ||
EphemeralID string | ||
} | ||
|
||
func (a *Agent) fields() common.MapStr { | ||
var agent mapStr | ||
agent.maybeSetString("name", a.Name) | ||
agent.maybeSetString("version", a.Version) | ||
agent.maybeSetString("ephemeral_id", a.EphemeralID) | ||
return common.MapStr(agent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package model | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common" | ||
) | ||
|
||
const ( | ||
agentName, agentVersion = "elastic-node", "1.0.0" | ||
) | ||
|
||
func TestAgentFields(t *testing.T) { | ||
tests := []struct { | ||
Agent Agent | ||
Fields common.MapStr | ||
}{ | ||
{ | ||
Agent: Agent{}, | ||
Fields: nil, | ||
}, | ||
{ | ||
Agent: Agent{ | ||
Name: agentName, | ||
Version: agentVersion, | ||
}, | ||
Fields: common.MapStr{ | ||
"name": "elastic-node", | ||
"version": "1.0.0", | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
assert.Equal(t, test.Fields, test.Agent.fields()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package model | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common" | ||
) | ||
|
||
type Host struct { | ||
// Hostname holds the detected hostname of the host. | ||
Hostname string | ||
|
||
// Name holds the user-defined name of the host, or the | ||
// detected hostname. | ||
Name string | ||
|
||
// ID holds a unique ID for the host. | ||
ID string | ||
|
||
// Architecture holds the host machine architecture. | ||
Architecture string | ||
|
||
// Type holds the host type, e.g. cloud instance machine type. | ||
Type string | ||
|
||
// IP holds the host IP address. | ||
// | ||
// TODO(axw) this should be a slice. | ||
IP net.IP | ||
|
||
// OS holds information about the operating system running on the host. | ||
OS OS | ||
} | ||
|
||
func (h *Host) fields() common.MapStr { | ||
if h == nil { | ||
return nil | ||
} | ||
var fields mapStr | ||
fields.maybeSetString("hostname", h.Hostname) | ||
fields.maybeSetString("name", h.Name) | ||
fields.maybeSetString("architecture", h.Architecture) | ||
fields.maybeSetString("type", h.Type) | ||
if h.IP != nil { | ||
fields.set("ip", h.IP.String()) | ||
} | ||
fields.maybeSetMapStr("os", h.OS.fields()) | ||
return common.MapStr(fields) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package model | ||
|
||
import ( | ||
"encoding/json" | ||
"net" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/apm-server/approvaltest" | ||
) | ||
|
||
func TestSystemTransformation(t *testing.T) { | ||
detected, configured := "host", "custom hostname" | ||
|
||
for name, host := range map[string]Host{ | ||
"hostname": {Hostname: detected}, | ||
"ignored hostname": {Name: configured}, | ||
"full hostname info": {Hostname: detected, Name: configured}, | ||
"full": { | ||
Hostname: detected, | ||
Name: configured, | ||
Architecture: "amd", | ||
Type: "t2.medium", | ||
IP: net.ParseIP("127.0.0.1"), | ||
OS: OS{ | ||
Platform: "osx", | ||
Full: "Mac OS Mojave", | ||
Type: "macos", | ||
}, | ||
}, | ||
} { | ||
t.Run(name, func(t *testing.T) { | ||
var fields mapStr | ||
metadata := &Metadata{Host: host} | ||
metadata.set(&fields, nil) | ||
resultJSON, err := json.Marshal(fields["host"]) | ||
require.NoError(t, err) | ||
name := filepath.Join("test_approved", "host", strings.ReplaceAll(name, " ", "_")) | ||
approvaltest.ApproveJSON(t, name, resultJSON) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.