-
Notifications
You must be signed in to change notification settings - Fork 490
Add an otelcol.processor.resourcedetection component #5764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7db6642
Add a otelcol.processor.resourcedetection component
ptodev 0a11ef1
Remove "block" from title
ptodev ffd96aa
Add common config and fill in attributes table
ptodev 98238ef
Remove examples
ptodev 18db16d
Write docs, add defaults
ptodev bdc202f
Make detector blocks optional
ptodev 54a22b0
Update changelog, add to all.go
ptodev 4c922a1
make generate docs
ptodev 44f63b6
Add docs aliases
ptodev 9e5bcff
Fix typo in comment
ptodev 7c896f5
Cleanup comments
ptodev 5c75846
Apply suggestions from code review
ptodev 0df95f0
PR review suggestions
ptodev 9b89487
Make k8s API config authentication options const.
ptodev c314342
Fail validation if an incorrect detector is supplied.
ptodev 1a3f73f
Remove unnecessary Consul attributes.
ptodev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,35 @@ | ||
package otelcol | ||
|
||
import "fmt" | ||
|
||
const ( | ||
KubernetesAPIConfig_AuthType_None = "none" | ||
KubernetesAPIConfig_AuthType_ServiceAccount = "serviceAccount" | ||
KubernetesAPIConfig_AuthType_KubeConfig = "kubeConfig" | ||
KubernetesAPIConfig_AuthType_TLS = "tls" | ||
) | ||
|
||
// KubernetesAPIConfig contains options relevant to connecting to the K8s API | ||
type KubernetesAPIConfig struct { | ||
// How to authenticate to the K8s API server. This can be one of `none` | ||
// (for no auth), `serviceAccount` (to use the standard service account | ||
// token provided to the agent pod), or `kubeConfig` to use credentials | ||
// from `~/.kube/config`. | ||
AuthType string `river:"auth_type,attr,optional"` | ||
|
||
// When using auth_type `kubeConfig`, override the current context. | ||
Context string `river:"context,attr,optional"` | ||
} | ||
|
||
// Validate returns an error if the config is invalid. | ||
func (c *KubernetesAPIConfig) Validate() error { | ||
switch c.AuthType { | ||
case KubernetesAPIConfig_AuthType_None, | ||
KubernetesAPIConfig_AuthType_ServiceAccount, | ||
KubernetesAPIConfig_AuthType_KubeConfig, | ||
KubernetesAPIConfig_AuthType_TLS: | ||
return nil | ||
default: | ||
return fmt.Errorf("invalid auth_type %q", c.AuthType) | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
component/otelcol/processor/resourcedetection/internal/aws/ec2/config.go
This file contains hidden or 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,72 @@ | ||
package ec2 | ||
|
||
import ( | ||
rac "github.com/grafana/agent/component/otelcol/processor/resourcedetection/internal/resource_attribute_config" | ||
"github.com/grafana/river" | ||
) | ||
|
||
const Name = "ec2" | ||
|
||
// Config defines user-specified configurations unique to the EC2 detector | ||
type Config struct { | ||
// Tags is a list of regex's to match ec2 instance tag keys that users want | ||
// to add as resource attributes to processed data | ||
Tags []string `river:"tags,attr,optional"` | ||
ResourceAttributes ResourceAttributesConfig `river:"resource_attributes,block,optional"` | ||
} | ||
|
||
// DefaultArguments holds default settings for Config. | ||
var DefaultArguments = Config{ | ||
ResourceAttributes: ResourceAttributesConfig{ | ||
CloudAccountID: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudAvailabilityZone: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudPlatform: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudProvider: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudRegion: rac.ResourceAttributeConfig{Enabled: true}, | ||
HostID: rac.ResourceAttributeConfig{Enabled: true}, | ||
HostImageID: rac.ResourceAttributeConfig{Enabled: true}, | ||
HostName: rac.ResourceAttributeConfig{Enabled: true}, | ||
HostType: rac.ResourceAttributeConfig{Enabled: true}, | ||
}, | ||
} | ||
|
||
var _ river.Defaulter = (*Config)(nil) | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *Config) SetToDefault() { | ||
*args = DefaultArguments | ||
} | ||
|
||
func (args Config) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"tags": append([]string{}, args.Tags...), | ||
ptodev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"resource_attributes": args.ResourceAttributes.Convert(), | ||
} | ||
} | ||
|
||
// ResourceAttributesConfig provides config to enable and disable resource attributes. | ||
type ResourceAttributesConfig struct { | ||
CloudAccountID rac.ResourceAttributeConfig `river:"cloud.account.id,block,optional"` | ||
CloudAvailabilityZone rac.ResourceAttributeConfig `river:"cloud.availability_zone,block,optional"` | ||
CloudPlatform rac.ResourceAttributeConfig `river:"cloud.platform,block,optional"` | ||
CloudProvider rac.ResourceAttributeConfig `river:"cloud.provider,block,optional"` | ||
CloudRegion rac.ResourceAttributeConfig `river:"cloud.region,block,optional"` | ||
HostID rac.ResourceAttributeConfig `river:"host.id,block,optional"` | ||
HostImageID rac.ResourceAttributeConfig `river:"host.image.id,block,optional"` | ||
HostName rac.ResourceAttributeConfig `river:"host.name,block,optional"` | ||
HostType rac.ResourceAttributeConfig `river:"host.type,block,optional"` | ||
} | ||
|
||
func (r ResourceAttributesConfig) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"cloud.account.id": r.CloudAccountID.Convert(), | ||
"cloud.availability_zone": r.CloudAvailabilityZone.Convert(), | ||
"cloud.platform": r.CloudPlatform.Convert(), | ||
"cloud.provider": r.CloudProvider.Convert(), | ||
"cloud.region": r.CloudRegion.Convert(), | ||
"host.id": r.HostID.Convert(), | ||
"host.image.id": r.HostImageID.Convert(), | ||
"host.name": r.HostName.Convert(), | ||
"host.type": r.HostType.Convert(), | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
component/otelcol/processor/resourcedetection/internal/aws/ecs/config.go
This file contains hidden or 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,86 @@ | ||
package ecs | ||
|
||
import ( | ||
rac "github.com/grafana/agent/component/otelcol/processor/resourcedetection/internal/resource_attribute_config" | ||
"github.com/grafana/river" | ||
) | ||
|
||
const Name = "ecs" | ||
|
||
type Config struct { | ||
ResourceAttributes ResourceAttributesConfig `river:"resource_attributes,block,optional"` | ||
} | ||
|
||
// DefaultArguments holds default settings for Config. | ||
var DefaultArguments = Config{ | ||
ResourceAttributes: ResourceAttributesConfig{ | ||
AwsEcsClusterArn: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsEcsLaunchtype: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsEcsTaskArn: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsEcsTaskFamily: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsEcsTaskRevision: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsLogGroupArns: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsLogGroupNames: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsLogStreamArns: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsLogStreamNames: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudAccountID: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudAvailabilityZone: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudPlatform: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudProvider: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudRegion: rac.ResourceAttributeConfig{Enabled: true}, | ||
}, | ||
} | ||
|
||
var _ river.Defaulter = (*Config)(nil) | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *Config) SetToDefault() { | ||
*args = DefaultArguments | ||
} | ||
|
||
func (args *Config) Convert() map[string]interface{} { | ||
if args == nil { | ||
return nil | ||
} | ||
|
||
return map[string]interface{}{ | ||
"resource_attributes": args.ResourceAttributes.Convert(), | ||
} | ||
} | ||
|
||
// ResourceAttributesConfig provides config for ecs resource attributes. | ||
type ResourceAttributesConfig struct { | ||
AwsEcsClusterArn rac.ResourceAttributeConfig `river:"aws.ecs.cluster.arn,block,optional"` | ||
AwsEcsLaunchtype rac.ResourceAttributeConfig `river:"aws.ecs.launchtype,block,optional"` | ||
AwsEcsTaskArn rac.ResourceAttributeConfig `river:"aws.ecs.task.arn,block,optional"` | ||
AwsEcsTaskFamily rac.ResourceAttributeConfig `river:"aws.ecs.task.family,block,optional"` | ||
AwsEcsTaskRevision rac.ResourceAttributeConfig `river:"aws.ecs.task.revision,block,optional"` | ||
AwsLogGroupArns rac.ResourceAttributeConfig `river:"aws.log.group.arns,block,optional"` | ||
AwsLogGroupNames rac.ResourceAttributeConfig `river:"aws.log.group.names,block,optional"` | ||
AwsLogStreamArns rac.ResourceAttributeConfig `river:"aws.log.stream.arns,block,optional"` | ||
AwsLogStreamNames rac.ResourceAttributeConfig `river:"aws.log.stream.names,block,optional"` | ||
CloudAccountID rac.ResourceAttributeConfig `river:"cloud.account.id,block,optional"` | ||
CloudAvailabilityZone rac.ResourceAttributeConfig `river:"cloud.availability_zone,block,optional"` | ||
CloudPlatform rac.ResourceAttributeConfig `river:"cloud.platform,block,optional"` | ||
CloudProvider rac.ResourceAttributeConfig `river:"cloud.provider,block,optional"` | ||
CloudRegion rac.ResourceAttributeConfig `river:"cloud.region,block,optional"` | ||
} | ||
|
||
func (r ResourceAttributesConfig) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"aws.ecs.cluster.arn": r.AwsEcsClusterArn.Convert(), | ||
"aws.ecs.launchtype": r.AwsEcsLaunchtype.Convert(), | ||
"aws.ecs.task.arn": r.AwsEcsTaskArn.Convert(), | ||
"aws.ecs.task.family": r.AwsEcsTaskFamily.Convert(), | ||
"aws.ecs.task.revision": r.AwsEcsTaskRevision.Convert(), | ||
"aws.log.group.arns": r.AwsLogGroupArns.Convert(), | ||
"aws.log.group.names": r.AwsLogGroupNames.Convert(), | ||
"aws.log.stream.arns": r.AwsLogStreamArns.Convert(), | ||
"aws.log.stream.names": r.AwsLogStreamNames.Convert(), | ||
"cloud.account.id": r.CloudAccountID.Convert(), | ||
"cloud.availability_zone": r.CloudAvailabilityZone.Convert(), | ||
"cloud.platform": r.CloudPlatform.Convert(), | ||
"cloud.provider": r.CloudProvider.Convert(), | ||
"cloud.region": r.CloudRegion.Convert(), | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
component/otelcol/processor/resourcedetection/internal/aws/eks/config.go
This file contains hidden or 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,46 @@ | ||
package eks | ||
|
||
import ( | ||
rac "github.com/grafana/agent/component/otelcol/processor/resourcedetection/internal/resource_attribute_config" | ||
"github.com/grafana/river" | ||
) | ||
|
||
const Name = "eks" | ||
|
||
type Config struct { | ||
ResourceAttributes ResourceAttributesConfig `river:"resource_attributes,block,optional"` | ||
} | ||
|
||
// DefaultArguments holds default settings for Config. | ||
var DefaultArguments = Config{ | ||
ResourceAttributes: ResourceAttributesConfig{ | ||
CloudPlatform: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudProvider: rac.ResourceAttributeConfig{Enabled: true}, | ||
}, | ||
} | ||
|
||
var _ river.Defaulter = (*Config)(nil) | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *Config) SetToDefault() { | ||
*args = DefaultArguments | ||
} | ||
|
||
func (args Config) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"resource_attributes": args.ResourceAttributes.Convert(), | ||
} | ||
} | ||
|
||
// ResourceAttributesConfig provides config for eks resource attributes. | ||
type ResourceAttributesConfig struct { | ||
CloudPlatform rac.ResourceAttributeConfig `river:"cloud.platform,block,optional"` | ||
CloudProvider rac.ResourceAttributeConfig `river:"cloud.provider,block,optional"` | ||
} | ||
|
||
func (r ResourceAttributesConfig) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"cloud.platform": r.CloudPlatform.Convert(), | ||
"cloud.provider": r.CloudProvider.Convert(), | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
component/otelcol/processor/resourcedetection/internal/aws/elasticbeanstalk/config.go
This file contains hidden or 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,55 @@ | ||
package elasticbeanstalk | ||
|
||
import ( | ||
rac "github.com/grafana/agent/component/otelcol/processor/resourcedetection/internal/resource_attribute_config" | ||
"github.com/grafana/river" | ||
) | ||
|
||
const Name = "elasticbeanstalk" | ||
|
||
type Config struct { | ||
ResourceAttributes ResourceAttributesConfig `river:"resource_attributes,block,optional"` | ||
} | ||
|
||
// DefaultArguments holds default settings for Config. | ||
var DefaultArguments = Config{ | ||
ResourceAttributes: ResourceAttributesConfig{ | ||
CloudPlatform: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudProvider: rac.ResourceAttributeConfig{Enabled: true}, | ||
DeploymentEnvironment: rac.ResourceAttributeConfig{Enabled: true}, | ||
ServiceInstanceID: rac.ResourceAttributeConfig{Enabled: true}, | ||
ServiceVersion: rac.ResourceAttributeConfig{Enabled: true}, | ||
}, | ||
} | ||
|
||
var _ river.Defaulter = (*Config)(nil) | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *Config) SetToDefault() { | ||
*args = DefaultArguments | ||
} | ||
|
||
func (args Config) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"resource_attributes": args.ResourceAttributes.Convert(), | ||
} | ||
} | ||
|
||
// ResourceAttributesConfig provides config for elastic_beanstalk resource attributes. | ||
type ResourceAttributesConfig struct { | ||
CloudPlatform rac.ResourceAttributeConfig `river:"cloud.platform,block,optional"` | ||
CloudProvider rac.ResourceAttributeConfig `river:"cloud.provider,block,optional"` | ||
DeploymentEnvironment rac.ResourceAttributeConfig `river:"deployment.environment,block,optional"` | ||
ServiceInstanceID rac.ResourceAttributeConfig `river:"service.instance.id,block,optional"` | ||
ServiceVersion rac.ResourceAttributeConfig `river:"service.version,block,optional"` | ||
} | ||
|
||
func (r ResourceAttributesConfig) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"cloud.platform": r.CloudPlatform.Convert(), | ||
"cloud.provider": r.CloudProvider.Convert(), | ||
"deployment.environment": r.DeploymentEnvironment.Convert(), | ||
"service.instance.id": r.ServiceInstanceID.Convert(), | ||
"service.version": r.ServiceVersion.Convert(), | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
component/otelcol/processor/resourcedetection/internal/aws/lambda/config.go
This file contains hidden or 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,67 @@ | ||
package lambda | ||
|
||
import ( | ||
rac "github.com/grafana/agent/component/otelcol/processor/resourcedetection/internal/resource_attribute_config" | ||
"github.com/grafana/river" | ||
) | ||
|
||
const Name = "lambda" | ||
|
||
type Config struct { | ||
ResourceAttributes ResourceAttributesConfig `river:"resource_attributes,block,optional"` | ||
} | ||
|
||
// DefaultArguments holds default settings for Config. | ||
var DefaultArguments = Config{ | ||
ResourceAttributes: ResourceAttributesConfig{ | ||
AwsLogGroupNames: rac.ResourceAttributeConfig{Enabled: true}, | ||
AwsLogStreamNames: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudPlatform: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudProvider: rac.ResourceAttributeConfig{Enabled: true}, | ||
CloudRegion: rac.ResourceAttributeConfig{Enabled: true}, | ||
FaasInstance: rac.ResourceAttributeConfig{Enabled: true}, | ||
FaasMaxMemory: rac.ResourceAttributeConfig{Enabled: true}, | ||
FaasName: rac.ResourceAttributeConfig{Enabled: true}, | ||
FaasVersion: rac.ResourceAttributeConfig{Enabled: true}, | ||
}, | ||
} | ||
|
||
var _ river.Defaulter = (*Config)(nil) | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *Config) SetToDefault() { | ||
*args = DefaultArguments | ||
} | ||
|
||
func (args Config) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"resource_attributes": args.ResourceAttributes.Convert(), | ||
} | ||
} | ||
|
||
// ResourceAttributesConfig provides config for lambda resource attributes. | ||
type ResourceAttributesConfig struct { | ||
AwsLogGroupNames rac.ResourceAttributeConfig `river:"aws.log.group.names,block,optional"` | ||
AwsLogStreamNames rac.ResourceAttributeConfig `river:"aws.log.stream.names,block,optional"` | ||
CloudPlatform rac.ResourceAttributeConfig `river:"cloud.platform,block,optional"` | ||
CloudProvider rac.ResourceAttributeConfig `river:"cloud.provider,block,optional"` | ||
CloudRegion rac.ResourceAttributeConfig `river:"cloud.region,block,optional"` | ||
FaasInstance rac.ResourceAttributeConfig `river:"faas.instance,block,optional"` | ||
FaasMaxMemory rac.ResourceAttributeConfig `river:"faas.max_memory,block,optional"` | ||
FaasName rac.ResourceAttributeConfig `river:"faas.name,block,optional"` | ||
FaasVersion rac.ResourceAttributeConfig `river:"faas.version,block,optional"` | ||
} | ||
|
||
func (r ResourceAttributesConfig) Convert() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"aws.log.group.names": r.AwsLogGroupNames.Convert(), | ||
"aws.log.stream.names": r.AwsLogStreamNames.Convert(), | ||
"cloud.platform": r.CloudPlatform.Convert(), | ||
"cloud.provider": r.CloudProvider.Convert(), | ||
"cloud.region": r.CloudRegion.Convert(), | ||
"faas.instance": r.FaasInstance.Convert(), | ||
"faas.max_memory": r.FaasMaxMemory.Convert(), | ||
"faas.name": r.FaasName.Convert(), | ||
"faas.version": r.FaasVersion.Convert(), | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.