Skip to content

Commit

Permalink
Merge branch 'main' into head-sampling-crd
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirdavid1 authored Aug 18, 2024
2 parents afbb307 + bb6bcf4 commit 8061ae4
Show file tree
Hide file tree
Showing 75 changed files with 1,906 additions and 611 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check links

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
check-links:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: lycheeverse/[email protected]
with:
args: >-
-v -n "*.md" "**/*.md"
--exclude "http://localhost*"
fail: true
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- "multi-apps"
- "helm-chart"
- "fe-synthetic"
- "cli-upgrade"
include:
- kube-version: "1.23"
kind-image: "kindest/node:v1.23.17@sha256:14d0a9a892b943866d7e6be119a06871291c517d279aedb816a4b4bc0ec0a5b3"
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ changelog:
- "^docs:"
- "^test:"
brews:
- tap:
- repository:
owner: keyval-dev
name: homebrew-odigos-cli
token: "{{ .Env.HOMEBREW_GITHUB_API_TOKEN }}"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<a href="https://github.com/odigos-io/odigos/actions/workflows/publish-cli.yml" target="_blank">
<img src="https://github.com/odigos-io/odigos/actions/workflows/publish-cli.yml/badge.svg" alt="Release Odigos CLI" style="margin-right: 10px; border: 1px solid #007acc; border-radius: 4px; padding: 5px;">
<a href="https://github.com/odigos-io/odigos/actions/workflows/release.yml" target="_blank">
<img src="https://github.com/odigos-io/odigos/actions/workflows/release.yml/badge.svg" alt="Release Odigos CLI" style="margin-right: 10px; border: 1px solid #007acc; border-radius: 4px; padding: 5px;">
</a>
<a href="https://goreportcard.com/report/github.com/odigos-io/odigos/cli" target="_blank">
<img src="https://goreportcard.com/badge/github.com/odigos-io/odigos/cli" alt="Go Report Card" style="margin-right: 10px; border: 1px solid #4CAF50; border-radius: 4px; padding: 5px;">
Expand Down
13 changes: 11 additions & 2 deletions api/config/crd/bases/odigos.io_odigosconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ spec:
- name: v1alpha1
schema:
openAPIV3Schema:
description: OdigosConfiguration is the Schema for the odigos configuration
description: |-
OdigosConfiguration is the Schema for the odigos configuration
Deprecated: Use common.OdigosConfiguration instead
properties:
apiVersion:
description: |-
Expand All @@ -37,11 +41,16 @@ spec:
metadata:
type: object
spec:
description: OdigosConfigurationSpec defines the desired state of OdigosConfiguration
description: |-
OdigosConfigurationSpec defines the desired state of OdigosConfiguration
Deprecated: Use common.OdigosConfiguration instead
properties:
autoscalerImage:
type: string
collectorGateway:
description: 'Deprecated: Use common.OdigosConfiguration instead'
properties:
goMemLimitMiB:
description: |-
Expand Down
33 changes: 33 additions & 0 deletions api/odigos/v1alpha1/odigosconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Deprecated: Use common.OdigosConfiguration instead
type CollectorGatewayConfiguration struct {
// RequestMemoryMiB is the memory request for the cluster gateway collector deployment.
// it will be embedded in the deployment as a resource request of the form "memory: <value>Mi"
Expand All @@ -30,6 +31,8 @@ type CollectorGatewayConfiguration struct {
}

// OdigosConfigurationSpec defines the desired state of OdigosConfiguration
//
// Deprecated: Use common.OdigosConfiguration instead
type OdigosConfigurationSpec struct {
OdigosVersion string `json:"odigosVersion"`
ConfigVersion int `json:"configVersion"`
Expand All @@ -55,6 +58,8 @@ type OdigosConfigurationSpec struct {
//+kubebuilder:object:root=true

// OdigosConfiguration is the Schema for the odigos configuration
//
// Deprecated: Use common.OdigosConfiguration instead
type OdigosConfiguration struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -74,3 +79,31 @@ type OdigosConfigurationList struct {
func init() {
SchemeBuilder.Register(&OdigosConfiguration{}, &OdigosConfigurationList{})
}

func (odigosConfig *OdigosConfiguration) ToCommonConfig() *common.OdigosConfiguration {
var collectorGateway common.CollectorGatewayConfiguration
if odigosConfig.Spec.CollectorGateway != nil {
collectorGateway = common.CollectorGatewayConfiguration{
RequestMemoryMiB: odigosConfig.Spec.CollectorGateway.RequestMemoryMiB,
MemoryLimiterLimitMiB: odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB,
MemoryLimiterSpikeLimitMiB: odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB,
GoMemLimitMib: odigosConfig.Spec.CollectorGateway.GoMemLimitMib,
}
}
return &common.OdigosConfiguration{
OdigosVersion: odigosConfig.Spec.OdigosVersion,
ConfigVersion: odigosConfig.Spec.ConfigVersion,
TelemetryEnabled: odigosConfig.Spec.TelemetryEnabled,
OpenshiftEnabled: odigosConfig.Spec.OpenshiftEnabled,
IgnoredNamespaces: odigosConfig.Spec.IgnoredNamespaces,
IgnoredContainers: odigosConfig.Spec.IgnoredContainers,
Psp: odigosConfig.Spec.Psp,
ImagePrefix: odigosConfig.Spec.ImagePrefix,
OdigletImage: odigosConfig.Spec.OdigletImage,
InstrumentorImage: odigosConfig.Spec.InstrumentorImage,
AutoscalerImage: odigosConfig.Spec.AutoscalerImage,
DefaultSDKs: odigosConfig.Spec.DefaultSDKs,
CollectorGateway: &collectorGateway,
GoAutoIncludeCodeAttributes: odigosConfig.Spec.GoAutoIncludeCodeAttributes,
}
}
23 changes: 12 additions & 11 deletions autoscaler/controllers/gateway/memory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gateway

import odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
import (
"github.com/odigos-io/odigos/common"
)

const (
defaultRequestMemoryMiB = 500
Expand All @@ -25,27 +27,26 @@ type memoryConfigurations struct {
gomemlimitMiB int
}

func getMemoryConfigurations(odigosConfig *odigosv1.OdigosConfiguration) *memoryConfigurations {

func getMemoryConfigurations(odigosConfig *common.OdigosConfiguration) *memoryConfigurations {
memoryRequestMiB := defaultRequestMemoryMiB
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.RequestMemoryMiB > 0 {
memoryRequestMiB = odigosConfig.Spec.CollectorGateway.RequestMemoryMiB
if odigosConfig.CollectorGateway != nil && odigosConfig.CollectorGateway.RequestMemoryMiB > 0 {
memoryRequestMiB = odigosConfig.CollectorGateway.RequestMemoryMiB
}

// the memory limiter hard limit is set as 50 MiB less than the memory request
memoryLimiterLimitMiB := memoryRequestMiB - defaultMemoryLimiterLimitDiffMib
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB > 0 {
memoryLimiterLimitMiB = odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB
if odigosConfig.CollectorGateway != nil && odigosConfig.CollectorGateway.MemoryLimiterLimitMiB > 0 {
memoryLimiterLimitMiB = odigosConfig.CollectorGateway.MemoryLimiterLimitMiB
}

memoryLimiterSpikeLimitMiB := memoryLimiterLimitMiB * defaultMemoryLimiterSpikePercentage / 100.0
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB > 0 {
memoryLimiterSpikeLimitMiB = odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB
if odigosConfig.CollectorGateway != nil && odigosConfig.CollectorGateway.MemoryLimiterSpikeLimitMiB > 0 {
memoryLimiterSpikeLimitMiB = odigosConfig.CollectorGateway.MemoryLimiterSpikeLimitMiB
}

gomemlimitMiB := int(memoryLimiterLimitMiB * defaultGoMemLimitPercentage / 100.0)
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.GoMemLimitMib != 0 {
gomemlimitMiB = odigosConfig.Spec.CollectorGateway.GoMemLimitMib
if odigosConfig.CollectorGateway != nil && odigosConfig.CollectorGateway.GoMemLimitMib != 0 {
gomemlimitMiB = odigosConfig.CollectorGateway.GoMemLimitMib
}

return &memoryConfigurations{
Expand Down
16 changes: 8 additions & 8 deletions autoscaler/controllers/gateway/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
appsv1 "k8s.io/api/apps/v1"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/common"
"github.com/odigos-io/odigos/common/consts"
commonconf "github.com/odigos-io/odigos/autoscaler/controllers/common"
"github.com/odigos-io/odigos/common"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"github.com/odigos-io/odigos/k8sutils/pkg/utils"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -44,11 +45,10 @@ func Sync(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme,
return err
}
// Add the generic batch processor to the list of processors
processors.Items = append(processors.Items, common.GetGenericBatchProcessor())
processors.Items = append(processors.Items, commonconf.GetGenericBatchProcessor())

odigosSystemNamespaceName := env.GetCurrentNamespace()
var odigosConfig odigosv1.OdigosConfiguration
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: odigosSystemNamespaceName, Name: consts.OdigosConfigurationName}, &odigosConfig); err != nil {
odigosConfig, err := utils.GetCurrentConfig(ctx, k8sClient)
if err != nil {
logger.Error(err, "failed to get odigos config")
return err
}
Expand All @@ -58,7 +58,7 @@ func Sync(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme,

func syncGateway(dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList,
gateway *odigosv1.CollectorsGroup, ctx context.Context,
c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, odigosConfig *odigosv1.OdigosConfiguration) error {
c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, odigosConfig *common.OdigosConfiguration) error {
logger := log.FromContext(ctx)
logger.V(0).Info("Syncing gateway")

Expand Down Expand Up @@ -88,7 +88,7 @@ func syncGateway(dests *odigosv1.DestinationList, processors *odigosv1.Processor
return err
}

err = common.UpdateCollectorGroupReceiverSignals(ctx, c, gateway, signals)
err = commonconf.UpdateCollectorGroupReceiverSignals(ctx, c, gateway, signals)
if err != nil {
logger.Error(err, "Failed to update cluster collectors group received signals")
return err
Expand Down
6 changes: 3 additions & 3 deletions autoscaler/controllers/odigosconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package controllers
import (
"context"

v1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/gateway"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -19,7 +19,6 @@ type OdigosConfigReconciler struct {
}

func (r *OdigosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling Odigos Configuration")

Expand All @@ -33,7 +32,8 @@ func (r *OdigosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request

// SetupWithManager sets up the controller with the Manager.
func (r *OdigosConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
// TODO: Clean up noise from too broad of a definition here
return ctrl.NewControllerManagedBy(mgr).
For(&v1.OdigosConfiguration{}).
For(&v1.ConfigMap{}).
Complete(r)
}
8 changes: 3 additions & 5 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

apierrors "k8s.io/apimachinery/pkg/api/errors"

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/common/utils"
Expand Down Expand Up @@ -83,7 +82,7 @@ This command will install k8s components that will auto-instrument your applicat
odigosProToken = odigosOnPremToken
}

config := createOdigosConfigSpec()
config := createOdigosConfig()

fmt.Printf("Installing Odigos version %s in namespace %s ...\n", versionFlag, ns)

Expand Down Expand Up @@ -178,12 +177,11 @@ func createNamespace(ctx context.Context, cmd *cobra.Command, client *kube.Clien
return nil
}

func createOdigosConfigSpec() odigosv1.OdigosConfigurationSpec {

func createOdigosConfig() common.OdigosConfiguration {
fullIgnoredNamespaces := utils.MergeDefaultIgnoreWithUserInput(userInputIgnoredNamespaces, consts.SystemNamespaces)
fullIgnoredContainers := utils.MergeDefaultIgnoreWithUserInput(userInputIgnoredContainers, consts.IgnoredContainers)

return odigosv1.OdigosConfigurationSpec{
return common.OdigosConfiguration{
OdigosVersion: versionFlag,
ConfigVersion: 1, // config version starts at 1 and incremented on every config change
TelemetryEnabled: telemetryEnabled,
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func updateApiKey(cmd *cobra.Command, args []string) {
fmt.Println("Odigos cloud login failed - unable to read the current Odigos configuration.")
os.Exit(1)
}
config.Spec.ConfigVersion += 1
config.ConfigVersion += 1

if odigosCloudApiKeyFlag == "" {
fmt.Println("Enter your odigos cloud api-key. You can find it here: https://app.odigos.io/settings")
Expand All @@ -92,7 +92,7 @@ func updateApiKey(cmd *cobra.Command, args []string) {
}
isPrevOdigosCloud := currentTier == common.CloudOdigosTier

resourceManagers := resources.CreateResourceManagers(client, ns, common.CloudOdigosTier, &odigosCloudApiKeyFlag, &config.Spec)
resourceManagers := resources.CreateResourceManagers(client, ns, common.CloudOdigosTier, &odigosCloudApiKeyFlag, config)
err = resources.ApplyResourceManagers(ctx, client, resourceManagers, "Updating")
if err != nil {
fmt.Println("Odigos cloud login failed - unable to apply Odigos resources.")
Expand All @@ -106,7 +106,7 @@ func updateApiKey(cmd *cobra.Command, args []string) {

if isPrevOdigosCloud {
l := log.Print("Restarting relevant pods ...")
err := restartPodsAfterCloudLogin(ctx, client, ns, config.Spec.ConfigVersion)
err := restartPodsAfterCloudLogin(ctx, client, ns, config.ConfigVersion)
if err != nil {
l.Error(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var logoutCmd = &cobra.Command{
Use: "logout",
Short: "Logout from Odigos cloud",
Long: `Disconnect this Odigos installation from your odigos cloud account.
After running this command, you will no longer be able to control and monitor this Odigos installation from Odigos cloud.
You can run 'odigos ui' to manage your Odigos installation locally.
`,
Expand Down Expand Up @@ -65,10 +65,10 @@ var logoutCmd = &cobra.Command{
fmt.Println("Odigos cloud logout failed - unable to read the current Odigos configuration.")
os.Exit(1)
}
config.Spec.ConfigVersion += 1
config.ConfigVersion += 1

emptyApiKey := ""
resourceManagers := resources.CreateResourceManagers(client, ns, common.CommunityOdigosTier, &emptyApiKey, &config.Spec)
resourceManagers := resources.CreateResourceManagers(client, ns, common.CommunityOdigosTier, &emptyApiKey, config)
err = resources.ApplyResourceManagers(ctx, client, resourceManagers, "Updating")
if err != nil {
fmt.Println("Odigos cloud logout failed - unable to apply Odigos resources.")
Expand Down
23 changes: 19 additions & 4 deletions cli/cmd/resources/applyresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/odigos-io/odigos/cli/cmd/resources/resourcemanager"
"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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)

func ApplyResourceManagers(ctx context.Context, client *kube.Client, resourceManagers []resourcemanager.ResourceManager, prefixForLogging string) error {
Expand All @@ -26,11 +28,11 @@ func ApplyResourceManagers(ctx context.Context, client *kube.Client, resourceMan
return nil
}

func DeleteOldOdigosSystemObjects(ctx context.Context, client *kube.Client, ns string, config *v1alpha1.OdigosConfiguration) error {
func DeleteOldOdigosSystemObjects(ctx context.Context, client *kube.Client, ns string, config *common.OdigosConfiguration) error {
resources := kube.GetManagedResources(ns)
for _, resource := range resources {
l := log.Print(fmt.Sprintf("Syncing %s", resource.Resource.Resource))
err := client.DeleteOldOdigosSystemObjects(ctx, resource, config.Spec.ConfigVersion)
err := client.DeleteOldOdigosSystemObjects(ctx, resource, config.ConfigVersion)
if err != nil {
l.Error(err)
os.Exit(1)
Expand All @@ -41,6 +43,19 @@ func DeleteOldOdigosSystemObjects(ctx context.Context, client *kube.Client, ns s
return nil
}

func GetCurrentConfig(ctx context.Context, client *kube.Client, ns string) (*v1alpha1.OdigosConfiguration, error) {
return client.OdigosClient.OdigosConfigurations(ns).Get(ctx, consts.OdigosConfigurationName, metav1.GetOptions{})
func GetCurrentConfig(ctx context.Context, client *kube.Client, ns string) (*common.OdigosConfiguration, error) {
configMap, err := client.CoreV1().ConfigMaps(ns).Get(ctx, consts.OdigosConfigurationName, metav1.GetOptions{})
if err != nil {
return nil, err
}
var odigosConfig common.OdigosConfiguration
if err := yaml.Unmarshal([]byte(configMap.Data[consts.OdigosConfigurationFileName]), &odigosConfig); err != nil {
return nil, err
}
return &odigosConfig, nil
}

func GetDeprecatedConfig(ctx context.Context, client *kube.Client, ns string) (*v1alpha1.OdigosConfiguration, error) {
return client.OdigosClient.OdigosConfigurations(ns).Get(ctx, consts.OdigosConfigurationName, metav1.GetOptions{})
}

Loading

0 comments on commit 8061ae4

Please sign in to comment.