Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/odiglet/google.golang.…
Browse files Browse the repository at this point in the history
…org/grpc-1.67.0
  • Loading branch information
blumamir authored Oct 13, 2024
2 parents 38244c7 + 1173fef commit fb6b757
Show file tree
Hide file tree
Showing 86 changed files with 2,438 additions and 208 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ node_modules
.DS_Store
go.work.sum
cli/odigos
.venv
.venv
**/__pycache__/
**/*.pyc
serving-certs/
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/instrumentor",
"cwd": "${workspaceFolder}/instrumentor"
"cwd": "${workspaceFolder}/instrumentor",
"env": {
"LOCAL_MUTATING_WEBHOOK_CERT_DIR": "${workspaceFolder}/serving-certs"
}
},
{
"name": "frontend",
Expand Down
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,36 @@ make debug-odiglet

Then, you can attach a debugger to the Odiglet pod. For example, if you are using Goland, you can follow the instructions [here](https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#step-3-create-the-remote-run-debug-configuration-on-the-client-computer) to attach to a remote process.
For Visual Studio Code, you can use the `.vscode/launch.json` file in this repo to attach to the Odiglet pod.



## Instrumentor

### Debugging
If the Mutating Webhook is enabled, follow these steps:

1. Copy the TLS certificate and key:
Create a local directory and extract the certificate and key by running the following command:
```
mkdir -p serving-certs && kubectl get secret instrumentor-webhook-cert -n odigos-system -o jsonpath='{.data.tls\.crt}' | base64 -d > serving-certs/tls.crt && kubectl get secret instrumentor-webhook-cert -n odigos-system -o jsonpath='{.data.tls\.key}' | base64 -d > serving-certs/tls.key
```


2. Apply this service to the cluster, it will replace the existing `odigos-instrumentor` service:

```
apiVersion: v1
kind: Service
metadata:
name: odigos-instrumentor
namespace: odigos-system
spec:
type: ExternalName
externalName: host.docker.internal
ports:
- name: webhook-server
port: 9443
protocol: TCP
```

Once this is done, you can use the .vscode/launch.json configuration and run instrumentor local for debugging.
7 changes: 3 additions & 4 deletions agents/python/configurator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
MINIMUM_PYTHON_SUPPORTED_VERSION = (3, 8)

class OdigosPythonConfigurator(sdk_config._BaseConfigurator):

def _configure(self, **kwargs):
trace_exporters, metric_exporters, log_exporters = sdk_config._import_exporters(
sdk_config._get_exporter_names("traces"),
sdk_config._get_exporter_names("metrics"),
sdk_config._get_exporter_names("logs"),
['otlp_proto_http'] if sdk_config._get_exporter_names("traces") else [],
[],
[],
)
initialize_components(trace_exporters, metric_exporters, log_exporters)
4 changes: 3 additions & 1 deletion autoscaler/controllers/collectorsgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/odigos-io/odigos/autoscaler/controllers/datacollection"
"github.com/odigos-io/odigos/autoscaler/controllers/gateway"

"github.com/odigos-io/odigos/common"
"sigs.k8s.io/controller-runtime/pkg/log"

"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -36,6 +37,7 @@ type CollectorsGroupReconciler struct {
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
OdigosTier common.OdigosTier
}

//+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=collectorsgroups,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -65,7 +67,7 @@ func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion)
err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
54 changes: 34 additions & 20 deletions autoscaler/controllers/datacollection/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"slices"
"strings"

"github.com/odigos-io/odigos/autoscaler/controllers/datacollection/custom"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"

"github.com/ghodss/yaml"
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
commonconf "github.com/odigos-io/odigos/autoscaler/controllers/common"
"github.com/odigos-io/odigos/autoscaler/controllers/datacollection/custom"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/config"
"github.com/odigos-io/odigos/common/consts"
constsK8s "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
v1 "k8s.io/api/core/v1"
Expand All @@ -30,7 +29,7 @@ import (

func SyncConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, allProcessors *odigosv1.ProcessorList,
datacollection *odigosv1.CollectorsGroup, ctx context.Context,
c client.Client, scheme *runtime.Scheme) (string, error) {
c client.Client, scheme *runtime.Scheme, tier common.OdigosTier) (string, error) {
logger := log.FromContext(ctx)

processors := commonconf.FilterAndSortProcessorsByOrderHint(allProcessors, odigosv1.CollectorsGroupRoleNodeCollector)
Expand All @@ -39,7 +38,7 @@ func SyncConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.D
SamplingExists := commonconf.FindFirstProcessorByType(allProcessors, "odigossampling")
setTracesLoadBalancer := SamplingExists != nil

desired, err := getDesiredConfigMap(apps, dests, processors, datacollection, scheme, setTracesLoadBalancer)
desired, err := getDesiredConfigMap(apps, dests, processors, datacollection, scheme, setTracesLoadBalancer, tier)
if err != nil {
logger.Error(err, "failed to get desired config map")
return "", err
Expand Down Expand Up @@ -98,8 +97,8 @@ func createConfigMap(desired *v1.ConfigMap, ctx context.Context, c client.Client
}

func getDesiredConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors []*odigosv1.Processor,
datacollection *odigosv1.CollectorsGroup, scheme *runtime.Scheme, setTracesLoadBalancer bool) (*v1.ConfigMap, error) {
cmData, err := calculateConfigMapData(apps, dests, processors, setTracesLoadBalancer)
datacollection *odigosv1.CollectorsGroup, scheme *runtime.Scheme, setTracesLoadBalancer bool, tier common.OdigosTier) (*v1.ConfigMap, error) {
cmData, err := calculateConfigMapData(apps, dests, processors, setTracesLoadBalancer, tier)
if err != nil {
return nil, err
}
Expand All @@ -126,7 +125,7 @@ func getDesiredConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odig
}

func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors []*odigosv1.Processor,
setTracesLoadBalancer bool) (string, error) {
setTracesLoadBalancer bool, tier common.OdigosTier) (string, error) {

empty := struct{}{}

Expand All @@ -136,8 +135,12 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o
log.Log.V(0).Info(err.Error(), "processor", name)
}
}

if tier != common.OnPremOdigosTier {
processorsCfg["odigosresourcename"] = empty
}

processorsCfg["batch"] = empty
processorsCfg["odigosresourcename"] = empty
processorsCfg["resource"] = config.GenericMap{
"attributes": []config.GenericMap{{
"key": "k8s.node.name",
Expand Down Expand Up @@ -207,7 +210,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o
"config": config.GenericMap{
"scrape_configs": []config.GenericMap{
{
"job_name": "otelcol",
"job_name": "otelcol",
"scrape_interval": "10s",
"static_configs": []config.GenericMap{
{
Expand All @@ -217,8 +220,8 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o
"metric_relabel_configs": []config.GenericMap{
{
"source_labels": []string{"__name__"},
"regex": "(.*odigos.*|^otelcol_processor_accepted.*)",
"action": "keep",
"regex": "(.*odigos.*|^otelcol_processor_accepted.*)",
"action": "keep",
},
},
},
Expand All @@ -234,11 +237,11 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o
},
},
Service: config.Service{
Pipelines: map[string]config.Pipeline{
Pipelines: map[string]config.Pipeline{
"metrics/otelcol": {
Receivers: []string{"prometheus/self-metrics"},
Receivers: []string{"prometheus/self-metrics"},
Processors: []string{"resource/pod-name"},
Exporters: []string{"otlp/odigos-own-telemetry-ui"},
Exporters: []string{"otlp/odigos-own-telemetry-ui"},
},
},
Extensions: []string{"health_check"},
Expand All @@ -249,7 +252,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o
Resource: map[string]*string{
// The collector add "otelcol" as a service name, so we need to remove it
// to avoid duplication, since we are interested in the instrumented services.
string(semconv.ServiceNameKey): nil,
string(semconv.ServiceNameKey): nil,
// The collector adds its own version as a service version, which is not needed currently.
string(semconv.ServiceVersionKey): nil,
},
Expand All @@ -274,6 +277,8 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o
}
}

commonProcessors := getCommonProcessorsByTier(tier)

if collectLogs {
includes := make([]string, 0)
for _, element := range apps.Items {
Expand Down Expand Up @@ -313,15 +318,15 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o

cfg.Service.Pipelines["logs"] = config.Pipeline{
Receivers: []string{"filelog"},
Processors: append([]string{"batch", "odigosresourcename", "resource", "resourcedetection", "odigostrafficmetrics"}, logsProcessors...),
Processors: append(commonProcessors, logsProcessors...),
Exporters: []string{"otlp/gateway"},
}
}

if collectTraces {
cfg.Service.Pipelines["traces"] = config.Pipeline{
Receivers: []string{"otlp"},
Processors: append([]string{"batch", "odigosresourcename", "resource", "resourcedetection", "odigostrafficmetrics"}, tracesProcessors...),
Processors: append(commonProcessors, tracesProcessors...),
Exporters: tracesPipelineExporter,
}
}
Expand All @@ -336,7 +341,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o

cfg.Service.Pipelines["metrics"] = config.Pipeline{
Receivers: []string{"otlp", "kubeletstats"},
Processors: append([]string{"batch", "odigosresourcename", "resource", "resourcedetection", "odigostrafficmetrics"}, metricsProcessors...),
Processors: append(commonProcessors, metricsProcessors...),
Exporters: []string{"otlp/gateway"},
}
}
Expand Down Expand Up @@ -396,3 +401,12 @@ func getSignalsFromOtelcolConfig(otelcolConfigContent string) ([]common.Observab

return signals, nil
}

func getCommonProcessorsByTier(tier common.OdigosTier) []string {
processors := []string{"batch"}
if tier != common.OnPremOdigosTier {
processors = append(processors, "odigosresourcename")
}
processors = append(processors, "resource", "resourcedetection", "odigostrafficmetrics")
return processors
}
2 changes: 1 addition & 1 deletion autoscaler/controllers/datacollection/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestCalculateConfigMapData(t *testing.T) {
},
},
},
false)
false, common.CommunityOdigosTier)

assert.Equal(t, err, nil)
assert.Equal(t, want, got)
Expand Down
9 changes: 5 additions & 4 deletions autoscaler/controllers/datacollection/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -18,7 +19,7 @@ const (
syncDaemonsetRetry = 3
)

func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string) error {
func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, tier common.OdigosTier) error {
logger := log.FromContext(ctx)

var instApps odigosv1.InstrumentedApplicationList
Expand Down Expand Up @@ -51,16 +52,16 @@ func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePul
return err
}

return syncDataCollection(&instApps, &dests, &processors, &dataCollectionCollectorGroup, ctx, c, scheme, imagePullSecrets, odigosVersion)
return syncDataCollection(&instApps, &dests, &processors, &dataCollectionCollectorGroup, ctx, c, scheme, imagePullSecrets, odigosVersion, tier)
}

func syncDataCollection(instApps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList,
dataCollection *odigosv1.CollectorsGroup, ctx context.Context, c client.Client,
scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string) error {
scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, tier common.OdigosTier) error {
logger := log.FromContext(ctx)
logger.V(0).Info("Syncing data collection")

_, err := SyncConfigMap(instApps, dests, processors, dataCollection, ctx, c, scheme)
_, err := SyncConfigMap(instApps, dests, processors, dataCollection, ctx, c, scheme, tier)
if err != nil {
logger.Error(err, "Failed to sync config map")
return err
Expand Down
4 changes: 3 additions & 1 deletion autoscaler/controllers/instrumentedapplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/datacollection"
"github.com/odigos-io/odigos/common"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -33,6 +34,7 @@ type InstrumentedApplicationReconciler struct {
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
OdigosTier common.OdigosTier
}

//+kubebuilder:rbac:groups=odigos.io,resources=instrumentedapplications,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -50,7 +52,7 @@ type InstrumentedApplicationReconciler struct {
func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling InstrumentedApps")
err := datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion)
err := datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
4 changes: 3 additions & 1 deletion autoscaler/controllers/processor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
v1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/datacollection"
"github.com/odigos-io/odigos/autoscaler/controllers/gateway"
"github.com/odigos-io/odigos/common"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -17,6 +18,7 @@ type ProcessorReconciler struct {
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
OdigosTier common.OdigosTier
}

func (r *ProcessorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
Expand All @@ -29,7 +31,7 @@ func (r *ProcessorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, err
}

err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion)
err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
Loading

0 comments on commit fb6b757

Please sign in to comment.