From d79988e2a707c37e965bd7090db49a39e2a1231b Mon Sep 17 00:00:00 2001 From: Ansgar Schulte <1299623+ansgarschulte@users.noreply.github.com> Date: Mon, 8 Jul 2024 11:33:06 +0200 Subject: [PATCH] feat: add enrichment rule from ec2 to host --- config/config.go | 1 + extloadtest/enrichment_rule.go | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/config/config.go b/config/config.go index 9d52495..ff0a6b7 100644 --- a/config/config.go +++ b/config/config.go @@ -55,6 +55,7 @@ type Specification struct { // Simulate Enrichments EnrichmentHostToContainerEnabled bool `json:"enrichmentHostToContainerEnabled" split_words:"true" required:"false" default:"false"` EnrichmentContainerToHostEnabled bool `json:"enrichmentContainerToHostEnabled" split_words:"true" required:"false" default:"false"` + EnrichmentEC2ToHostEnabled bool `json:"enrichmentEC2ToHostEnabled" split_words:"true" required:"false" default:"false"` // discovery delay in ms DiscoveryDelayInMs int `json:"discoveryDelayInMs" split_words:"true" required:"false" default:"0"` diff --git a/extloadtest/enrichment_rule.go b/extloadtest/enrichment_rule.go index 3b0a4e0..1141d9d 100644 --- a/extloadtest/enrichment_rule.go +++ b/extloadtest/enrichment_rule.go @@ -26,6 +26,9 @@ func (d *ltEnrichmentRuleProvider) DescribeEnrichmentRules() []discovery_kit_api if config.Config.EnrichmentContainerToHostEnabled { result = append(result, getContainerToHostEnrichmentRule()) } + if config.Config.EnrichmentEC2ToHostEnabled { + result = append(result, getEC2ToHostEnrichmentRule()) + } return result } @@ -78,3 +81,50 @@ func getContainerToHostEnrichmentRule() discovery_kit_api.TargetEnrichmentRule { }, } } +func getEC2ToHostEnrichmentRule() discovery_kit_api.TargetEnrichmentRule { + return discovery_kit_api.TargetEnrichmentRule{ + Id: "com.steadybit.extension_loadtest.ec2-to-host", + Version: extbuild.GetSemverVersionStringOrUnknown(), + Src: discovery_kit_api.SourceOrDestination{ + Type: "com.steadybit.extension_aws.ec2-instance", + Selector: map[string]string{ + "aws-ec2.hostname.internal": "${dest.host.hostname}", + }, + }, + Dest: discovery_kit_api.SourceOrDestination{ + Type: "com.steadybit.extension_host.host", + Selector: map[string]string{ + "host.hostname": "${src.aws-ec2.hostname.internal}", + }, + }, + Attributes: []discovery_kit_api.Attribute{ + { + Matcher: discovery_kit_api.Equals, + Name: "aws.account", + }, { + Matcher: discovery_kit_api.Equals, + Name: "aws.region", + }, + { + Matcher: discovery_kit_api.Equals, + Name: "aws.zone", + }, + { + Matcher: discovery_kit_api.Equals, + Name: "aws-ec2.arn", + }, + { + Matcher: discovery_kit_api.Equals, + Name: "aws-ec2.instance.id", + }, + { + Matcher: discovery_kit_api.Equals, + Name: "aws-ec2.instance.name", + }, + { + Matcher: discovery_kit_api.StartsWith, + Name: "aws-ec2.label.", + }, + }, + } +}