Skip to content

Commit

Permalink
Remove instrumentedApplication from instrumentor/instrumentationconfig (
Browse files Browse the repository at this point in the history
#2126)

* When updating the `instrumentationConfig` spec (e.g. `SdkConfig`s)
rely on the runtime detauls written in the status of the
`instrumentationConfig`.
* Create a common predicate to the instrumentor controller which passes
events where the runtime details in the `instrumentationConfig` have
been updated - currently only checking the length of the slice and this
will be improved in the future.
  • Loading branch information
RonFed authored Jan 5, 2025
1 parent 52ee331 commit 40959c0
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 226 deletions.
10 changes: 5 additions & 5 deletions instrumentor/controllers/instrumentationconfig/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func updateInstrumentationConfigForWorkload(ic *odigosv1alpha1.InstrumentationConfig, ia *odigosv1alpha1.InstrumentedApplication, rules *odigosv1alpha1.InstrumentationRuleList, serviceName string) error {
func updateInstrumentationConfigForWorkload(ic *odigosv1alpha1.InstrumentationConfig, rules *odigosv1alpha1.InstrumentationRuleList, serviceName string) error {

workloadName, workloadKind, err := workload.ExtractWorkloadInfoFromRuntimeObjectName(ia.Name)
workloadName, workloadKind, err := workload.ExtractWorkloadInfoFromRuntimeObjectName(ic.Name)
if err != nil {
return err
}
workload := workload.PodWorkload{
Name: workloadName,
Namespace: ia.Namespace,
Namespace: ic.Namespace,
Kind: workloadKind,
}

ic.Spec.ServiceName = serviceName

sdkConfigs := make([]odigosv1alpha1.SdkConfig, 0, len(ia.Spec.RuntimeDetails))
sdkConfigs := make([]odigosv1alpha1.SdkConfig, 0, len(ic.Status.RuntimeDetailsByContainer))

// create an empty sdk config for each detected programming language
for _, container := range ia.Spec.RuntimeDetails {
for _, container := range ic.Status.RuntimeDetailsByContainer {
containerLanguage := container.Language
if containerLanguage == common.IgnoredProgrammingLanguage || containerLanguage == common.UnknownProgrammingLanguage {
continue
Expand Down
159 changes: 41 additions & 118 deletions instrumentor/controllers/instrumentationconfig/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,23 @@ import (
)

func TestUpdateInstrumentationConfigForWorkload_SingleLanguage(t *testing.T) {

ic := odigosv1.InstrumentationConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
}},
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
},
},
},
}
rules := &odigosv1.InstrumentationRuleList{}
err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -45,21 +40,14 @@ func TestUpdateInstrumentationConfigForWorkload_SingleLanguage(t *testing.T) {
}

func TestUpdateInstrumentationConfigForWorkload_MultipleLanguages(t *testing.T) {

ic := odigosv1.InstrumentationConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container-1",
Language: common.JavascriptProgrammingLanguage,
Expand All @@ -72,7 +60,7 @@ func TestUpdateInstrumentationConfigForWorkload_MultipleLanguages(t *testing.T)
},
}
rules := &odigosv1.InstrumentationRuleList{}
err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -95,14 +83,8 @@ func TestUpdateInstrumentationConfigForWorkload_IgnoreUnknownLanguage(t *testing
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container-1",
Language: common.JavascriptProgrammingLanguage,
Expand All @@ -119,7 +101,7 @@ func TestUpdateInstrumentationConfigForWorkload_IgnoreUnknownLanguage(t *testing
},
}
rules := &odigosv1.InstrumentationRuleList{}
err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -139,18 +121,12 @@ func TestUpdateInstrumentationConfigForWorkload_NoLanguages(t *testing.T) {
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{},
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{},
},
}
rules := &odigosv1.InstrumentationRuleList{}
err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -160,21 +136,14 @@ func TestUpdateInstrumentationConfigForWorkload_NoLanguages(t *testing.T) {
}

