|
| 1 | +// Licensed to Elasticsearch B.V. under one or more contributor |
| 2 | +// license agreements. See the NOTICE file distributed with |
| 3 | +// this work for additional information regarding copyright |
| 4 | +// ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +// the Apache License, Version 2.0 (the "License"); you may |
| 6 | +// not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package model |
| 19 | + |
| 20 | +import ( |
| 21 | + "strconv" |
| 22 | + "strings" |
| 23 | + |
| 24 | + "github.com/elastic/apm-server/utility" |
| 25 | + "github.com/elastic/beats/libbeat/common" |
| 26 | +) |
| 27 | + |
| 28 | +func CopyECS(fields common.MapStr) { |
| 29 | + // context.tags -> labels |
| 30 | + utility.Add(fields, "labels", fields["context"].(common.MapStr)["tags"]) |
| 31 | + |
| 32 | + // context.request.url.protocol -> url.scheme (minus trailing colon) |
| 33 | + if scheme, err := fields.GetValue("context.request.url.protocol"); err == nil { |
| 34 | + if schemeStr, ok := scheme.(string); ok { |
| 35 | + utility.MergeAdd(fields, "url", common.MapStr{"scheme": strings.TrimSuffix(schemeStr, ":")}) |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + // context.request.url.port -> url.port (as int) |
| 40 | + if port, err := fields.GetValue("context.request.url.port"); err == nil { |
| 41 | + if portStr, ok := port.(string); ok { |
| 42 | + if portNum, err := strconv.Atoi(portStr); err == nil { |
| 43 | + utility.MergeAdd(fields, "url", common.MapStr{"port": portNum}) |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + // docker.container.labels -> container.labels |
| 49 | + if containerLabels, err := fields.GetValue("docker.container.labels"); err == nil { |
| 50 | + if containerLabelsMap, ok := containerLabels.(common.MapStr); ok { |
| 51 | + utility.MergeAdd(fields, "container", common.MapStr{"labels": containerLabelsMap}) |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments