Skip to content

Commit

Permalink
Merge branch 'main' into reduce-fp-java-inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
AvihuHenya authored Feb 4, 2025
2 parents 1e240fd + de210c0 commit 33dcc5a
Show file tree
Hide file tree
Showing 245 changed files with 1,571 additions and 6,870 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/trigger-odigos-enterprise.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/commits/$COMMIT_SHA/pulls")
# Extract PR URL
PR_URL=$(echo "$RESPONSE" | jq -r '.[0].html_url')
echo "PR_URL=$(echo "$RESPONSE" | jq -r '.[0].html_url')" >> "$GITHUB_ENV"
- name: Trigger process PR in Odigos Enterprise
run: |
Expand Down
141 changes: 98 additions & 43 deletions cli/cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,87 +1,142 @@
package cmd

import (
"context"
"fmt"
"os"
"strconv"

"github.com/odigos-io/odigos/cli/cmd/resources"
"github.com/odigos-io/odigos/cli/cmd/resources/odigospro"
cmdcontext "github.com/odigos-io/odigos/cli/pkg/cmd_context"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/cli/pkg/log"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var configCmd = &cobra.Command{
Use: "config",
Short: "Manage Odigos configuration",
Long: "Manage Odigos configuration settings, including central backend URL and other properties",
Long: "Manage Odigos configuration settings to customize system behavior.",
}

// `odigos config set <property> <value>`
var setConfigCmd = &cobra.Command{
Use: "set <property> <value>",
Short: "Set a configuration property in Odigos",
Args: cobra.ExactArgs(2),
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
property := args[0]
value := args[1]
value := args[1:]

ctx := cmd.Context()
client := cmdcontext.KubeClientFromContextOrExit(ctx)
ns, _ := cmd.Flags().GetString("namespace")
if ns == "" {
ns = "odigos-system"
}
ns, err := resources.GetOdigosNamespace(client, ctx)

l := log.Print(fmt.Sprintf("Updating %s to %s...", property, value))
err := updateConfigProperty(ctx, client, ns, property, value)

config, err := resources.GetCurrentConfig(ctx, client, ns)
if err != nil {
odigosConfig, err := resources.GetDeprecatedConfig(ctx, client, ns)
if err != nil {
l.Error(fmt.Errorf("unable to read the current Odigos configuration: %w", err))
os.Exit(1)
}
config = odigosConfig.ToCommonConfig()
}

config.ConfigVersion += 1
err = setConfigProperty(config, property, value)
if err != nil {
l.Error(err)
os.Exit(1)
}
l.Success()

if property == "central-backend-url" {
l = log.Print("Restarting UI pod to apply changes...")
err = restartUIPod(ctx, client, ns)
if err != nil {
l.Error(err)
os.Exit(1)
}
l.Success()
currentTier, err := odigospro.GetCurrentOdigosTier(ctx, client, ns)
if err != nil {
l.Error(fmt.Errorf("unable to read the current Odigos tier: %w", err))
os.Exit(1)
}
},
}

func updateConfigProperty(ctx context.Context, client *kube.Client, ns, property, value string) error {
configMapName := "odigos-config"
resourceManagers := resources.CreateResourceManagers(client, ns, currentTier, nil, config, "Updating Config")
err = resources.ApplyResourceManagers(ctx, client, resourceManagers, "Updating Config")
if err != nil {
l.Error(fmt.Errorf("failed to apply updated configuration: %w", err))
os.Exit(1)
}

cm, err := client.CoreV1().ConfigMaps(ns).Get(ctx, configMapName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get ConfigMap: %w", err)
}
err = resources.DeleteOldOdigosSystemObjects(ctx, client, ns, config)
if err != nil {
fmt.Println("Odigos config update failed - unable to cleanup old Odigos resources.")
os.Exit(1)
}

cm.Data[property] = value
_, err = client.CoreV1().ConfigMaps(ns).Update(ctx, cm, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("failed to update ConfigMap: %w", err)
}
l.Success()

return nil
},
}

