diff --git a/config/config.go b/config/config.go index d90504e..9d52495 100644 --- a/config/config.go +++ b/config/config.go @@ -52,6 +52,10 @@ type Specification struct { DisableHostDiscovery bool `json:"disableHostDiscovery" split_words:"true" required:"false" default:"false"` DisableContainerDiscovery bool `json:"disableContainerDiscovery" split_words:"true" required:"false" default:"false"` + // Simulate Enrichments + EnrichmentHostToContainerEnabled bool `json:"enrichmentHostToContainerEnabled" split_words:"true" required:"false" default:"false"` + EnrichmentContainerToHostEnabled bool `json:"enrichmentContainerToHostEnabled" 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 new file mode 100644 index 0000000..3b0a4e0 --- /dev/null +++ b/extloadtest/enrichment_rule.go @@ -0,0 +1,80 @@ +package extloadtest + +import ( + "github.com/steadybit/discovery-kit/go/discovery_kit_api" + "github.com/steadybit/discovery-kit/go/discovery_kit_sdk" + "github.com/steadybit/extension-kit/extbuild" + "github.com/steadybit/extension-loadtest/config" +) + +type ltEnrichmentRuleProvider struct { +} + +var ( + _ discovery_kit_sdk.EnrichmentRulesDescriber = (*ltEnrichmentRuleProvider)(nil) +) + +func NewEnrichmentRuleProvider() discovery_kit_sdk.EnrichmentRulesDescriber { + return <EnrichmentRuleProvider{} +} + +func (d *ltEnrichmentRuleProvider) DescribeEnrichmentRules() []discovery_kit_api.TargetEnrichmentRule { + result := make([]discovery_kit_api.TargetEnrichmentRule, 0) + if config.Config.EnrichmentHostToContainerEnabled { + result = append(result, getHostToContainerEnrichmentRule()) + } + if config.Config.EnrichmentContainerToHostEnabled { + result = append(result, getContainerToHostEnrichmentRule()) + } + return result +} + +func getHostToContainerEnrichmentRule() discovery_kit_api.TargetEnrichmentRule { + return discovery_kit_api.TargetEnrichmentRule{ + Id: "com.steadybit.extension_loadtest.host-to-container", + Version: extbuild.GetSemverVersionStringOrUnknown(), + Src: discovery_kit_api.SourceOrDestination{ + Type: "com.steadybit.extension_host.host", + Selector: map[string]string{ + "host.hostname": "${dest.host.hostname}", + }, + }, + Dest: discovery_kit_api.SourceOrDestination{ + Type: "com.steadybit.extension_container.container", + Selector: map[string]string{ + "host.hostname": "${src.host.hostname}", + }, + }, + Attributes: []discovery_kit_api.Attribute{ + { + Matcher: discovery_kit_api.StartsWith, + Name: "host.os.", + }, + }, + } +} + +func getContainerToHostEnrichmentRule() discovery_kit_api.TargetEnrichmentRule { + return discovery_kit_api.TargetEnrichmentRule{ + Id: "com.steadybit.extension_loadtest.container-to-host", + Version: extbuild.GetSemverVersionStringOrUnknown(), + Src: discovery_kit_api.SourceOrDestination{ + Type: "com.steadybit.extension_container.container", + Selector: map[string]string{ + "host.hostname": "${dest.host.hostname}", + }, + }, + Dest: discovery_kit_api.SourceOrDestination{ + Type: "com.steadybit.extension_host.host", + Selector: map[string]string{ + "host.hostname": "${src.host.hostname}", + }, + }, + Attributes: []discovery_kit_api.Attribute{ + { + Matcher: discovery_kit_api.Equals, + Name: "container.id", + }, + }, + } +} diff --git a/main.go b/main.go index 3a6a4d3..12d1a3a 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,8 @@ func main() { targetData.RegisterDiscoveries() targetData.RegisterRecreateActions() + discovery_kit_sdk.Register(extloadtest.NewEnrichmentRuleProvider()) + action_kit_sdk.InstallSignalHandler() action_kit_sdk.RegisterCoverageEndpoints()