Skip to content

Commit

Permalink
feat: added to dummy enrichment rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ReuDa committed Jul 5, 2024
1 parent 15dff94 commit b82a069
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
80 changes: 80 additions & 0 deletions extloadtest/enrichment_rule.go
Original file line number Diff line number Diff line change
@@ -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 &ltEnrichmentRuleProvider{}
}

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",
},
},
}
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func main() {
targetData.RegisterDiscoveries()
targetData.RegisterRecreateActions()

discovery_kit_sdk.Register(extloadtest.NewEnrichmentRuleProvider())

action_kit_sdk.InstallSignalHandler()
action_kit_sdk.RegisterCoverageEndpoints()

Expand Down

0 comments on commit b82a069

Please sign in to comment.