Skip to content

Commit

Permalink
Merge branch 'main' into fix-test-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 authored Aug 30, 2023
2 parents c8e5c51 + eb6ec46 commit b9cb118
Show file tree
Hide file tree
Showing 39 changed files with 490 additions and 438 deletions.
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/dlclark/regexp2 v1.10.0
github.com/gin-gonic/gin v1.9.1
github.com/go-logr/logr v1.2.4
github.com/jaegertracing/jaeger v1.47.0
github.com/jaegertracing/jaeger v1.48.0
github.com/pelletier/go-toml/v2 v2.0.9
github.com/prometheus/client_golang v1.16.0
github.com/sirupsen/logrus v1.9.3
Expand All @@ -22,12 +22,12 @@ require (
go.opentelemetry.io/otel/trace v1.16.0
go.uber.org/zap v1.25.0
google.golang.org/grpc v1.57.0
k8s.io/api v0.27.4
k8s.io/apimachinery v0.27.4
k8s.io/apiserver v0.27.4
k8s.io/client-go v0.27.4
k8s.io/api v0.28.1
k8s.io/apimachinery v0.28.1
k8s.io/apiserver v0.28.1
k8s.io/client-go v0.28.1
k8s.io/klog/v2 v2.100.1
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
)

require (
Expand All @@ -49,7 +49,7 @@ require (
github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
Expand All @@ -70,12 +70,11 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v23.1.21+incompatible // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
Expand Down Expand Up @@ -129,18 +128,19 @@ require (
go.etcd.io/etcd/api/v3 v3.5.9 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.1-0.20230612162650-64be7e574a17 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
Expand All @@ -151,7 +151,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
86 changes: 40 additions & 46 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hack/tfconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
defaultConfig: "20000000"
configs:
- id: "00000000"
name: "tree"
Expand Down
18 changes: 9 additions & 9 deletions pkg/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/kubewharf/kelemetry/pkg/aggregator/tracer"
"github.com/kubewharf/kelemetry/pkg/manager"
"github.com/kubewharf/kelemetry/pkg/metrics"
"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
"github.com/kubewharf/kelemetry/pkg/util/zconstants"
)

Expand Down Expand Up @@ -109,7 +109,7 @@ type Aggregator interface {
// it waits for the primary event to be created and takes it as the parent.
// If the primary event does not get created after options.subObjectPrimaryBackoff, this event is promoted as primary.
// If multiple primary events are sent, the slower one (by SpanCache-authoritative timing) is demoted.
Send(ctx context.Context, object util.ObjectRef, event *aggregatorevent.Event, subObjectId *SubObjectId) error
Send(ctx context.Context, object utilobject.Rich, event *aggregatorevent.Event, subObjectId *SubObjectId) error
}

type SubObjectId struct {
Expand Down Expand Up @@ -183,7 +183,7 @@ func (aggregator *aggregator) Close(ctx context.Context) error { return nil }

func (aggregator *aggregator) Send(
ctx context.Context,
object util.ObjectRef,
object utilobject.Rich,
event *aggregatorevent.Event,
subObjectId *SubObjectId,
) (err error) {
Expand Down Expand Up @@ -370,12 +370,12 @@ func (aggregator *aggregator) Send(

func (aggregator *aggregator) ensureObjectSpan(
ctx context.Context,
object util.ObjectRef,
object utilobject.Rich,
eventTime time.Time,
) (tracer.SpanContext, error) {
return aggregator.getOrCreateSpan(ctx, object, eventTime, func() (_ tracer.SpanContext, err error) {
// try to associate a parent object
var parent *util.ObjectRef
var parent *utilobject.Rich

for _, linker := range aggregator.Linkers.Impls {
parent = linker.Lookup(ctx, object)
Expand All @@ -395,7 +395,7 @@ func (aggregator *aggregator) ensureObjectSpan(

func (aggregator *aggregator) getOrCreateSpan(
ctx context.Context,
object util.ObjectRef,
object utilobject.Rich,
eventTime time.Time,
parentGetter func() (tracer.SpanContext, error),
) (tracer.SpanContext, error) {
Expand Down Expand Up @@ -530,7 +530,7 @@ func (aggregator *aggregator) getOrCreateSpan(

func (aggregator *aggregator) createSpan(
ctx context.Context,
object util.ObjectRef,
object utilobject.Rich,
nestLevel string,
eventTime time.Time,
parent tracer.SpanContext,
Expand Down Expand Up @@ -580,11 +580,11 @@ func (aggregator *aggregator) createSpan(
return spanContext, nil
}

func (aggregator *aggregator) expiringSpanCacheKey(object util.ObjectRef, timestamp time.Time) string {
func (aggregator *aggregator) expiringSpanCacheKey(object utilobject.Rich, timestamp time.Time) string {
expiringWindow := timestamp.Unix() / int64(aggregator.options.spanTtl.Seconds())
return aggregator.spanCacheKey(object, fmt.Sprintf("field=object,window=%d", expiringWindow))
}

func (aggregator *aggregator) spanCacheKey(object util.ObjectRef, subObjectId string) string {
func (aggregator *aggregator) spanCacheKey(object utilobject.Rich, subObjectId string) string {
return fmt.Sprintf("%s/%s", object.String(), subObjectId)
}
4 changes: 2 additions & 2 deletions pkg/aggregator/eventdecorator/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"context"

"github.com/kubewharf/kelemetry/pkg/aggregator/aggregatorevent"
"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
)

type Decorator interface {
Decorate(ctx context.Context, object util.ObjectRef, event *aggregatorevent.Event)
Decorate(ctx context.Context, object utilobject.Rich, event *aggregatorevent.Event)
}
4 changes: 2 additions & 2 deletions pkg/aggregator/eventdecorator/eventtagger/eventtagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/kubewharf/kelemetry/pkg/aggregator/eventdecorator"
"github.com/kubewharf/kelemetry/pkg/aggregator/resourcetagger"
"github.com/kubewharf/kelemetry/pkg/manager"
"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
)

func init() {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (d *eventTagDecorator) Init() error {
func (d *eventTagDecorator) Start(ctx context.Context) error { return nil }
func (d *eventTagDecorator) Close(ctx context.Context) error { return nil }

func (d *eventTagDecorator) Decorate(ctx context.Context, object util.ObjectRef, event *aggregatorevent.Event) {
func (d *eventTagDecorator) Decorate(ctx context.Context, object utilobject.Rich, event *aggregatorevent.Event) {
if event == nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/aggregator/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package linker
import (
"context"

"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
)

type Linker interface {
Lookup(ctx context.Context, object util.ObjectRef) *util.ObjectRef
Lookup(ctx context.Context, object utilobject.Rich) *utilobject.Rich
}
4 changes: 2 additions & 2 deletions pkg/aggregator/objectspandecorator/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package objectspandecorator
import (
"context"

"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
)

type Decorator interface {
Decorate(ctx context.Context, object util.ObjectRef, traceSource string, tags map[string]string)
Decorate(ctx context.Context, object utilobject.Rich, traceSource string, tags map[string]string)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/kubewharf/kelemetry/pkg/aggregator/objectspandecorator"
"github.com/kubewharf/kelemetry/pkg/aggregator/resourcetagger"
"github.com/kubewharf/kelemetry/pkg/manager"
"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
)

func init() {
Expand Down Expand Up @@ -54,7 +54,7 @@ func (d *ObjectSpanTag) Init() error { return nil }
func (d *ObjectSpanTag) Start(ctx context.Context) error { return nil }
func (d *ObjectSpanTag) Close(ctx context.Context) error { return nil }

func (d *ObjectSpanTag) Decorate(ctx context.Context, object util.ObjectRef, traceSource string, tags map[string]string) {
func (d *ObjectSpanTag) Decorate(ctx context.Context, object utilobject.Rich, traceSource string, tags map[string]string) {
if tags == nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/aggregator/resourcetagger/resource_tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/kubewharf/kelemetry/pkg/k8s/objectcache"
"github.com/kubewharf/kelemetry/pkg/manager"
"github.com/kubewharf/kelemetry/pkg/metrics"
"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
)

func init() {
Expand Down Expand Up @@ -133,7 +133,7 @@ func (d *ResourceTagger) registerResource(gr schema.GroupResource, tagPathMappin
}
}

func (d *ResourceTagger) DecorateTag(ctx context.Context, object util.ObjectRef, traceSource string, tags map[string]any) {
func (d *ResourceTagger) DecorateTag(ctx context.Context, object utilobject.Rich, traceSource string, tags map[string]any) {
if tags == nil {
return
}
Expand All @@ -153,7 +153,7 @@ func (d *ResourceTagger) DecorateTag(ctx context.Context, object util.ObjectRef,
logger.Debug("Fetching dynamic object for tag decorator")

var err error
raw, err = d.ObjectCache.Get(ctx, object)
raw, err = d.ObjectCache.Get(ctx, object.VersionedKey)
if err != nil {
tagMetric.Result = "FetchErr"
logger.WithError(err).Error("cannot fetch object value")
Expand Down
21 changes: 5 additions & 16 deletions pkg/annotationlinker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import (

"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/kubewharf/kelemetry/pkg/aggregator/linker"
"github.com/kubewharf/kelemetry/pkg/k8s"
"github.com/kubewharf/kelemetry/pkg/k8s/discovery"
"github.com/kubewharf/kelemetry/pkg/k8s/objectcache"
"github.com/kubewharf/kelemetry/pkg/manager"
"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
)

func init() {
Expand Down Expand Up @@ -59,7 +58,7 @@ func (ctrl *controller) Init() error { return nil }
func (ctrl *controller) Start(ctx context.Context) error { return nil }
func (ctrl *controller) Close(ctx context.Context) error { return nil }

func (ctrl *controller) Lookup(ctx context.Context, object util.ObjectRef) *util.ObjectRef {
func (ctrl *controller) Lookup(ctx context.Context, object utilobject.Rich) *utilobject.Rich {
raw := object.Raw

logger := ctrl.Logger.WithFields(object.AsFields("object"))
Expand All @@ -68,7 +67,7 @@ func (ctrl *controller) Lookup(ctx context.Context, object util.ObjectRef) *util
logger.Debug("Fetching dynamic object")

var err error
raw, err = ctrl.ObjectCache.Get(ctx, object)
raw, err = ctrl.ObjectCache.Get(ctx, object.VersionedKey)

if err != nil {
logger.WithError(err).Error("cannot fetch object value")
Expand All @@ -93,20 +92,10 @@ func (ctrl *controller) Lookup(ctx context.Context, object util.ObjectRef) *util
ref.Cluster = object.Cluster
}

objectRef := &util.ObjectRef{
Cluster: ref.Cluster,
GroupVersionResource: schema.GroupVersionResource{
Group: ref.GroupVersionResource.Group,
Version: ref.GroupVersionResource.Version,
Resource: ref.GroupVersionResource.Resource,
},
Namespace: ref.Namespace,
Name: ref.Name,
Uid: ref.Uid,
}
objectRef := ref.ToRich()
logger.WithField("parent", objectRef).Debug("Resolved parent")

return objectRef
return &objectRef
}

return nil
Expand Down
18 changes: 18 additions & 0 deletions pkg/annotationlinker/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package annotationlinker
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
)

const LinkAnnotation = "kelemetry.kubewharf.io/parent-link"
Expand All @@ -31,3 +33,19 @@ type ParentLink struct {

Uid types.UID `json:"uid"`
}

func (ln ParentLink) ToRich() utilobject.Rich {
return utilobject.Rich{
VersionedKey: utilobject.VersionedKey{
Key: utilobject.Key{
Cluster: ln.Cluster,
Group: ln.Group,
Resource: ln.Resource,
Namespace: ln.Namespace,
Name: ln.Name,
},
Version: ln.Version,
},
Uid: ln.Uid,
}
}
14 changes: 2 additions & 12 deletions pkg/audit/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"github.com/kubewharf/kelemetry/pkg/k8s/discovery"
"github.com/kubewharf/kelemetry/pkg/manager"
"github.com/kubewharf/kelemetry/pkg/metrics"
"github.com/kubewharf/kelemetry/pkg/util"
utilobject "github.com/kubewharf/kelemetry/pkg/util/object"
"github.com/kubewharf/kelemetry/pkg/util/shutdown"
"github.com/kubewharf/kelemetry/pkg/util/zconstants"
)
Expand Down Expand Up @@ -210,17 +210,7 @@ func (recv *receiver) handleItem(
}
}

objectRef := util.ObjectRef{
Cluster: message.Cluster,
GroupVersionResource: schema.GroupVersionResource{
Group: message.ObjectRef.APIGroup,
Version: message.ObjectRef.APIVersion,
Resource: message.ObjectRef.Resource,
},
Namespace: message.ObjectRef.Namespace,
Name: message.ObjectRef.Name,
Uid: message.ObjectRef.UID,
}
objectRef := utilobject.RichFromAudit(message.ObjectRef, message.Cluster)

if message.ResponseObject != nil {
objectRef.Raw = &unstructured.Unstructured{
Expand Down
Loading

0 comments on commit b9cb118

Please sign in to comment.