func TestUpdateInstrumentationConfigForWorkload_SameLanguageMultipleContainers(t *testing.T) {

ic := odigosv1.InstrumentationConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container-1",
Language: common.JavascriptProgrammingLanguage,
Expand All @@ -187,7 +156,7 @@ func TestUpdateInstrumentationConfigForWorkload_SameLanguageMultipleContainers(t
},
}
rules := &odigosv1.InstrumentationRuleList{}
err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -200,21 +169,14 @@ func TestUpdateInstrumentationConfigForWorkload_SameLanguageMultipleContainers(t
}

func TestUpdateInstrumentationConfigForWorkload_SingleMatchingRule(t *testing.T) {

ic := odigosv1.InstrumentationConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
Expand All @@ -237,7 +199,7 @@ func TestUpdateInstrumentationConfigForWorkload_SingleMatchingRule(t *testing.T)
},
},
}
err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand Down Expand Up @@ -266,14 +228,8 @@ func TestUpdateInstrumentationConfigForWorkload_InWorkloadList(t *testing.T) {
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
Expand Down Expand Up @@ -303,7 +259,7 @@ func TestUpdateInstrumentationConfigForWorkload_InWorkloadList(t *testing.T) {
},
}

err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -316,21 +272,14 @@ func TestUpdateInstrumentationConfigForWorkload_InWorkloadList(t *testing.T) {
}

func TestUpdateInstrumentationConfigForWorkload_NotInWorkloadList(t *testing.T) {

ic := odigosv1.InstrumentationConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
Expand Down Expand Up @@ -360,7 +309,7 @@ func TestUpdateInstrumentationConfigForWorkload_NotInWorkloadList(t *testing.T)
},
}

err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -374,21 +323,14 @@ func TestUpdateInstrumentationConfigForWorkload_NotInWorkloadList(t *testing.T)
}

func TestUpdateInstrumentationConfigForWorkload_DisabledRule(t *testing.T) {

ic := odigosv1.InstrumentationConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
Expand All @@ -412,7 +354,7 @@ func TestUpdateInstrumentationConfigForWorkload_DisabledRule(t *testing.T) {
},
}

err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -426,21 +368,14 @@ func TestUpdateInstrumentationConfigForWorkload_DisabledRule(t *testing.T) {
}

func TestUpdateInstrumentationConfigForWorkload_MultipleDefaultRules(t *testing.T) {

ic := odigosv1.InstrumentationConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
Expand Down Expand Up @@ -476,7 +411,7 @@ func TestUpdateInstrumentationConfigForWorkload_MultipleDefaultRules(t *testing.
},
}

err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand Down Expand Up @@ -531,14 +466,8 @@ func TestUpdateInstrumentationConfigForWorkload_RuleForLibrary(t *testing.T) {
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
Expand Down Expand Up @@ -567,7 +496,7 @@ func TestUpdateInstrumentationConfigForWorkload_RuleForLibrary(t *testing.T) {
},
}

err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand All @@ -593,14 +522,8 @@ func TestUpdateInstrumentationConfigForWorkload_LibraryRuleOtherLanguage(t *test
Namespace: "testns",
},
Spec: odigosv1.InstrumentationConfigSpec{},
}
ia := odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-test",
Namespace: "testns",
},
Spec: odigosv1.InstrumentedApplicationSpec{
RuntimeDetails: []odigosv1.RuntimeDetailsByContainer{
Status: odigosv1.InstrumentationConfigStatus{
RuntimeDetailsByContainer: []odigosv1.RuntimeDetailsByContainer{
{
ContainerName: "test-container",
Language: common.JavascriptProgrammingLanguage,
Expand Down Expand Up @@ -630,7 +553,7 @@ func TestUpdateInstrumentationConfigForWorkload_LibraryRuleOtherLanguage(t *test
},
}

err := updateInstrumentationConfigForWorkload(&ic, &ia, rules, "service-name")
err := updateInstrumentationConfigForWorkload(&ic, rules, "service-name")
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}
Expand Down
Loading

0 comments on commit 40959c0

Please sign in to comment.