From a46ffae2e13b96a36ddad8ed4b6e2287f14beddb Mon Sep 17 00:00:00 2001 From: Louise Harlen Date: Thu, 16 May 2024 07:01:16 +0100 Subject: [PATCH 1/7] add application_id tag --- enricher/mappings/mappings.go | 1 + 1 file changed, 1 insertion(+) diff --git a/enricher/mappings/mappings.go b/enricher/mappings/mappings.go index ccf88e2..4a813a4 100644 --- a/enricher/mappings/mappings.go +++ b/enricher/mappings/mappings.go @@ -22,6 +22,7 @@ const ( ) const ( + RESOURCE_APPLICATION_ID = "application_id" RESOURCE_FIELD_NAME = "resource" RESOURCE_SERVICE_NAME = "service.name" RESOURCE_PARTITION = "cloud.partition" From a8f060a78d18fac1aa32ca4df32a142a912e33e0 Mon Sep 17 00:00:00 2001 From: Louise Harlen Date: Thu, 16 May 2024 14:46:35 +0100 Subject: [PATCH 2/7] rest of the changes --- enricher/ecs/ecs.go | 21 ++++++++++++++------- enricher/mappings/mappings.go | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/enricher/ecs/ecs.go b/enricher/ecs/ecs.go index 3e8ecd5..6565917 100644 --- a/enricher/ecs/ecs.go +++ b/enricher/ecs/ecs.go @@ -13,7 +13,9 @@ import ( type Enricher struct { canvaAWSAccount string + canvaAppId string canvaAppName string + canvaComponent string logGroup string ecsTaskFamily string ecsTaskRevision int @@ -45,7 +47,9 @@ func NewEnricher() *Enricher { return &Enricher{ canvaAWSAccount: os.Getenv("CANVA_AWS_ACCOUNT"), + canvaAppId: os.Getenv("CANVA_APP_ID"), canvaAppName: os.Getenv("CANVA_APP_NAME"), + canvaComponent: os.Getenv("CANVA_COMPONENT"), logGroup: os.Getenv("LOG_GROUP"), ecsTaskFamily: ecsTaskFamily, ecsTaskRevision: ecsTaskRevision, @@ -55,13 +59,16 @@ func NewEnricher() *Enricher { // EnrichRecord modifies existing record. func (enr *Enricher) EnrichRecord(r map[interface{}]interface{}, t time.Time) map[interface{}]interface{} { resource := map[interface{}]interface{}{ - mappings.RESOURCE_ACCOUNT_ID: enr.canvaAWSAccount, - "service.name": enr.canvaAppName, - "cloud.platform": "aws_ecs", - "aws.ecs.launchtype": "EC2", - "aws.ecs.task.family": enr.ecsTaskFamily, - "aws.ecs.task.revision": enr.ecsTaskRevision, - "aws.log.group.names": enr.logGroup, + mappings.RESOURCE_ACCOUNT_ID: enr.canvaAWSAccount, + mappings.RESOURCE_APPLICATION_ID: enr.canvaAppId, + mappings.RESOURCE_COMPONENT: enr.canvaComponent, + mappings.RESOURCE_SERVICE_NAME: enr.canvaAppName, + "service.name": enr.canvaAppName, + "cloud.platform": "aws_ecs", + "aws.ecs.launchtype": "EC2", + "aws.ecs.task.family": enr.ecsTaskFamily, + "aws.ecs.task.revision": enr.ecsTaskRevision, + "aws.log.group.names": enr.logGroup, } body := make(map[interface{}]interface{}) diff --git a/enricher/mappings/mappings.go b/enricher/mappings/mappings.go index 4a813a4..122fa95 100644 --- a/enricher/mappings/mappings.go +++ b/enricher/mappings/mappings.go @@ -33,6 +33,7 @@ const ( RESOURCE_ORGANIZATION = "organization" RESOURCE_PLATFORM = "cloud.platform" RESOURCE_PROVIDER = "cloud.provider" + RESOURCE_COMPONENT = "component" ) const ( From 4af7734f3bd514556f39c08be6920e089f87d12f Mon Sep 17 00:00:00 2001 From: Louise Harlen Date: Thu, 16 May 2024 14:49:50 +0100 Subject: [PATCH 3/7] Remove duplicate service.name --- enricher/ecs/ecs.go | 1 - 1 file changed, 1 deletion(-) diff --git a/enricher/ecs/ecs.go b/enricher/ecs/ecs.go index 6565917..51daf20 100644 --- a/enricher/ecs/ecs.go +++ b/enricher/ecs/ecs.go @@ -63,7 +63,6 @@ func (enr *Enricher) EnrichRecord(r map[interface{}]interface{}, t time.Time) ma mappings.RESOURCE_APPLICATION_ID: enr.canvaAppId, mappings.RESOURCE_COMPONENT: enr.canvaComponent, mappings.RESOURCE_SERVICE_NAME: enr.canvaAppName, - "service.name": enr.canvaAppName, "cloud.platform": "aws_ecs", "aws.ecs.launchtype": "EC2", "aws.ecs.task.family": enr.ecsTaskFamily, From c2e9949e8151c9a0c49f65c0f962bc2da2a75750 Mon Sep 17 00:00:00 2001 From: Louise Harlen Date: Thu, 16 May 2024 15:26:38 +0100 Subject: [PATCH 4/7] fix tests --- enricher/ecs/ecs_test.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/enricher/ecs/ecs_test.go b/enricher/ecs/ecs_test.go index 1ea01ad..a5f84e6 100644 --- a/enricher/ecs/ecs_test.go +++ b/enricher/ecs/ecs_test.go @@ -24,7 +24,9 @@ func TestEnrichRecords(t *testing.T) { name: "enrich", enr: &Enricher{ canvaAWSAccount: "canva_aws_account_val", + canvaAppId: "canva_app_id_val", canvaAppName: "canva_app_name_val", + canvaComponent: "canva_component_val", logGroup: "log_group_val", ecsTaskFamily: "ecs_task_family_val", ecsTaskRevision: 10001, @@ -46,18 +48,20 @@ func TestEnrichRecords(t *testing.T) { }, want: map[interface{}]interface{}{ mappings.RESOURCE_FIELD_NAME: map[interface{}]interface{}{ - mappings.RESOURCE_ACCOUNT_ID: "canva_aws_account_val", - "service.name": "canva_app_name_val", - "cloud.platform": "aws_ecs", - "aws.ecs.launchtype": "EC2", - "aws.ecs.task.family": "ecs_task_family_val", - "aws.ecs.task.revision": 10001, - "aws.log.group.names": "log_group_val", - "host.id": "ec2_instance_id_val", - "aws.ecs.cluster.name": "ecs_cluster_val", - "aws.ecs.task.arn": "ecs_task_arn_val", - "container.id": "container_id_val", - "container.name": "container_name_val", + mappings.RESOURCE_ACCOUNT_ID: "canva_aws_account_val", + mappings.RESOURCE_APPLICATION_ID: "canva_app_id_val", + mappings.RESOURCE_COMPONENT: "canva_component_val", + mappings.RESOURCE_SERVICE_NAME: "canva_app_name_val", + "cloud.platform": "aws_ecs", + "aws.ecs.launchtype": "EC2", + "aws.ecs.task.family": "ecs_task_family_val", + "aws.ecs.task.revision": 10001, + "aws.log.group.names": "log_group_val", + "host.id": "ec2_instance_id_val", + "aws.ecs.cluster.name": "ecs_cluster_val", + "aws.ecs.task.arn": "ecs_task_arn_val", + "container.id": "container_id_val", + "container.name": "container_name_val", }, "body": map[interface{}]interface{}{ "other_key_1": "other_value_1", From 68d4ddf393556987d6dcd9140660a6d3a08fef44 Mon Sep 17 00:00:00 2001 From: Louise Harlen Date: Mon, 20 May 2024 20:50:36 +0100 Subject: [PATCH 5/7] comments --- enricher/ecs/ecs.go | 32 ++++++++++++++++---------------- enricher/ecs/ecs_test.go | 14 +++++++------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/enricher/ecs/ecs.go b/enricher/ecs/ecs.go index 51daf20..315c906 100644 --- a/enricher/ecs/ecs.go +++ b/enricher/ecs/ecs.go @@ -12,13 +12,13 @@ import ( ) type Enricher struct { - canvaAWSAccount string - canvaAppId string - canvaAppName string - canvaComponent string - logGroup string - ecsTaskFamily string - ecsTaskRevision int + canvaAWSAccount string + canvaApplicationId string + canvaAppName string + canvaComponent string + logGroup string + ecsTaskFamily string + ecsTaskRevision int } var _ enricher.IEnricher = (*Enricher)(nil) @@ -46,13 +46,13 @@ func NewEnricher() *Enricher { } return &Enricher{ - canvaAWSAccount: os.Getenv("CANVA_AWS_ACCOUNT"), - canvaAppId: os.Getenv("CANVA_APP_ID"), - canvaAppName: os.Getenv("CANVA_APP_NAME"), - canvaComponent: os.Getenv("CANVA_COMPONENT"), - logGroup: os.Getenv("LOG_GROUP"), - ecsTaskFamily: ecsTaskFamily, - ecsTaskRevision: ecsTaskRevision, + canvaAWSAccount: os.Getenv("CANVA_AWS_ACCOUNT"), + canvaApplicationId: os.Getenv("CANVA_APP_ID"), + canvaAppName: os.Getenv("CANVA_APP_NAME"), + canvaComponent: os.Getenv("CANVA_COMPONENT"), + logGroup: os.Getenv("LOG_GROUP"), + ecsTaskFamily: ecsTaskFamily, + ecsTaskRevision: ecsTaskRevision, } } @@ -60,9 +60,9 @@ func NewEnricher() *Enricher { func (enr *Enricher) EnrichRecord(r map[interface{}]interface{}, t time.Time) map[interface{}]interface{} { resource := map[interface{}]interface{}{ mappings.RESOURCE_ACCOUNT_ID: enr.canvaAWSAccount, - mappings.RESOURCE_APPLICATION_ID: enr.canvaAppId, + mappings.RESOURCE_APPLICATION_ID: enr.canvaApplicationId, mappings.RESOURCE_COMPONENT: enr.canvaComponent, - mappings.RESOURCE_SERVICE_NAME: enr.canvaAppName, + "service.name": enr.canvaAppName, "cloud.platform": "aws_ecs", "aws.ecs.launchtype": "EC2", "aws.ecs.task.family": enr.ecsTaskFamily, diff --git a/enricher/ecs/ecs_test.go b/enricher/ecs/ecs_test.go index a5f84e6..0984573 100644 --- a/enricher/ecs/ecs_test.go +++ b/enricher/ecs/ecs_test.go @@ -23,13 +23,13 @@ func TestEnrichRecords(t *testing.T) { { name: "enrich", enr: &Enricher{ - canvaAWSAccount: "canva_aws_account_val", - canvaAppId: "canva_app_id_val", - canvaAppName: "canva_app_name_val", - canvaComponent: "canva_component_val", - logGroup: "log_group_val", - ecsTaskFamily: "ecs_task_family_val", - ecsTaskRevision: 10001, + canvaAWSAccount: "canva_aws_account_val", + canvaApplicationId: "canva_application_id_val", + canvaAppName: "canva_app_name_val", + canvaComponent: "canva_component_val", + logGroup: "log_group_val", + ecsTaskFamily: "ecs_task_family_val", + ecsTaskRevision: 10001, }, args: args{ map[interface{}]interface{}{ From 4e8e2eafcf08267a68edd58d2e81bde8cd627ba4 Mon Sep 17 00:00:00 2001 From: Louise Harlen Date: Mon, 20 May 2024 20:53:38 +0100 Subject: [PATCH 6/7] fix test --- enricher/ecs/ecs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enricher/ecs/ecs_test.go b/enricher/ecs/ecs_test.go index 0984573..6df7874 100644 --- a/enricher/ecs/ecs_test.go +++ b/enricher/ecs/ecs_test.go @@ -49,7 +49,7 @@ func TestEnrichRecords(t *testing.T) { want: map[interface{}]interface{}{ mappings.RESOURCE_FIELD_NAME: map[interface{}]interface{}{ mappings.RESOURCE_ACCOUNT_ID: "canva_aws_account_val", - mappings.RESOURCE_APPLICATION_ID: "canva_app_id_val", + mappings.RESOURCE_APPLICATION_ID: "canva_application_id_val", mappings.RESOURCE_COMPONENT: "canva_component_val", mappings.RESOURCE_SERVICE_NAME: "canva_app_name_val", "cloud.platform": "aws_ecs", From c5cdb0c6d1654a3864068f73cce85f59140c7e23 Mon Sep 17 00:00:00 2001 From: Louise Harlen Date: Tue, 21 May 2024 07:58:23 +0100 Subject: [PATCH 7/7] rename applicaiton_id env var --- enricher/ecs/ecs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enricher/ecs/ecs.go b/enricher/ecs/ecs.go index 315c906..11f9141 100644 --- a/enricher/ecs/ecs.go +++ b/enricher/ecs/ecs.go @@ -47,7 +47,7 @@ func NewEnricher() *Enricher { return &Enricher{ canvaAWSAccount: os.Getenv("CANVA_AWS_ACCOUNT"), - canvaApplicationId: os.Getenv("CANVA_APP_ID"), + canvaApplicationId: os.Getenv("CANVA_APPLICATION_ID"), canvaAppName: os.Getenv("CANVA_APP_NAME"), canvaComponent: os.Getenv("CANVA_COMPONENT"), logGroup: os.Getenv("LOG_GROUP"),