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

refactor(instrumentor): generic instrumentation device handling #765

Merged
merged 3 commits into from
Nov 15, 2023
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
2 changes: 0 additions & 2 deletions api/config/crd/bases/odigos.io_odigosconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ spec:
type: string
psp:
type: boolean
sidecarInstrumentation:
type: boolean
telemetryEnabled:
type: boolean
required:
Expand Down
19 changes: 9 additions & 10 deletions api/odigos/v1alpha1/odigosconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// OdigosConfigurationSpec defines the desired state of OdigosConfiguration
type OdigosConfigurationSpec struct {
OdigosVersion string `json:"odigosVersion"`
ConfigVersion int `json:"configVersion"`
TelemetryEnabled bool `json:"telemetryEnabled,omitempty"`
SidecarInstrumentation bool `json:"sidecarInstrumentation,omitempty"`
IgnoredNamespaces []string `json:"ignoredNamespaces,omitempty"`
Psp bool `json:"psp,omitempty"`
ImagePrefix string `json:"imagePrefix,omitempty"`
OdigletImage string `json:"odigletImage,omitempty"`
InstrumentorImage string `json:"instrumentorImage,omitempty"`
AutoscalerImage string `json:"autoscalerImage,omitempty"`
OdigosVersion string `json:"odigosVersion"`
ConfigVersion int `json:"configVersion"`
TelemetryEnabled bool `json:"telemetryEnabled,omitempty"`
IgnoredNamespaces []string `json:"ignoredNamespaces,omitempty"`
Psp bool `json:"psp,omitempty"`
ImagePrefix string `json:"imagePrefix,omitempty"`
OdigletImage string `json:"odigletImage,omitempty"`
InstrumentorImage string `json:"instrumentorImage,omitempty"`
AutoscalerImage string `json:"autoscalerImage,omitempty"`
}

//+genclient
Expand Down
21 changes: 9 additions & 12 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var (
versionFlag string
skipWait bool
telemetryEnabled bool
sidecarInstrumentation bool
psp bool
ignoredNamespaces []string
DefaultIgnoredNamespaces = []string{"odigos-system", "kube-system", "local-path-storage", "istio-system", "linkerd"}
Expand Down Expand Up @@ -129,16 +128,15 @@ func createNamespace(ctx context.Context, cmd *cobra.Command, client *kube.Clien

func createOdigosConfigSpec() odigosv1.OdigosConfigurationSpec {
return odigosv1.OdigosConfigurationSpec{
OdigosVersion: versionFlag,
ConfigVersion: 1, // config version starts at 1 and incremented on every config change
TelemetryEnabled: telemetryEnabled,
SidecarInstrumentation: sidecarInstrumentation,
IgnoredNamespaces: ignoredNamespaces,
Psp: psp,
ImagePrefix: imagePrefix,
OdigletImage: odigletImage,
InstrumentorImage: instrumentorImage,
AutoscalerImage: autoScalerImage,
OdigosVersion: versionFlag,
ConfigVersion: 1, // config version starts at 1 and incremented on every config change
TelemetryEnabled: telemetryEnabled,
IgnoredNamespaces: ignoredNamespaces,
Psp: psp,
ImagePrefix: imagePrefix,
OdigletImage: odigletImage,
InstrumentorImage: instrumentorImage,
AutoscalerImage: autoScalerImage,
}
}

Expand All @@ -158,7 +156,6 @@ func init() {
installCmd.Flags().StringVarP(&odigosCloudApiKeyFlag, "api-key", "k", "", "api key for odigos cloud")
installCmd.Flags().BoolVar(&skipWait, "nowait", false, "skip waiting for odigos pods to be ready")
installCmd.Flags().BoolVar(&telemetryEnabled, "telemetry", true, "send general telemetry regarding Odigos usage")
installCmd.Flags().BoolVar(&sidecarInstrumentation, "sidecar-instrumentation", false, "use sidecars for eBPF instrumentations")
installCmd.Flags().StringVar(&odigletImage, "odiglet-image", "keyval/odigos-odiglet", "odiglet container image name")
installCmd.Flags().StringVar(&instrumentorImage, "instrumentor-image", "keyval/odigos-instrumentor", "instrumentor container image name")
installCmd.Flags().StringVar(&autoScalerImage, "autoscaler-image", "keyval/odigos-autoscaler", "autoscaler container image name")
Expand Down
3 changes: 0 additions & 3 deletions cli/cmd/resources/crds/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ func NewConfiguration() *apiextensionsv1.CustomResourceDefinition {
"psp": {
Type: "boolean",
},
"sidecarInstrumentation": {
Type: "boolean",
},
"telemetryEnabled": {
Type: "boolean",
},
Expand Down
8 changes: 2 additions & 6 deletions cli/cmd/resources/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func NewInstrumentorClusterRoleBinding(ns string) *rbacv1.ClusterRoleBinding {
}
}

func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool, sidecarInstrumentation bool, ignoredNamespaces []string, imagePrefix string, imageName string) *appsv1.Deployment {
func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool, ignoredNamespaces []string, imagePrefix string, imageName string) *appsv1.Deployment {
args := []string{
"--health-probe-bind-address=:8081",
"--metrics-bind-address=127.0.0.1:8080",
Expand All @@ -389,10 +389,6 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool,
args = append(args, "--telemetry-disabled")
}

if sidecarInstrumentation {
args = append(args, "--golang-sidecar-instrumentation")
}

return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
Expand Down Expand Up @@ -529,7 +525,7 @@ func (a *instrumentorResourceManager) InstallFromScratch(ctx context.Context) er
NewInstrumentorRoleBinding(a.ns),
NewInstrumentorClusterRole(),
NewInstrumentorClusterRoleBinding(a.ns),
NewInstrumentorDeployment(a.ns, a.config.OdigosVersion, a.config.TelemetryEnabled, a.config.SidecarInstrumentation, a.config.IgnoredNamespaces, a.config.ImagePrefix, a.config.InstrumentorImage),
NewInstrumentorDeployment(a.ns, a.config.OdigosVersion, a.config.TelemetryEnabled, a.config.IgnoredNamespaces, a.config.ImagePrefix, a.config.InstrumentorImage),
}
return a.client.ApplyResources(ctx, a.config.ConfigVersion, resources)
}
36 changes: 36 additions & 0 deletions common/device_names.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package common

type OdigosInstrumentationDevice string

const (
JavaDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/java"
PythonDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/python"
GoDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/go"
DotNetDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/dotnet"
JavascriptDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/javascript"
)

var InstrumentationDevices = []OdigosInstrumentationDevice{
JavaDeviceName,
PythonDeviceName,
GoDeviceName,
DotNetDeviceName,
JavascriptDeviceName,
}

func ProgrammingLanguageToInstrumentationDevice(language ProgrammingLanguage) OdigosInstrumentationDevice {
switch language {
case JavaProgrammingLanguage:
return JavaDeviceName
case PythonProgrammingLanguage:
return PythonDeviceName
case GoProgrammingLanguage:
return GoDeviceName
case DotNetProgrammingLanguage:
return DotNetDeviceName
case JavascriptProgrammingLanguage:
return JavascriptDeviceName
default:
return ""
}
}
6 changes: 3 additions & 3 deletions instrumentor/controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1"
"github.com/keyval-dev/odigos/common/consts"
"github.com/keyval-dev/odigos/common/utils"
"github.com/keyval-dev/odigos/instrumentor/patch"
"github.com/keyval-dev/odigos/instrumentor/instrumentation"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -55,7 +55,7 @@ func instrument(logger logr.Logger, ctx context.Context, kubeClient client.Clien
return err
}

return patch.ModifyObject(podSpec, runtimeDetails)
return instrumentation.ModifyObject(podSpec, runtimeDetails)
})

