Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update describe to rely on Sources #2378

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
640 changes: 320 additions & 320 deletions frontend/graph/generated.go

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions frontend/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ type EntityProperty {
explain: String
}

type InstrumentationLabelsAnalyze {
type InstrumentationSourcesAnalyze {
instrumented: EntityProperty!
workload: EntityProperty
namespace: EntityProperty
Expand Down Expand Up @@ -536,7 +536,7 @@ type SourceAnalyze {
name: EntityProperty!
kind: EntityProperty!
namespace: EntityProperty!
labels: InstrumentationLabelsAnalyze!
sourceObjects: InstrumentationSourcesAnalyze!

runtimeInfo: RuntimeInfoAnalyze!
instrumentationConfig: InstrumentationConfigAnalyze!
Expand Down
10 changes: 5 additions & 5 deletions frontend/services/describe/source_describe/source_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func ConvertSourceAnalyzeToGQL(analyze *source.SourceAnalyze) *model.SourceAnaly
Name: describe_utils.ConvertEntityPropertyToGQL(&analyze.Name),
Kind: describe_utils.ConvertEntityPropertyToGQL(&analyze.Kind),
Namespace: describe_utils.ConvertEntityPropertyToGQL(&analyze.Namespace),
Labels: &model.InstrumentationLabelsAnalyze{
Instrumented: describe_utils.ConvertEntityPropertyToGQL(&analyze.Labels.Instrumented),
Workload: describe_utils.ConvertEntityPropertyToGQL(analyze.Labels.Workload),
Namespace: describe_utils.ConvertEntityPropertyToGQL(analyze.Labels.Namespace),
InstrumentedText: describe_utils.ConvertEntityPropertyToGQL(&analyze.Labels.InstrumentedText),
SourceObjects: &model.InstrumentationSourcesAnalyze{
Instrumented: describe_utils.ConvertEntityPropertyToGQL(&analyze.SourceObjectsAnalysis.Instrumented),
Workload: describe_utils.ConvertEntityPropertyToGQL(analyze.SourceObjectsAnalysis.Workload),
Namespace: describe_utils.ConvertEntityPropertyToGQL(analyze.SourceObjectsAnalysis.Namespace),
InstrumentedText: describe_utils.ConvertEntityPropertyToGQL(&analyze.SourceObjectsAnalysis.InstrumentedText),
},
RuntimeInfo: convertRuntimeInfoToGQL(analyze.RuntimeInfo),
InstrumentationConfig: &model.InstrumentationConfigAnalyze{
Expand Down
2 changes: 1 addition & 1 deletion frontend/webapp/graphql/queries/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const DESCRIBE_SOURCE = gql`
status
explain
}
labels {
sourceObjects {
instrumented {
name
value
Expand Down
2 changes: 1 addition & 1 deletion frontend/webapp/hooks/describe/useDescribeSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useDescribeSource = ({ namespace, name, kind }: WorkloadId) => {
};

Object.values(code).forEach((val) => mapObjects(val));
Object.values(code.labels).forEach((val) => mapObjects(val, 'Labels'));
Object.values(code.sourceObjects).forEach((val) => mapObjects(val, 'Sources'));
Object.values(code.instrumentationConfig).forEach((val) => mapObjects(val, 'Instrumentation Config'));
code.runtimeInfo?.containers?.forEach((obj, i) => Object.values(obj).forEach((val) => mapObjects(val, 'Runtime Info', { keyPrefix: `Container #${i + 1} - ` })));
Object.values(code.instrumentationDevice).forEach((val) => mapObjects(val, 'Instrumentation Device'));
Expand Down
4 changes: 2 additions & 2 deletions frontend/webapp/types/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface EntityProperty {
explain?: string;
}

interface InstrumentationLabelsAnalyze {
interface InstrumentationSourcesAnalyze {
instrumented: EntityProperty;
workload?: EntityProperty;
namespace?: EntityProperty;
Expand Down Expand Up @@ -64,7 +64,7 @@ interface SourceAnalyze {
name: EntityProperty;
kind: EntityProperty;
namespace: EntityProperty;
labels: InstrumentationLabelsAnalyze;
sourceObjects: InstrumentationSourcesAnalyze;

runtimeInfo?: RuntimeInfoAnalyze;
instrumentationConfig: InstrumentationConfigAnalyze;
Expand Down
15 changes: 8 additions & 7 deletions k8sutils/pkg/describe/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"k8s.io/client-go/kubernetes"

odigosclientset "github.com/odigos-io/odigos/api/generated/odigos/clientset/versioned/typed/odigos/v1alpha1"
"github.com/odigos-io/odigos/api/k8sconsts"
"github.com/odigos-io/odigos/k8sutils/pkg/describe/source"
)

Expand All @@ -18,10 +19,10 @@ func printWorkloadManifestInfo(analyze *source.SourceAnalyze, sb *strings.Builde
printProperty(sb, 0, &analyze.Namespace)

sb.WriteString("Labels:\n")
printProperty(sb, 1, &analyze.Labels.Instrumented)
printProperty(sb, 1, analyze.Labels.Workload)
printProperty(sb, 1, analyze.Labels.Namespace)
printProperty(sb, 1, &analyze.Labels.InstrumentedText)
printProperty(sb, 1, &analyze.SourceObjectsAnalysis.Instrumented)
printProperty(sb, 1, analyze.SourceObjectsAnalysis.Workload)
printProperty(sb, 1, analyze.SourceObjectsAnalysis.Namespace)
printProperty(sb, 1, &analyze.SourceObjectsAnalysis.InstrumentedText)
}

func printRuntimeDetails(analyze *source.SourceAnalyze, sb *strings.Builder) {
Expand Down Expand Up @@ -150,7 +151,7 @@ func DescribeDeployment(ctx context.Context, kubeClient kubernetes.Interface, od
return nil, err
}
workloadObj := &source.K8sSourceObject{
Kind: "deployment",
Kind: k8sconsts.WorkloadKindDeployment,
ObjectMeta: deployment.ObjectMeta,
PodTemplateSpec: &deployment.Spec.Template,
LabelSelector: deployment.Spec.Selector,
Expand All @@ -165,7 +166,7 @@ func DescribeDaemonSet(ctx context.Context, kubeClient kubernetes.Interface, odi
return nil, err
}
workloadObj := &source.K8sSourceObject{
Kind: "daemonset",
Kind: k8sconsts.WorkloadKindDaemonSet,
ObjectMeta: ds.ObjectMeta,
PodTemplateSpec: &ds.Spec.Template,
LabelSelector: ds.Spec.Selector,
Expand All @@ -180,7 +181,7 @@ func DescribeStatefulSet(ctx context.Context, kubeClient kubernetes.Interface, o
return nil, err
}
workloadObj := &source.K8sSourceObject{
Kind: "statefulset",
Kind: k8sconsts.WorkloadKindStatefulSet,
ObjectMeta: ss.ObjectMeta,
PodTemplateSpec: &ss.Spec.Template,
LabelSelector: ss.Spec.Selector,
Expand Down
67 changes: 31 additions & 36 deletions k8sutils/pkg/describe/source/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/describe/properties"
"github.com/odigos-io/odigos/k8sutils/pkg/envoverwrite"
)

type InstrumentationLabelsAnalyze struct {
type InstrumentationSourcesAnalyze struct {
Instrumented properties.EntityProperty `json:"instrumented"`
Workload *properties.EntityProperty `json:"workload"`
Namespace *properties.EntityProperty `json:"namespace"`
Expand Down Expand Up @@ -73,10 +72,10 @@ type PodAnalyze struct {
}

type SourceAnalyze struct {
Name properties.EntityProperty `json:"name"`
Kind properties.EntityProperty `json:"kind"`
Namespace properties.EntityProperty `json:"namespace"`
Labels InstrumentationLabelsAnalyze `json:"labels"`
Name properties.EntityProperty `json:"name"`
Kind properties.EntityProperty `json:"kind"`
Namespace properties.EntityProperty `json:"namespace"`
SourceObjectsAnalysis InstrumentationSourcesAnalyze `json:"sourceObjects"`

RuntimeInfo *RuntimeInfoAnalyze `json:"runtimeInfo"`
InstrumentationConfig InstrumentationConfigAnalyze `json:"instrumentationConfig"`
Expand All @@ -88,62 +87,58 @@ type SourceAnalyze struct {
}

// Deprecated: Sources are used to mark workloads for instrumentation.
func analyzeInstrumentationLabels(resource *OdigosSourceResources, workloadObj *K8sSourceObject) (InstrumentationLabelsAnalyze, bool) {
workloadLabel, workloadFound := workloadObj.GetLabels()[consts.OdigosInstrumentationLabel]
nsLabel, nsFound := resource.Namespace.GetLabels()[consts.OdigosInstrumentationLabel]
func analyzeInstrumentationBySources(sources *odigosv1.WorkloadSources) (InstrumentationSourcesAnalyze, bool) {
workloadSource := sources.Workload
nsSource := sources.Namespace

workload := &properties.EntityProperty{Name: "Workload", Value: "unset",
Explain: "the value of the odigos-instrumentation label on the workload object in k8s"}
if workloadFound {
workload.Value = fmt.Sprintf("%s=%s", consts.OdigosInstrumentationLabel, workloadLabel)
Explain: "existence of workload specific Source object in k8s"}
if sources.Workload != nil && !sources.Workload.Spec.DisableInstrumentation {
workload.Value = "instrumented"
}

ns := &properties.EntityProperty{Name: "Namespace", Value: "unset",
Explain: "the value of the odigos-instrumentation label on the namespace object in k8s"}
if nsFound {
ns.Value = fmt.Sprintf("%s=%s", consts.OdigosInstrumentationLabel, nsLabel)
Explain: "existence of namespace Source for this workload in k8s"}
if sources.Namespace != nil && !sources.Namespace.Spec.DisableInstrumentation {
ns.Value = "instrumented"
}

var instrumented bool
var decisionText string

if workloadFound {
instrumented = workloadLabel == consts.InstrumentationEnabled
if workloadSource != nil {
instrumented = !workloadSource.Spec.DisableInstrumentation
if instrumented {
decisionText = "Workload is instrumented because the " + workloadObj.Kind + " contains the label '" +
consts.OdigosInstrumentationLabel + "=" + workloadLabel + "'"
decisionText = "Workload is instrumented because the workload source is present and enabled"
} else {
decisionText = "Workload is NOT instrumented because the " + workloadObj.Kind + " contains the label '" +
consts.OdigosInstrumentationLabel + "=" + workloadLabel + "'"
decisionText = "Workload is NOT instrumented because the workload source is present and disabled"
}
} else {
instrumented = nsLabel == consts.InstrumentationEnabled
if instrumented {
decisionText = "Workload is instrumented because the " + workloadObj.Kind +
" is not labeled, and the namespace is labeled with '" + consts.OdigosInstrumentationLabel + "=" + nsLabel + "'"
} else {
if nsFound {
decisionText = "Workload is NOT instrumented because the " + workloadObj.Kind +
" is not labeled, and the namespace is labeled with '" + consts.OdigosInstrumentationLabel + "=" + nsLabel + "'"
if nsSource != nil {
instrumented = !nsSource.Spec.DisableInstrumentation
if instrumented {
decisionText = "Workload is instrumented because the workload source is not present, but the namespace source is present and enabled"
} else {
decisionText = "Workload is NOT instrumented because neither the workload nor the namespace has the '" +
consts.OdigosInstrumentationLabel + "' label set"
decisionText = "Workload is NOT instrumented because the workload source is not present, but the namespace source is present and disabled"
}
} else {
instrumented = false
decisionText = "Workload is NOT instrumented because neither the workload source nor the namespace source are present"
}
}

instrumentedProperty := properties.EntityProperty{
Name: "Instrumented",
Value: instrumented,
Explain: "whether this workload is considered for instrumentation based on the presence of the odigos-instrumentation label",
Explain: "whether this workload is considered for instrumentation based on the presence of the Source objects",
}
decisionTextProperty := properties.EntityProperty{
Name: "DecisionText",
Value: decisionText,
Explain: "a human readable explanation of the decision to instrument or not instrument this workload",
}

return InstrumentationLabelsAnalyze{
return InstrumentationSourcesAnalyze{
Instrumented: instrumentedProperty,
Workload: workload,
Namespace: ns,
Expand All @@ -158,7 +153,7 @@ func analyzeInstrumentationConfig(resources *OdigosSourceResources, instrumented
Name: "Created",
Value: properties.GetTextCreated(instrumentationConfigCreated),
Status: properties.GetSuccessOrTransitioning(instrumentationConfigCreated == instrumented),
Explain: "whether the instrumentation config object exists in the cluster. When a workload is labeled for instrumentation," +
Explain: "whether the instrumentation config object exists in the cluster. When a Source object is created," +
" an instrumentation config object is created",
}

Expand Down Expand Up @@ -519,7 +514,7 @@ func analyzePods(resources *OdigosSourceResources, expectedDevices Instrumentati
}

func AnalyzeSource(resources *OdigosSourceResources, workloadObj *K8sSourceObject) *SourceAnalyze {
labelsAnalysis, instrumented := analyzeInstrumentationLabels(resources, workloadObj)
sourcesAnalysis, instrumented := analyzeInstrumentationBySources(resources.Sources)
runtimeAnalysis := analyzeRuntimeInfo(resources)
icAnalysis := analyzeInstrumentationConfig(resources, instrumented)
device := analyzeInstrumentationDevice(resources, workloadObj, instrumented)
Expand All @@ -532,7 +527,7 @@ func AnalyzeSource(resources *OdigosSourceResources, workloadObj *K8sSourceObjec
Explain: "the kind of the k8s workload object that this source describes (deployment/daemonset/statefulset)"},
Namespace: properties.EntityProperty{Name: "Namespace", Value: workloadObj.GetNamespace(),
Explain: "the namespace of the k8s workload object that this source describes"},
Labels: labelsAnalysis,
SourceObjectsAnalysis: sourcesAnalysis,

RuntimeInfo: runtimeAnalysis,
InstrumentationConfig: icAnalysis,
Expand Down
Loading
Loading