Skip to content

Commit

Permalink
Informers cache: don't send updates for non-meaningful Pod/Service up…
Browse files Browse the repository at this point in the history
…dates (#1330)

* Informers cache: don't send updates for non-meaningful Pod/Service updates

* update helm chart and dependencies

* reverted dependency changes

* update k8s utils dependency
  • Loading branch information
mariomac authored Nov 7, 2024
1 parent 6301bb7 commit 2c89a9f
Show file tree
Hide file tree
Showing 44 changed files with 3,342 additions and 236 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ install-hooks:
prereqs: install-hooks
@echo "### Check if prerequisites are met, and installing missing dependencies"
mkdir -p $(TEST_OUTPUT)/run
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,v1.60.3)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,v1.61.0)
$(call go-install-tool,$(BPF2GO),github.com/cilium/ebpf/cmd/bpf2go,$(call gomod-version,cilium/ebpf))
$(call go-install-tool,$(GO_OFFSETS_TRACKER),github.com/grafana/go-offsets-tracker/cmd/go-offsets-tracker,$(call gomod-version,grafana/go-offsets-tracker))
$(call go-install-tool,$(GOIMPORTS_REVISER),github.com/incu6us/goimports-reviser/v3,v3.6.4)
Expand Down
2 changes: 1 addition & 1 deletion charts/beyla/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: beyla
version: 1.4.7
version: 1.4.8
appVersion: 1.8.6
description: eBPF-based autoinstrumentation HTTP, HTTP2 and gRPC services, as well as network metrics.
home: https://grafana.com/oss/beyla-ebpf/
Expand Down
18 changes: 18 additions & 0 deletions charts/beyla/templates/cache-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,25 @@ spec:
- containerPort: {{ .Values.k8sCache.service.port }}
protocol: TCP
name: grpc
{{- if .Values.k8sCache.profile_port }}
- name: profile
containerPort: {{ .Values.k8sCache.profile_port }}
protocol: TCP
{{- end }}
env:
- name: BEYLA_K8S_CACHE_PORT
value: "{{ .Values.k8sCache.service.port }}"
{{- if .Values.k8sCache.profile_port }}
- name: BEYLA_K8S_CACHE_PROFILE_PORT
value: "{{ .Values.k8sCache.profile_port }}"
{{- end }}
{{- range $key, $value := .Values.k8sCache.env }}
- name: {{ $key }}
value: "{{ $value }}"
{{- end }}
{{- range $key, $value := .Values.k8sCache.envValueFrom }}
- name: {{ $key | quote }}
valueFrom:
{{- tpl (toYaml $value) $ | nindent 16 }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/beyla/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ serviceMonitor:
k8sCache:
# -- Number of replicas for the Kubernetes metadata chache service. 0 disables the service.
replicas: 0
# -- Enables the profile port for the Beyla cache
profile_port: 0
## Env variables that will override configmap values
## For example:
## BEYLA_K8S_CACHE_LOG_LEVEL: "debug"
# -- extra environment variables
env: {}
# BEYLA_K8S_CACHE_LOG_LEVEL: "debug"

# -- extra environment variables to be set from resources such as k8s configMaps/secrets
envValueFrom: {}
# ENV_NAME:
# secretKeyRef:
# name: secret-name
# key: value_key
image:
# -- K8s Cache image registry (defaults to docker.io)
registry: "docker.io"
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/go-logr/logr v1.4.2
github.com/gobwas/glob v0.2.3
github.com/goccy/go-json v0.10.2
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/grafana/go-offsets-tracker v0.1.7
Expand All @@ -25,7 +26,7 @@ require (
github.com/shirou/gopsutil/v3 v3.24.4
github.com/stretchr/testify v1.9.0
github.com/vishvananda/netlink v1.1.0
github.com/vladimirvivien/gexe v0.2.0
github.com/vladimirvivien/gexe v0.3.0
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
github.com/yl2chen/cidranger v1.0.2
go.opentelemetry.io/collector/component v0.112.0
Expand Down Expand Up @@ -56,7 +57,7 @@ require (
go.opentelemetry.io/otel/trace v1.31.0
go.uber.org/zap v1.27.0
golang.org/x/arch v0.7.0
golang.org/x/mod v0.17.0
golang.org/x/mod v0.20.0
golang.org/x/net v0.30.0
golang.org/x/sys v0.26.0
google.golang.org/grpc v1.67.1
Expand Down Expand Up @@ -110,7 +111,6 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
Expand Down Expand Up @@ -177,10 +177,10 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/apiextensions-apiserver v0.31.2 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJ
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vladimirvivien/gexe v0.2.0 h1:nbdAQ6vbZ+ZNsolCgSVb9Fno60kzSuvtzVh6Ytqi/xY=
github.com/vladimirvivien/gexe v0.2.0/go.mod h1:LHQL00w/7gDUKIak24n801ABp8C+ni6eBht9vGVst8w=
github.com/vladimirvivien/gexe v0.3.0 h1:4xwiOwGrDob5OMR6E92B9olDXYDglXdHhzR1ggYtWJM=
github.com/vladimirvivien/gexe v0.3.0/go.mod h1:fp7cy60ON1xjhtEI/+bfSEIXX35qgmI+iRYlGOqbBFM=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ=
Expand Down Expand Up @@ -379,8 +379,8 @@ golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6R
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down Expand Up @@ -451,8 +451,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk=
k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk=
k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk=
k8s.io/apiextensions-apiserver v0.31.2 h1:W8EwUb8+WXBLu56ser5IudT2cOho0gAKeTOnywBLxd0=
k8s.io/apiextensions-apiserver v0.31.2/go.mod h1:i+Geh+nGCJEGiCGR3MlBDkS7koHIIKWVfWeRFiOsUcM=
k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw=
k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc=
Expand All @@ -461,8 +461,8 @@ k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b h1:Q9xmGWBvOGd8UJyccgpYlLosk/JlfP3xQLNkQlHJeXw=
k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b/go.mod h1:UxDHUPsUwTOOxSU+oXURfFBcAS6JwiRXTYqYwfuGowc=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 h1:jGnCPejIetjiy2gqaJ5V0NLwTpF4wbQ6cZIItJCSHno=
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
sigs.k8s.io/controller-runtime v0.19.1 h1:Son+Q40+Be3QWb+niBXAg2vFiYWolDjjRfO8hn/cxOk=
sigs.k8s.io/controller-runtime v0.19.1/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
Expand Down
23 changes: 21 additions & 2 deletions pkg/kubecache/meta/informers_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/testing/protocmp"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -38,6 +40,9 @@ type informersConfig struct {
kubeClient kubernetes.Interface
}

// global object used for comparing protobuf messages in the informers event handlers
var protoCmpTransform = protocmp.Transform()

type InformerOption func(*informersConfig)

func WithKubeConfigPath(path string) InformerOption {
Expand Down Expand Up @@ -228,7 +233,14 @@ func (inf *Informers) initPodInformer(informerFactory informers.SharedInformerFa
Resource: obj.(*indexableEntity).EncodedMeta,
})
},
UpdateFunc: func(_, newObj interface{}) {
UpdateFunc: func(oldObj, newObj interface{}) {
if cmp.Equal(
oldObj.(*indexableEntity).EncodedMeta,
newObj.(*indexableEntity).EncodedMeta,
protoCmpTransform,
) {
return
}
inf.Notify(&informer.Event{
Type: informer.EventType_UPDATED,
Resource: newObj.(*indexableEntity).EncodedMeta,
Expand Down Expand Up @@ -366,7 +378,14 @@ func (inf *Informers) ipInfoEventHandler() *cache.ResourceEventHandlerFuncs {
Resource: obj.(*indexableEntity).EncodedMeta,
})
},
UpdateFunc: func(_, newObj interface{}) {
UpdateFunc: func(oldObj, newObj interface{}) {
if cmp.Equal(
oldObj.(*indexableEntity).EncodedMeta,
newObj.(*indexableEntity).EncodedMeta,
protoCmpTransform,
) {
return
}
inf.Notify(&informer.Event{
Type: informer.EventType_UPDATED,
Resource: newObj.(*indexableEntity).EncodedMeta,
Expand Down
185 changes: 185 additions & 0 deletions vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go

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

Loading

0 comments on commit 2c89a9f

Please sign in to comment.