func restartUIPod(ctx context.Context, client *kube.Client, ns string) error {
pods, err := client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: "app=odigos-ui"})
if err != nil {
return fmt.Errorf("failed to list UI pods: %w", err)
}
func setConfigProperty(config *common.OdigosConfiguration, property string, value []string) error {
switch property {
case "central-backend-url":
if len(value) != 1 {
return fmt.Errorf("%s expects exactly one value", property)
}
config.CentralBackendURL = value[0]

for _, pod := range pods.Items {
err := client.CoreV1().Pods(ns).Delete(ctx, pod.Name, metav1.DeleteOptions{})
case "telemetry-enabled", "openshift-enabled", "psp", "skip-webhook-issuer-creation", "allow-concurrent-agents":
if len(value) != 1 {
return fmt.Errorf("%s expects exactly one value (true/false)", property)
}
boolValue, err := strconv.ParseBool(value[0])
if err != nil {
return fmt.Errorf("failed to delete pod %s: %w", pod.Name, err)
return fmt.Errorf("invalid boolean value for %s: %s", property, value[0])
}

switch property {
case "telemetry-enabled":
config.TelemetryEnabled = boolValue
case "openshift-enabled":
config.OpenshiftEnabled = boolValue
case "psp":
config.Psp = boolValue
case "skip-webhook-issuer-creation":
config.SkipWebhookIssuerCreation = boolValue
case "allow-concurrent-agents":
config.AllowConcurrentAgents = &boolValue
}

case "image-prefix", "odiglet-image", "instrumentor-image", "autoscaler-image", "ui-mode":
if len(value) != 1 {
return fmt.Errorf("%s expects exactly one value", property)
}
switch property {
case "image-prefix":
config.ImagePrefix = value[0]
case "odiglet-image":
config.OdigletImage = value[0]
case "instrumentor-image":
config.InstrumentorImage = value[0]
case "autoscaler-image":
config.AutoscalerImage = value[0]
case "ui-mode":
config.UiMode = common.UiMode(value[0])
}

case "ignored-namespaces":
if len(value) < 1 {
return fmt.Errorf("%s expects at least one value", property)
}
config.IgnoredNamespaces = value

case "ignored-containers":
if len(value) < 1 {
return fmt.Errorf("%s expects at least one value", property)
}
config.IgnoredContainers = value

default:
return fmt.Errorf("invalid property: %s", property)
}

return nil
Expand All @@ -91,5 +146,5 @@ func init() {
rootCmd.AddCommand(configCmd)
configCmd.AddCommand(setConfigCmd)

setConfigCmd.Flags().StringP("namespace", "n", "odigos-system", "Namespace where Odigos is installed")
setConfigCmd.Flags().StringP("namespace", "n", consts.DefaultOdigosNamespace, "Namespace where Odigos is installed")
}
52 changes: 31 additions & 21 deletions cli/pkg/autodetect/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,43 @@ type ClusterDetails struct {
K8SVersion *version.Version
}

func GetK8SClusterDetails(ctx context.Context, kc string, kContext string, client *kube.Client) *ClusterDetails {
clusterDetails := &ClusterDetails{}
details := k8sutils.GetCurrentClusterDetails(kc, kContext)
serverVersion, err := client.Discovery().ServerVersion()
func getKindFromDetectors(ctx context.Context, args DetectionArguments) Kind {
for _, detector := range availableDetectors {
relevant := detector.Detect(ctx, args)
if relevant {
return detector.Kind()
}
}
return KindUnknown
}

func getServerVersion(c *kube.Client) (string, *version.Version) {
resp, err := c.Discovery().ServerVersion()
if err != nil {
clusterDetails.K8SVersion = nil
fmt.Printf("Unknown k8s version, assuming oldest supported version: %s\n", k8sconsts.MinK8SVersionForInstallation)
} else {
ver := version.MustParse(serverVersion.String())
clusterDetails.K8SVersion = ver
return k8sconsts.MinK8SVersionForInstallation.String(), k8sconsts.MinK8SVersionForInstallation
}

args := DetectionArguments{
parsedVer, err := version.Parse(resp.GitVersion)
if err != nil {
fmt.Printf("Unknown k8s version, assuming oldest supported version: %s\n", k8sconsts.MinK8SVersionForInstallation)
return k8sconsts.MinK8SVersionForInstallation.String(), k8sconsts.MinK8SVersionForInstallation
}
return resp.GitVersion, parsedVer
}

func GetK8SClusterDetails(ctx context.Context, kc string, kContext string, client *kube.Client) *ClusterDetails {
details := k8sutils.GetCurrentClusterDetails(kc, kContext)
serverVersionStr, serverVersion := getServerVersion(client)

kind := getKindFromDetectors(ctx, DetectionArguments{
ClusterDetails: details,
ServerVersion: serverVersion.GitVersion,
ServerVersion: serverVersionStr,
KubeClient: client,
}
})

for _, detector := range availableDetectors {
relevant := detector.Detect(ctx, args)
if !relevant {
continue
}
clusterDetails.Kind = detector.Kind()
return clusterDetails
return &ClusterDetails{
Kind: kind,
K8SVersion: serverVersion,
}

clusterDetails.Kind = KindUnknown
return clusterDetails
}
2 changes: 1 addition & 1 deletion docs/cli/odigos_config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Manage Odigos configuration

### Synopsis

Manage Odigos configuration settings, including central backend URL and other properties
Manage Odigos configuration settings to customize system behavior.

### Options

Expand Down
2 changes: 1 addition & 1 deletion docs/instrumentations/golang/ebpf.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The following go modules will be auto instrumented by Odigos:
- [`github.com/rabbitmq/amqp091-go`](https://pkg.go.dev/github.com/rabbitmq/amqp091-go) ⭐️ versions `>= v1.4.0`. messaging client for RabbitMQ
- [`github.com/segmentio/kafka-go`](https://pkg.go.dev/github.com/segmentio/kafka-go) versions `>= v0.4.1`. messaging client for Apache Kafka
- [`github.com/apache/pulsar-client-go`](https://pkg.go.dev/github.com/apache/pulsar-client-go) ⭐️ versions `>= v0.12.0`. messaging client for Apache Pulsar
- [`github.com/IBM/sarama`](https://pkg.go.dev/github.com/IBM/sarama) ⭐️ versions `>= v1.40.0`. messaging client for Apache Kafka
- [`github.com/IBM/sarama`](https://github.com/IBM/sarama) ⭐️ versions `>= v1.40.0`. messaging client for Apache Kafka

### RPC (Remote Procedure Call)

Expand Down
2 changes: 1 addition & 1 deletion docs/setup/system-requirements.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This allows users to maintain observability on nodes that meet the requirements
- [Kind](https://kind.sigs.k8s.io)
- [Minikube](https://minikube.sigs.k8s.io/docs/start)
- [K3s](https://k3s.io)
- [Red Hat OpenShift](https://www.redhat.com/en/technologies/cloud-computing/openshift) (see [how to install on OpenShift](/setup/installation-options#openshift-installation))
- [Red Hat OpenShift](https://catalog.redhat.com/software/container-stacks/detail/675201b3ade18c062e2efc0b) (see [how to install on OpenShift](/setup/installation-options#openshift-installation))
- [Amazon Elastic Kubernetes Service (EKS)](https://aws.amazon.com/eks/)
- [Google Kubernetes Engine (GKE)](https://cloud.google.com/kubernetes-engine)
- [Azure Kubernetes Service (AKS)](https://azure.microsoft.com/en-us/products/kubernetes-service)
32 changes: 32 additions & 0 deletions frontend/kube/watchers/instrumentation_config_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

var instrumentationConfigAddedEventBatcher *EventBatcher
var instrumentationConfigModifiedEventBatcher *EventBatcher
var instrumentationConfigDeletedEventBatcher *EventBatcher

func StartInstrumentationConfigWatcher(ctx context.Context, namespace string) error {
Expand All @@ -33,6 +34,21 @@ func StartInstrumentationConfigWatcher(ctx context.Context, namespace string) er
},
)

instrumentationConfigModifiedEventBatcher = NewEventBatcher(
EventBatcherConfig{
MinBatchSize: 1,
Duration: 5 * time.Second,
Event: sse.MessageEventModified,
CRDType: consts.InstrumentationConfig,
SuccessBatchMessageFunc: func(count int, crdType string) string {
return fmt.Sprintf("Successfully updated %d sources", count)
},
FailureBatchMessageFunc: func(count int, crdType string) string {
return fmt.Sprintf("Failed to update %d sources", count)
},
},
)

instrumentationConfigDeletedEventBatcher = NewEventBatcher(
EventBatcherConfig{
MinBatchSize: 1,
Expand Down Expand Up @@ -60,6 +76,7 @@ func StartInstrumentationConfigWatcher(ctx context.Context, namespace string) er
func handleInstrumentationConfigWatchEvents(ctx context.Context, watcher watch.Interface) {
ch := watcher.ResultChan()
defer instrumentationConfigAddedEventBatcher.Cancel()
defer instrumentationConfigModifiedEventBatcher.Cancel()
defer instrumentationConfigDeletedEventBatcher.Cancel()
for {
select {
Expand All @@ -73,6 +90,8 @@ func handleInstrumentationConfigWatchEvents(ctx context.Context, watcher watch.I
switch event.Type {
case watch.Added:
handleAddedInstrumentationConfig(event.Object.(*v1alpha1.InstrumentationConfig))
case watch.Modified:
handleModifiedInstrumentationConfig(event.Object.(*v1alpha1.InstrumentationConfig))
case watch.Deleted:
handleDeletedInstrumentationConfig(event.Object.(*v1alpha1.InstrumentationConfig))
}
Expand All @@ -93,6 +112,19 @@ func handleAddedInstrumentationConfig(instruConfig *v1alpha1.InstrumentationConf
instrumentationConfigAddedEventBatcher.AddEvent(sse.MessageTypeSuccess, data, target)
}

func handleModifiedInstrumentationConfig(instruConfig *v1alpha1.InstrumentationConfig) {
namespace := instruConfig.Namespace
name, kind, err := commonutils.ExtractWorkloadInfoFromRuntimeObjectName(instruConfig.Name)
if err != nil {
genericErrorMessage(sse.MessageEventModified, consts.InstrumentationConfig, err.Error())
return
}

target := fmt.Sprintf("namespace=%s&name=%s&kind=%s", namespace, name, kind)
data := fmt.Sprintf(`Source "%s" updated`, name)
instrumentationConfigModifiedEventBatcher.AddEvent(sse.MessageTypeSuccess, data, target)
}

func handleDeletedInstrumentationConfig(instruConfig *v1alpha1.InstrumentationConfig) {
namespace := instruConfig.Namespace
name, kind, err := commonutils.ExtractWorkloadInfoFromRuntimeObjectName(instruConfig.Name)
Expand Down
32 changes: 0 additions & 32 deletions frontend/webapp/app/globals.css

This file was deleted.

Loading

0 comments on commit 33dcc5a

Please sign in to comment.