|
| 1 | +package ecs |
| 2 | + |
| 3 | +import ( |
| 4 | + rac "github.com/grafana/agent/component/otelcol/processor/resourcedetection/internal/resource_attribute_config" |
| 5 | + "github.com/grafana/river" |
| 6 | +) |
| 7 | + |
| 8 | +const Name = "ecs" |
| 9 | + |
| 10 | +type Config struct { |
| 11 | + ResourceAttributes ResourceAttributesConfig `river:"resource_attributes,block,optional"` |
| 12 | +} |
| 13 | + |
| 14 | +// DefaultArguments holds default settings for Config. |
| 15 | +var DefaultArguments = Config{ |
| 16 | + ResourceAttributes: ResourceAttributesConfig{ |
| 17 | + AwsEcsClusterArn: rac.ResourceAttributeConfig{Enabled: true}, |
| 18 | + AwsEcsLaunchtype: rac.ResourceAttributeConfig{Enabled: true}, |
| 19 | + AwsEcsTaskArn: rac.ResourceAttributeConfig{Enabled: true}, |
| 20 | + AwsEcsTaskFamily: rac.ResourceAttributeConfig{Enabled: true}, |
| 21 | + AwsEcsTaskRevision: rac.ResourceAttributeConfig{Enabled: true}, |
| 22 | + AwsLogGroupArns: rac.ResourceAttributeConfig{Enabled: true}, |
| 23 | + AwsLogGroupNames: rac.ResourceAttributeConfig{Enabled: true}, |
| 24 | + AwsLogStreamArns: rac.ResourceAttributeConfig{Enabled: true}, |
| 25 | + AwsLogStreamNames: rac.ResourceAttributeConfig{Enabled: true}, |
| 26 | + CloudAccountID: rac.ResourceAttributeConfig{Enabled: true}, |
| 27 | + CloudAvailabilityZone: rac.ResourceAttributeConfig{Enabled: true}, |
| 28 | + CloudPlatform: rac.ResourceAttributeConfig{Enabled: true}, |
| 29 | + CloudProvider: rac.ResourceAttributeConfig{Enabled: true}, |
| 30 | + CloudRegion: rac.ResourceAttributeConfig{Enabled: true}, |
| 31 | + }, |
| 32 | +} |
| 33 | + |
| 34 | +var _ river.Defaulter = (*Config)(nil) |
| 35 | + |
| 36 | +// SetToDefault implements river.Defaulter. |
| 37 | +func (args *Config) SetToDefault() { |
| 38 | + *args = DefaultArguments |
| 39 | +} |
| 40 | + |
| 41 | +func (args *Config) Convert() map[string]interface{} { |
| 42 | + if args == nil { |
| 43 | + return nil |
| 44 | + } |
| 45 | + |
| 46 | + return map[string]interface{}{ |
| 47 | + "resource_attributes": args.ResourceAttributes.Convert(), |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +// ResourceAttributesConfig provides config for ecs resource attributes. |
| 52 | +type ResourceAttributesConfig struct { |
| 53 | + AwsEcsClusterArn rac.ResourceAttributeConfig `river:"aws.ecs.cluster.arn,block,optional"` |
| 54 | + AwsEcsLaunchtype rac.ResourceAttributeConfig `river:"aws.ecs.launchtype,block,optional"` |
| 55 | + AwsEcsTaskArn rac.ResourceAttributeConfig `river:"aws.ecs.task.arn,block,optional"` |
| 56 | + AwsEcsTaskFamily rac.ResourceAttributeConfig `river:"aws.ecs.task.family,block,optional"` |
| 57 | + AwsEcsTaskRevision rac.ResourceAttributeConfig `river:"aws.ecs.task.revision,block,optional"` |
| 58 | + AwsLogGroupArns rac.ResourceAttributeConfig `river:"aws.log.group.arns,block,optional"` |
| 59 | + AwsLogGroupNames rac.ResourceAttributeConfig `river:"aws.log.group.names,block,optional"` |
| 60 | + AwsLogStreamArns rac.ResourceAttributeConfig `river:"aws.log.stream.arns,block,optional"` |
| 61 | + AwsLogStreamNames rac.ResourceAttributeConfig `river:"aws.log.stream.names,block,optional"` |
| 62 | + CloudAccountID rac.ResourceAttributeConfig `river:"cloud.account.id,block,optional"` |
| 63 | + CloudAvailabilityZone rac.ResourceAttributeConfig `river:"cloud.availability_zone,block,optional"` |
| 64 | + CloudPlatform rac.ResourceAttributeConfig `river:"cloud.platform,block,optional"` |
| 65 | + CloudProvider rac.ResourceAttributeConfig `river:"cloud.provider,block,optional"` |
| 66 | + CloudRegion rac.ResourceAttributeConfig `river:"cloud.region,block,optional"` |
| 67 | +} |
| 68 | + |
| 69 | +func (r ResourceAttributesConfig) Convert() map[string]interface{} { |
| 70 | + return map[string]interface{}{ |
| 71 | + "aws.ecs.cluster.arn": r.AwsEcsClusterArn.Convert(), |
| 72 | + "aws.ecs.launchtype": r.AwsEcsLaunchtype.Convert(), |
| 73 | + "aws.ecs.task.arn": r.AwsEcsTaskArn.Convert(), |
| 74 | + "aws.ecs.task.family": r.AwsEcsTaskFamily.Convert(), |
| 75 | + "aws.ecs.task.revision": r.AwsEcsTaskRevision.Convert(), |
| 76 | + "aws.log.group.arns": r.AwsLogGroupArns.Convert(), |
| 77 | + "aws.log.group.names": r.AwsLogGroupNames.Convert(), |
| 78 | + "aws.log.stream.arns": r.AwsLogStreamArns.Convert(), |
| 79 | + "aws.log.stream.names": r.AwsLogStreamNames.Convert(), |
| 80 | + "cloud.account.id": r.CloudAccountID.Convert(), |
| 81 | + "cloud.availability_zone": r.CloudAvailabilityZone.Convert(), |
| 82 | + "cloud.platform": r.CloudPlatform.Convert(), |
| 83 | + "cloud.provider": r.CloudProvider.Convert(), |
| 84 | + "cloud.region": r.CloudRegion.Convert(), |
| 85 | + } |
| 86 | +} |
0 commit comments