-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tagger): implement remote External Data resolution
Signed-off-by: Wassim DHIF <[email protected]>
- Loading branch information
Showing
20 changed files
with
732 additions
and
162 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
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,3 @@ | ||
module github.com/DataDog/datadog-agent/comp/core/tagger/origindetection | ||
|
||
go 1.22.0 |
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,69 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
package origindetection | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// ProductOrigin is the origin of the product that sent the entity. | ||
type ProductOrigin int | ||
|
||
const ( | ||
// ProductOriginDogStatsDLegacy is the ProductOrigin for DogStatsD in Legacy mode. | ||
// TODO: remove this when dogstatsd_origin_detection_unified is enabled by default | ||
ProductOriginDogStatsDLegacy ProductOrigin = iota | ||
// ProductOriginDogStatsD is the ProductOrigin for DogStatsD. | ||
ProductOriginDogStatsD ProductOrigin = iota | ||
// ProductOriginAPM is the ProductOrigin for APM. | ||
ProductOriginAPM ProductOrigin = iota | ||
|
||
// External Data Prefixes | ||
// These prefixes are used to build the External Data Environment Variable. | ||
|
||
ExternalDataInitPrefix = "it-" | ||
ExternalDataContainerNamePrefix = "cn-" | ||
ExternalDataPodUIDPrefix = "pu-" | ||
) | ||
|
||
// OriginInfo contains the Origin Detection information. | ||
type OriginInfo struct { | ||
ContainerIDFromSocket string // ContainerIDFromSocket is the origin resolved using Unix Domain Socket. | ||
PodUID string // PodUID is the origin resolved from the Kubernetes Pod UID. | ||
ContainerID string // ContainerID is the origin resolved from the container ID. | ||
ExternalData ExternalData // ExternalData is the external data list. | ||
Cardinality string // Cardinality is the cardinality of the resolved origin. | ||
ProductOrigin ProductOrigin // ProductOrigin is the product that sent the origin information. | ||
} | ||
|
||
// ExternalData contains the parsed external data items. | ||
type ExternalData struct { | ||
Init bool | ||
ContainerName string | ||
PodUID string | ||
} | ||
|
||
type GenerateContainerIDFromExternalData func(externalData ExternalData) (string, error) | ||
|
||
func ParseExternalData(externalEnv string) (ExternalData, error) { | ||
if externalEnv == "" { | ||
return ExternalData{}, nil | ||
} | ||
var externalData ExternalData | ||
var parsingError error | ||
for _, item := range strings.Split(externalEnv, ",") { | ||
switch { | ||
case strings.HasPrefix(item, ExternalDataInitPrefix): | ||
externalData.Init, parsingError = strconv.ParseBool(item[len(ExternalDataInitPrefix):]) | ||
case strings.HasPrefix(item, ExternalDataContainerNamePrefix): | ||
externalData.ContainerName = item[len(ExternalDataContainerNamePrefix):] | ||
case strings.HasPrefix(item, ExternalDataPodUIDPrefix): | ||
externalData.PodUID = item[len(ExternalDataPodUIDPrefix):] | ||
} | ||
} | ||
return externalData, parsingError | ||
} |
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
Oops, something went wrong.