if err != nil {
Expand Down Expand Up @@ -95,7 +95,7 @@ func uninstrument(logger logr.Logger, ctx context.Context, kubeClient client.Cli
return err
}

patch.Revert(podSpec)
instrumentation.Revert(podSpec)
return nil
})

Expand Down
62 changes: 62 additions & 0 deletions instrumentor/instrumentation/instrumentation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package instrumentation

import (
odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1"
"github.com/keyval-dev/odigos/common"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

type CollectorInfo struct {
Hostname string
Port int
}

func ModifyObject(original *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) error {
var modifiedContainers []v1.Container
for _, container := range original.Spec.Containers {
containerLanguage := getLanguageOfContainer(instrumentation, container.Name)
if containerLanguage == nil {
continue
}

instrumentationDeviceName := common.ProgrammingLanguageToInstrumentationDevice(*containerLanguage)
if instrumentationDeviceName == "" {
// should not happen, only for safety
continue
}

if container.Resources.Limits == nil {
container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity)
}
container.Resources.Limits[v1.ResourceName(instrumentationDeviceName)] = resource.MustParse("1")

modifiedContainers = append(modifiedContainers, container)
}

original.Spec.Containers = modifiedContainers
return nil
}

func Revert(original *v1.PodTemplateSpec) {
for _, instrumentationDevice := range common.InstrumentationDevices {
removeDeviceFromPodSpec(instrumentationDevice, original)
}
}

func removeDeviceFromPodSpec(deviceName common.OdigosInstrumentationDevice, podSpec *v1.PodTemplateSpec) {
for _, container := range podSpec.Spec.Containers {
delete(container.Resources.Limits, v1.ResourceName(deviceName))
delete(container.Resources.Requests, v1.ResourceName(deviceName))
}
}

func getLanguageOfContainer(instrumentation *odigosv1.InstrumentedApplication, containerName string) *common.ProgrammingLanguage {
for _, l := range instrumentation.Spec.Languages {
if l.ContainerName == containerName {
return &l.Language
}
}

return nil
}
2 changes: 0 additions & 2 deletions instrumentor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/go-logr/zapr"
"github.com/keyval-dev/odigos/instrumentor/patch"
bridge "github.com/keyval-dev/opentelemetry-zap-bridge"

v1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1"
Expand Down Expand Up @@ -72,7 +71,6 @@ func main() {
"Enabling this will ensure there is only one active controller manager.")
flag.Var(&ignoredNameSpaces, "ignore-namespace", "The ignored namespaces")
flag.BoolVar(&telemetryDisabled, "telemetry-disabled", false, "Disable telemetry")
flag.BoolVar(&patch.GolangSidecarInstrumentation, "golang-sidecar-instrumentation", false, "Instrument Go applications with sidecar")

opts := ctrlzap.Options{
Development: true,
Expand Down
37 changes: 0 additions & 37 deletions instrumentor/patch/dotnet.go

This file was deleted.

Loading