From bd6a02b826298199dc11f8bbef8c48ea772ca164 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Wed, 9 Oct 2024 07:37:19 -0700 Subject: [PATCH 01/42] feat: add memory-based trace --- telemetry/log/memory/log.go | 4 +- telemetry/trace/domain.go | 13 ++++ telemetry/trace/memory/options.go | 20 ++++++ telemetry/trace/memory/trace.go | 105 ++++++++++++++++++++++++++++++ telemetry/trace/options.go | 53 +++++++++++++++ telemetry/trace/trace.go | 21 ++++++ telemetry/trace/utils.go | 30 +++++++++ 7 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 telemetry/trace/domain.go create mode 100644 telemetry/trace/memory/options.go create mode 100644 telemetry/trace/memory/trace.go create mode 100644 telemetry/trace/options.go create mode 100644 telemetry/trace/trace.go create mode 100644 telemetry/trace/utils.go diff --git a/telemetry/log/memory/log.go b/telemetry/log/memory/log.go index 8a2eec1..dcee4ec 100644 --- a/telemetry/log/memory/log.go +++ b/telemetry/log/memory/log.go @@ -30,10 +30,12 @@ func (l *memoryLog) Write(rec log.Record) error { func (l *memoryLog) Read(opts ...log.ReadOption) ([]log.Record, error) { options := log.NewReadOptions(opts...) - entries := []*buffer.Entry{} + var entries []*buffer.Entry if options.Count > 0 { entries = l.buffer.Get(options.Count) + } else { + entries = l.buffer.Get(l.buffer.Options().Size) } records := []log.Record{} diff --git a/telemetry/trace/domain.go b/telemetry/trace/domain.go new file mode 100644 index 0000000..165f811 --- /dev/null +++ b/telemetry/trace/domain.go @@ -0,0 +1,13 @@ +package trace + +import "time" + +type Span struct { + Name string + Id string + Parent string + Trace string + Started time.Time + Duration time.Duration + Metadata map[string]string +} diff --git a/telemetry/trace/memory/options.go b/telemetry/trace/memory/options.go new file mode 100644 index 0000000..80294cc --- /dev/null +++ b/telemetry/trace/memory/options.go @@ -0,0 +1,20 @@ +package memory + +import ( + "context" + + "github.com/w-h-a/pkg/telemetry/trace" +) + +type sizeKey struct{} + +func LogWithSize(s int) trace.TraceOption { + return func(o *trace.TraceOptions) { + o.Context = context.WithValue(o.Context, sizeKey{}, s) + } +} + +func GetSizeFromContext(ctx context.Context) (int, bool) { + s, ok := ctx.Value(sizeKey{}).(int) + return s, ok +} diff --git a/telemetry/trace/memory/trace.go b/telemetry/trace/memory/trace.go new file mode 100644 index 0000000..3090584 --- /dev/null +++ b/telemetry/trace/memory/trace.go @@ -0,0 +1,105 @@ +package memory + +import ( + "context" + "time" + + "github.com/google/uuid" + "github.com/w-h-a/pkg/telemetry/buffer" + "github.com/w-h-a/pkg/telemetry/buffer/memory" + "github.com/w-h-a/pkg/telemetry/trace" +) + +type memoryTrace struct { + options trace.TraceOptions + buffer buffer.Buffer +} + +func (t *memoryTrace) Options() trace.TraceOptions { + return t.options +} + +func (t *memoryTrace) Start(ctx context.Context, name string, md map[string]string) (context.Context, *trace.Span, error) { + span := &trace.Span{ + Name: name, + Id: uuid.New().String(), + Trace: uuid.New().String(), + Started: time.Now(), + Metadata: md, + } + + if ctx == nil { + newCtx, err := trace.ContextWithIds(context.Background(), span.Trace, span.Id) + return newCtx, span, err + } + + traceId, traceFound, parentId, spanFound := trace.IdsFromContext(ctx) + + if !traceFound { + newCtx, err := trace.ContextWithIds(ctx, span.Trace, span.Id) + return newCtx, span, err + } else { + span.Trace = traceId + } + + if spanFound { + span.Parent = parentId + } + + newCtx, err := trace.ContextWithIds(ctx, span.Trace, span.Id) + return newCtx, span, err +} + +func (t *memoryTrace) Finish(span *trace.Span) error { + span.Duration = time.Since(span.Started) + + t.buffer.Put(span) + + return nil +} + +func (t *memoryTrace) Read(opts ...trace.ReadOption) ([]*trace.Span, error) { + options := trace.NewReadOptions(opts...) + + var entries []*buffer.Entry + + if options.Count > 0 { + entries = t.buffer.Get(options.Count) + } else { + entries = t.buffer.Get(t.buffer.Options().Size) + } + + spans := []*trace.Span{} + + for _, entry := range entries { + span := entry.Value.(*trace.Span) + + if len(options.Trace) > 0 && options.Trace != span.Trace { + continue + } + + spans = append(spans, span) + } + + return spans, nil +} + +func (t *memoryTrace) String() string { + return "memory" +} + +func NewTrace(opts ...trace.TraceOption) trace.Trace { + options := trace.NewTraceOptions(opts...) + + t := &memoryTrace{ + options: options, + } + + if s, ok := GetSizeFromContext(options.Context); ok && s > 0 { + t.buffer = memory.NewBuffer(buffer.BufferWithSize(s)) + } else { + t.buffer = memory.NewBuffer() + } + + return t +} diff --git a/telemetry/trace/options.go b/telemetry/trace/options.go new file mode 100644 index 0000000..c788eec --- /dev/null +++ b/telemetry/trace/options.go @@ -0,0 +1,53 @@ +package trace + +import "context" + +type TraceOption func(o *TraceOptions) + +type TraceOptions struct { + Context context.Context +} + +func NewTraceOptions(opts ...TraceOption) TraceOptions { + options := TraceOptions{ + Context: context.Background(), + } + + for _, fn := range opts { + fn(&options) + } + + return options +} + +type ReadOption func(o *ReadOptions) + +type ReadOptions struct { + Trace string + Count int + Context context.Context +} + +func ReadWithTrace(t string) ReadOption { + return func(o *ReadOptions) { + o.Trace = t + } +} + +func ReadWithCount(c int) ReadOption { + return func(o *ReadOptions) { + o.Count = c + } +} + +func NewReadOptions(opts ...ReadOption) ReadOptions { + options := ReadOptions{ + Context: context.Background(), + } + + for _, fn := range opts { + fn(&options) + } + + return options +} diff --git a/telemetry/trace/trace.go b/telemetry/trace/trace.go new file mode 100644 index 0000000..b094da9 --- /dev/null +++ b/telemetry/trace/trace.go @@ -0,0 +1,21 @@ +package trace + +import "context" + +var tracer Trace + +type Trace interface { + Options() TraceOptions + Start(ctx context.Context, name string, md map[string]string) (context.Context, *Span, error) + Finish(span *Span) error + Read(opts ...ReadOption) ([]*Span, error) + String() string +} + +func SetTracer(t Trace) { + tracer = t +} + +func GetTracer() Trace { + return tracer +} diff --git a/telemetry/trace/utils.go b/telemetry/trace/utils.go new file mode 100644 index 0000000..945ba26 --- /dev/null +++ b/telemetry/trace/utils.go @@ -0,0 +1,30 @@ +package trace + +import ( + "context" + + "github.com/w-h-a/pkg/utils/metadatautils" +) + +const ( + traceIdKey = "trace-id" + spanIdKey = "span-id" +) + +func ContextWithIds(ctx context.Context, traceId, parentId string) (context.Context, error) { + return metadatautils.MergeContext(ctx, map[string]string{ + traceIdKey: traceId, + spanIdKey: parentId, + }, true), nil +} + +func IdsFromContext(ctx context.Context) (traceId string, foundTrace bool, parentId string, foundParent bool) { + traceId, traceOk := metadatautils.GetContext(ctx, traceId) + if !traceOk { + return + } + + parentId, spanOk := metadatautils.GetContext(ctx, spanIdKey) + + return traceId, traceOk, parentId, spanOk +} From dea1c66a2a1af3d77d612eee9b932a506ea0127e Mon Sep 17 00:00:00 2001 From: w-h-a Date: Wed, 9 Oct 2024 07:39:44 -0700 Subject: [PATCH 02/42] refactor: quick name change --- telemetry/trace/memory/options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telemetry/trace/memory/options.go b/telemetry/trace/memory/options.go index 80294cc..d9c4102 100644 --- a/telemetry/trace/memory/options.go +++ b/telemetry/trace/memory/options.go @@ -8,7 +8,7 @@ import ( type sizeKey struct{} -func LogWithSize(s int) trace.TraceOption { +func TraceWithSize(s int) trace.TraceOption { return func(o *trace.TraceOptions) { o.Context = context.WithValue(o.Context, sizeKey{}, s) } From 8751ea7e7df9d3e27d87595c3e6d032b640ea811 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Thu, 10 Oct 2024 16:13:14 -0700 Subject: [PATCH 03/42] feat: poor man's trace exporter --- Makefile | 4 + proto/trace/trace.pb.go | 345 ++++++++++++++++++++++++++++++++ proto/trace/trace.proto | 26 +++ serverv2/grpc/handlers/trace.go | 43 ++++ serverv2/grpc/handlers/utils.go | 18 ++ serverv2/grpc/server.go | 17 +- serverv2/http/handlers/trace.go | 45 +++++ serverv2/http/server.go | 20 +- serverv2/http/utils.go | 24 --- serverv2/options.go | 7 + utils/httputils/http_utils.go | 19 ++ 11 files changed, 542 insertions(+), 26 deletions(-) create mode 100644 proto/trace/trace.pb.go create mode 100644 proto/trace/trace.proto create mode 100644 serverv2/grpc/handlers/trace.go create mode 100644 serverv2/grpc/handlers/utils.go create mode 100644 serverv2/http/handlers/trace.go delete mode 100644 serverv2/http/utils.go diff --git a/Makefile b/Makefile index 5ce24fb..091ef53 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,10 @@ test: proto-health: protoc proto/health/*.proto --go_out=paths=source_relative:. --proto_path=. +.PHONY: proto-trace +proto-trace: + protoc proto/trace/*.proto --go_out=paths=source_relative:. --proto_path=. + .PHONY: proto-sidecar proto-sidecar: protoc proto/sidecar/*.proto --go_out=paths=source_relative:. --proto_path=. diff --git a/proto/trace/trace.pb.go b/proto/trace/trace.pb.go new file mode 100644 index 0000000..58f3a99 --- /dev/null +++ b/proto/trace/trace.pb.go @@ -0,0 +1,345 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.21.9 +// source: proto/trace/trace.proto + +package trace + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// domain +type Span struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + Parent string `protobuf:"bytes,3,opt,name=parent,proto3" json:"parent,omitempty"` + Trace string `protobuf:"bytes,4,opt,name=trace,proto3" json:"trace,omitempty"` + Started uint64 `protobuf:"varint,5,opt,name=started,proto3" json:"started,omitempty"` + Duration uint64 `protobuf:"varint,6,opt,name=duration,proto3" json:"duration,omitempty"` + Metadata map[string]string `protobuf:"bytes,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *Span) Reset() { + *x = Span{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_trace_trace_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Span) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Span) ProtoMessage() {} + +func (x *Span) ProtoReflect() protoreflect.Message { + mi := &file_proto_trace_trace_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Span.ProtoReflect.Descriptor instead. +func (*Span) Descriptor() ([]byte, []int) { + return file_proto_trace_trace_proto_rawDescGZIP(), []int{0} +} + +func (x *Span) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Span) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Span) GetParent() string { + if x != nil { + return x.Parent + } + return "" +} + +func (x *Span) GetTrace() string { + if x != nil { + return x.Trace + } + return "" +} + +func (x *Span) GetStarted() uint64 { + if x != nil { + return x.Started + } + return 0 +} + +func (x *Span) GetDuration() uint64 { + if x != nil { + return x.Duration + } + return 0 +} + +func (x *Span) GetMetadata() map[string]string { + if x != nil { + return x.Metadata + } + return nil +} + +// trace request/response +type TraceRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Count uint64 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` +} + +func (x *TraceRequest) Reset() { + *x = TraceRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_trace_trace_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TraceRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TraceRequest) ProtoMessage() {} + +func (x *TraceRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_trace_trace_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TraceRequest.ProtoReflect.Descriptor instead. +func (*TraceRequest) Descriptor() ([]byte, []int) { + return file_proto_trace_trace_proto_rawDescGZIP(), []int{1} +} + +func (x *TraceRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *TraceRequest) GetCount() uint64 { + if x != nil { + return x.Count + } + return 0 +} + +type TraceResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Spans []*Span `protobuf:"bytes,1,rep,name=spans,proto3" json:"spans,omitempty"` +} + +func (x *TraceResponse) Reset() { + *x = TraceResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_trace_trace_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TraceResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TraceResponse) ProtoMessage() {} + +func (x *TraceResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_trace_trace_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TraceResponse.ProtoReflect.Descriptor instead. +func (*TraceResponse) Descriptor() ([]byte, []int) { + return file_proto_trace_trace_proto_rawDescGZIP(), []int{2} +} + +func (x *TraceResponse) GetSpans() []*Span { + if x != nil { + return x.Spans + } + return nil +} + +var File_proto_trace_trace_proto protoreflect.FileDescriptor + +var file_proto_trace_trace_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2f, 0x74, 0x72, + 0x61, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, + 0x22, 0x82, 0x02, 0x0a, 0x04, 0x53, 0x70, 0x61, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, + 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, + 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x73, 0x74, + 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x35, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x07, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x61, 0x6e, + 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, + 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, + 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x34, 0x0a, 0x0c, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x32, 0x0a, 0x0d, 0x54, + 0x72, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, + 0x73, 0x70, 0x61, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x74, 0x72, + 0x61, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x61, 0x6e, 0x52, 0x05, 0x73, 0x70, 0x61, 0x6e, 0x73, 0x42, + 0x22, 0x5a, 0x20, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, + 0x68, 0x2d, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, + 0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_trace_trace_proto_rawDescOnce sync.Once + file_proto_trace_trace_proto_rawDescData = file_proto_trace_trace_proto_rawDesc +) + +func file_proto_trace_trace_proto_rawDescGZIP() []byte { + file_proto_trace_trace_proto_rawDescOnce.Do(func() { + file_proto_trace_trace_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_trace_trace_proto_rawDescData) + }) + return file_proto_trace_trace_proto_rawDescData +} + +var file_proto_trace_trace_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_proto_trace_trace_proto_goTypes = []interface{}{ + (*Span)(nil), // 0: trace.Span + (*TraceRequest)(nil), // 1: trace.TraceRequest + (*TraceResponse)(nil), // 2: trace.TraceResponse + nil, // 3: trace.Span.MetadataEntry +} +var file_proto_trace_trace_proto_depIdxs = []int32{ + 3, // 0: trace.Span.metadata:type_name -> trace.Span.MetadataEntry + 0, // 1: trace.TraceResponse.spans:type_name -> trace.Span + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_proto_trace_trace_proto_init() } +func file_proto_trace_trace_proto_init() { + if File_proto_trace_trace_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_trace_trace_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Span); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_trace_trace_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TraceRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_trace_trace_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TraceResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_trace_trace_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_proto_trace_trace_proto_goTypes, + DependencyIndexes: file_proto_trace_trace_proto_depIdxs, + MessageInfos: file_proto_trace_trace_proto_msgTypes, + }.Build() + File_proto_trace_trace_proto = out.File + file_proto_trace_trace_proto_rawDesc = nil + file_proto_trace_trace_proto_goTypes = nil + file_proto_trace_trace_proto_depIdxs = nil +} diff --git a/proto/trace/trace.proto b/proto/trace/trace.proto new file mode 100644 index 0000000..7f8468a --- /dev/null +++ b/proto/trace/trace.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; + +package trace; + +option go_package = "github.com/w-h-a/pkg/proto/trace"; + +// domain +message Span { + string name = 1; + string id = 2; + string parent = 3; + string trace = 4; + uint64 started = 5; + uint64 duration = 6; + map metadata = 7; +} + +// trace request/response +message TraceRequest { + string id = 1; + uint64 count = 2; +} + +message TraceResponse { + repeated Span spans = 1; +} \ No newline at end of file diff --git a/serverv2/grpc/handlers/trace.go b/serverv2/grpc/handlers/trace.go new file mode 100644 index 0000000..31ae307 --- /dev/null +++ b/serverv2/grpc/handlers/trace.go @@ -0,0 +1,43 @@ +package handlers + +import ( + "context" + + pb "github.com/w-h-a/pkg/proto/trace" + "github.com/w-h-a/pkg/telemetry/trace" + "github.com/w-h-a/pkg/utils/errorutils" +) + +type TraceHandler interface { + Read(ctx context.Context, req *pb.TraceRequest, rsp *pb.TraceResponse) error +} + +type Trace struct { + TraceHandler +} + +type traceHandler struct { + tracer trace.Trace +} + +func (h *traceHandler) Read(ctx context.Context, req *pb.TraceRequest, rsp *pb.TraceResponse) error { + spans, err := h.tracer.Read( + trace.ReadWithTrace(req.Id), + trace.ReadWithCount(int(req.Count)), + ) + if err != nil { + return errorutils.InternalServerError("trace", "failed to retrieve traces: %v", err) + } + + for _, span := range spans { + rsp.Spans = append(rsp.Spans, SerializeSpan(span)) + } + + return nil +} + +func NewTraceHandler(tracer trace.Trace) TraceHandler { + return &Trace{&traceHandler{ + tracer: tracer, + }} +} diff --git a/serverv2/grpc/handlers/utils.go b/serverv2/grpc/handlers/utils.go new file mode 100644 index 0000000..a3eabad --- /dev/null +++ b/serverv2/grpc/handlers/utils.go @@ -0,0 +1,18 @@ +package handlers + +import ( + pb "github.com/w-h-a/pkg/proto/trace" + "github.com/w-h-a/pkg/telemetry/trace" +) + +func SerializeSpan(s *trace.Span) *pb.Span { + return &pb.Span{ + Name: s.Name, + Id: s.Id, + Parent: s.Parent, + Trace: s.Trace, + Started: uint64(s.Started.UnixNano()), + Duration: uint64(s.Duration.Nanoseconds()), + Metadata: s.Metadata, + } +} diff --git a/serverv2/grpc/server.go b/serverv2/grpc/server.go index 2425669..771184b 100644 --- a/serverv2/grpc/server.go +++ b/serverv2/grpc/server.go @@ -16,7 +16,9 @@ import ( "time" "github.com/w-h-a/pkg/serverv2" + "github.com/w-h-a/pkg/serverv2/grpc/handlers" "github.com/w-h-a/pkg/telemetry/log" + "github.com/w-h-a/pkg/telemetry/trace" "github.com/w-h-a/pkg/utils/errorutils" "github.com/w-h-a/pkg/utils/marshalutils" "github.com/w-h-a/pkg/utils/metadatautils" @@ -84,7 +86,20 @@ func (s *server) Run() error { } s.mtx.RUnlock() - // TODO: init exporters here? + if len(s.options.Tracer) > 0 { + // init trace exporters + switch s.options.Tracer { + case "memory": + tracer := trace.GetTracer() + if tracer == nil { + log.Fatalf("failed to init memory trace exporter: memory tracer was not set") + } + grpcTrace := handlers.NewTraceHandler(tracer) + s.Handle(NewHandler(grpcTrace)) + default: + log.Warnf("tracer %s is not supported", s.options.Tracer) + } + } // TODO: tls listener, err := net.Listen("tcp", s.options.Address) diff --git a/serverv2/http/handlers/trace.go b/serverv2/http/handlers/trace.go new file mode 100644 index 0000000..c5da17b --- /dev/null +++ b/serverv2/http/handlers/trace.go @@ -0,0 +1,45 @@ +package handlers + +import ( + "net/http" + "strconv" + + "github.com/w-h-a/pkg/telemetry/trace" + "github.com/w-h-a/pkg/utils/errorutils" + "github.com/w-h-a/pkg/utils/httputils" +) + +type TraceHandler interface { + Read(w http.ResponseWriter, r *http.Request) +} + +type traceHandler struct { + tracer trace.Trace +} + +func (h *traceHandler) Read(w http.ResponseWriter, r *http.Request) { + id := r.URL.Query().Get("id") + + count := r.URL.Query().Get("count") + + c, err := strconv.Atoi(count) + if err != nil { + httputils.ErrResponse(w, errorutils.BadRequest("trace", "received bad count query param: %v", err)) + return + } + + spans, err := h.tracer.Read( + trace.ReadWithTrace(id), + trace.ReadWithCount(c), + ) + if err != nil { + httputils.ErrResponse(w, errorutils.InternalServerError("trace", "failed to retrieve traces: %v", err)) + return + } + + httputils.OkResponse(w, spans) +} + +func NewTraceHandler(tracer trace.Trace) TraceHandler { + return &traceHandler{tracer} +} diff --git a/serverv2/http/server.go b/serverv2/http/server.go index e8799c6..c65afa9 100644 --- a/serverv2/http/server.go +++ b/serverv2/http/server.go @@ -12,8 +12,11 @@ import ( "syscall" "time" + "github.com/gorilla/mux" "github.com/w-h-a/pkg/serverv2" + "github.com/w-h-a/pkg/serverv2/http/handlers" "github.com/w-h-a/pkg/telemetry/log" + "github.com/w-h-a/pkg/telemetry/trace" ) type server struct { @@ -68,7 +71,22 @@ func (s *server) Run() error { } s.mtx.RUnlock() - // TODO: init exporters here? + if len(s.options.Tracer) > 0 { + // init trace exporters + switch s.options.Tracer { + case "memory": + tracer := trace.GetTracer() + if tracer == nil { + log.Fatalf("failed to init memory trace exporter: memory tracer was not set") + } + router := mux.NewRouter() + httpTrace := handlers.NewTraceHandler(tracer) + router.Methods("GET").Path("/").HandlerFunc(httpTrace.Read) + s.mux.Handle("/trace", router) + default: + log.Warnf("tracer %s is not supported", s.options.Tracer) + } + } // TODO: tls listener, err := net.Listen("tcp", s.options.Address) diff --git a/serverv2/http/utils.go b/serverv2/http/utils.go deleted file mode 100644 index 71fa12a..0000000 --- a/serverv2/http/utils.go +++ /dev/null @@ -1,24 +0,0 @@ -package http - -import ( - "encoding/json" - "net/http" - - "github.com/w-h-a/pkg/utils/errorutils" -) - -func ErrResponse(w http.ResponseWriter, err error) { - internal := err.(*errorutils.Error) - Response(w, int(internal.Code), []byte(internal.Error())) -} - -func OkResponse(w http.ResponseWriter, payload interface{}) { - bs, _ := json.Marshal(payload) - Response(w, 200, bs) -} - -func Response(w http.ResponseWriter, code int, bs []byte) { - w.Header().Set("content-type", "application/json") - w.WriteHeader(code) - w.Write(bs) -} diff --git a/serverv2/options.go b/serverv2/options.go index 54b343a..3bf7102 100644 --- a/serverv2/options.go +++ b/serverv2/options.go @@ -12,6 +12,7 @@ type ServerOptions struct { Id string Version string Address string + Tracer string Context context.Context } @@ -45,6 +46,12 @@ func ServerWithAddress(addr string) ServerOption { } } +func ServerWithTracer(tracer string) ServerOption { + return func(o *ServerOptions) { + o.Tracer = tracer + } +} + func NewServerOptions(opts ...ServerOption) ServerOptions { options := ServerOptions{ Namespace: defaultNamespace, diff --git a/utils/httputils/http_utils.go b/utils/httputils/http_utils.go index 5dc047e..f5839bc 100644 --- a/utils/httputils/http_utils.go +++ b/utils/httputils/http_utils.go @@ -2,11 +2,14 @@ package httputils import ( "bytes" + "encoding/json" "fmt" "io" "net/http" "strings" "time" + + "github.com/w-h-a/pkg/utils/errorutils" ) func HttpGetNTimes(url string, n int) ([]byte, error) { @@ -63,3 +66,19 @@ func ExtractBody(r io.ReadCloser) ([]byte, error) { return body, nil } + +func ErrResponse(w http.ResponseWriter, err error) { + internal := err.(*errorutils.Error) + Response(w, int(internal.Code), []byte(internal.Error())) +} + +func OkResponse(w http.ResponseWriter, payload interface{}) { + bs, _ := json.Marshal(payload) + Response(w, 200, bs) +} + +func Response(w http.ResponseWriter, code int, bs []byte) { + w.Header().Set("content-type", "application/json") + w.WriteHeader(code) + w.Write(bs) +} From e362b871bbe5e6ec8463058b99b6dc2b530fddef Mon Sep 17 00:00:00 2001 From: w-h-a Date: Thu, 10 Oct 2024 17:17:13 -0700 Subject: [PATCH 04/42] refactor: try a diff strategy --- serverv2/grpc/handlers/trace.go | 43 ------------------------------- serverv2/grpc/handlers/utils.go | 18 ------------- serverv2/grpc/server.go | 17 ------------- serverv2/http/handlers/trace.go | 45 --------------------------------- serverv2/http/server.go | 20 --------------- serverv2/options.go | 7 ----- 6 files changed, 150 deletions(-) delete mode 100644 serverv2/grpc/handlers/trace.go delete mode 100644 serverv2/grpc/handlers/utils.go delete mode 100644 serverv2/http/handlers/trace.go diff --git a/serverv2/grpc/handlers/trace.go b/serverv2/grpc/handlers/trace.go deleted file mode 100644 index 31ae307..0000000 --- a/serverv2/grpc/handlers/trace.go +++ /dev/null @@ -1,43 +0,0 @@ -package handlers - -import ( - "context" - - pb "github.com/w-h-a/pkg/proto/trace" - "github.com/w-h-a/pkg/telemetry/trace" - "github.com/w-h-a/pkg/utils/errorutils" -) - -type TraceHandler interface { - Read(ctx context.Context, req *pb.TraceRequest, rsp *pb.TraceResponse) error -} - -type Trace struct { - TraceHandler -} - -type traceHandler struct { - tracer trace.Trace -} - -func (h *traceHandler) Read(ctx context.Context, req *pb.TraceRequest, rsp *pb.TraceResponse) error { - spans, err := h.tracer.Read( - trace.ReadWithTrace(req.Id), - trace.ReadWithCount(int(req.Count)), - ) - if err != nil { - return errorutils.InternalServerError("trace", "failed to retrieve traces: %v", err) - } - - for _, span := range spans { - rsp.Spans = append(rsp.Spans, SerializeSpan(span)) - } - - return nil -} - -func NewTraceHandler(tracer trace.Trace) TraceHandler { - return &Trace{&traceHandler{ - tracer: tracer, - }} -} diff --git a/serverv2/grpc/handlers/utils.go b/serverv2/grpc/handlers/utils.go deleted file mode 100644 index a3eabad..0000000 --- a/serverv2/grpc/handlers/utils.go +++ /dev/null @@ -1,18 +0,0 @@ -package handlers - -import ( - pb "github.com/w-h-a/pkg/proto/trace" - "github.com/w-h-a/pkg/telemetry/trace" -) - -func SerializeSpan(s *trace.Span) *pb.Span { - return &pb.Span{ - Name: s.Name, - Id: s.Id, - Parent: s.Parent, - Trace: s.Trace, - Started: uint64(s.Started.UnixNano()), - Duration: uint64(s.Duration.Nanoseconds()), - Metadata: s.Metadata, - } -} diff --git a/serverv2/grpc/server.go b/serverv2/grpc/server.go index 771184b..b1a97b0 100644 --- a/serverv2/grpc/server.go +++ b/serverv2/grpc/server.go @@ -16,9 +16,7 @@ import ( "time" "github.com/w-h-a/pkg/serverv2" - "github.com/w-h-a/pkg/serverv2/grpc/handlers" "github.com/w-h-a/pkg/telemetry/log" - "github.com/w-h-a/pkg/telemetry/trace" "github.com/w-h-a/pkg/utils/errorutils" "github.com/w-h-a/pkg/utils/marshalutils" "github.com/w-h-a/pkg/utils/metadatautils" @@ -86,21 +84,6 @@ func (s *server) Run() error { } s.mtx.RUnlock() - if len(s.options.Tracer) > 0 { - // init trace exporters - switch s.options.Tracer { - case "memory": - tracer := trace.GetTracer() - if tracer == nil { - log.Fatalf("failed to init memory trace exporter: memory tracer was not set") - } - grpcTrace := handlers.NewTraceHandler(tracer) - s.Handle(NewHandler(grpcTrace)) - default: - log.Warnf("tracer %s is not supported", s.options.Tracer) - } - } - // TODO: tls listener, err := net.Listen("tcp", s.options.Address) if err != nil { diff --git a/serverv2/http/handlers/trace.go b/serverv2/http/handlers/trace.go deleted file mode 100644 index c5da17b..0000000 --- a/serverv2/http/handlers/trace.go +++ /dev/null @@ -1,45 +0,0 @@ -package handlers - -import ( - "net/http" - "strconv" - - "github.com/w-h-a/pkg/telemetry/trace" - "github.com/w-h-a/pkg/utils/errorutils" - "github.com/w-h-a/pkg/utils/httputils" -) - -type TraceHandler interface { - Read(w http.ResponseWriter, r *http.Request) -} - -type traceHandler struct { - tracer trace.Trace -} - -func (h *traceHandler) Read(w http.ResponseWriter, r *http.Request) { - id := r.URL.Query().Get("id") - - count := r.URL.Query().Get("count") - - c, err := strconv.Atoi(count) - if err != nil { - httputils.ErrResponse(w, errorutils.BadRequest("trace", "received bad count query param: %v", err)) - return - } - - spans, err := h.tracer.Read( - trace.ReadWithTrace(id), - trace.ReadWithCount(c), - ) - if err != nil { - httputils.ErrResponse(w, errorutils.InternalServerError("trace", "failed to retrieve traces: %v", err)) - return - } - - httputils.OkResponse(w, spans) -} - -func NewTraceHandler(tracer trace.Trace) TraceHandler { - return &traceHandler{tracer} -} diff --git a/serverv2/http/server.go b/serverv2/http/server.go index c65afa9..844f4b7 100644 --- a/serverv2/http/server.go +++ b/serverv2/http/server.go @@ -12,11 +12,8 @@ import ( "syscall" "time" - "github.com/gorilla/mux" "github.com/w-h-a/pkg/serverv2" - "github.com/w-h-a/pkg/serverv2/http/handlers" "github.com/w-h-a/pkg/telemetry/log" - "github.com/w-h-a/pkg/telemetry/trace" ) type server struct { @@ -71,23 +68,6 @@ func (s *server) Run() error { } s.mtx.RUnlock() - if len(s.options.Tracer) > 0 { - // init trace exporters - switch s.options.Tracer { - case "memory": - tracer := trace.GetTracer() - if tracer == nil { - log.Fatalf("failed to init memory trace exporter: memory tracer was not set") - } - router := mux.NewRouter() - httpTrace := handlers.NewTraceHandler(tracer) - router.Methods("GET").Path("/").HandlerFunc(httpTrace.Read) - s.mux.Handle("/trace", router) - default: - log.Warnf("tracer %s is not supported", s.options.Tracer) - } - } - // TODO: tls listener, err := net.Listen("tcp", s.options.Address) if err != nil { diff --git a/serverv2/options.go b/serverv2/options.go index 3bf7102..54b343a 100644 --- a/serverv2/options.go +++ b/serverv2/options.go @@ -12,7 +12,6 @@ type ServerOptions struct { Id string Version string Address string - Tracer string Context context.Context } @@ -46,12 +45,6 @@ func ServerWithAddress(addr string) ServerOption { } } -func ServerWithTracer(tracer string) ServerOption { - return func(o *ServerOptions) { - o.Tracer = tracer - } -} - func NewServerOptions(opts ...ServerOption) ServerOptions { options := ServerOptions{ Namespace: defaultNamespace, From 359486e38be78e8be336c8c4aac04046450283e0 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Thu, 10 Oct 2024 17:44:41 -0700 Subject: [PATCH 05/42] chore: debug --- utils/metadatautils/metadata_utils.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/metadatautils/metadata_utils.go b/utils/metadatautils/metadata_utils.go index 18b7d63..fa8cd00 100644 --- a/utils/metadatautils/metadata_utils.go +++ b/utils/metadatautils/metadata_utils.go @@ -4,6 +4,8 @@ import ( "context" "net/http" "strings" + + "github.com/w-h-a/pkg/telemetry/log" ) type metadataKey struct{} @@ -57,6 +59,7 @@ func GetContext(ctx context.Context, k string) (string, bool) { } val, ok := md[strings.ToLower(k)] + log.Infof("GET CONTEXT KEY %s, VALUE %s, md %#+v", k, val, md) return val, ok } @@ -90,6 +93,7 @@ func RequestToContext(r *http.Request) context.Context { md := Metadata{} for k, v := range r.Header { + log.Infof("KEY %s, VALUE %s", k, v) md[strings.ToLower(k)] = strings.Join(v, ",") } From 7bd708a78e174278f5dc6786de89fef147313e00 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Thu, 10 Oct 2024 17:50:46 -0700 Subject: [PATCH 06/42] fix: use the key --- telemetry/trace/utils.go | 2 +- utils/metadatautils/metadata_utils.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/telemetry/trace/utils.go b/telemetry/trace/utils.go index 945ba26..b438682 100644 --- a/telemetry/trace/utils.go +++ b/telemetry/trace/utils.go @@ -19,7 +19,7 @@ func ContextWithIds(ctx context.Context, traceId, parentId string) (context.Cont } func IdsFromContext(ctx context.Context) (traceId string, foundTrace bool, parentId string, foundParent bool) { - traceId, traceOk := metadatautils.GetContext(ctx, traceId) + traceId, traceOk := metadatautils.GetContext(ctx, traceIdKey) if !traceOk { return } diff --git a/utils/metadatautils/metadata_utils.go b/utils/metadatautils/metadata_utils.go index fa8cd00..18b7d63 100644 --- a/utils/metadatautils/metadata_utils.go +++ b/utils/metadatautils/metadata_utils.go @@ -4,8 +4,6 @@ import ( "context" "net/http" "strings" - - "github.com/w-h-a/pkg/telemetry/log" ) type metadataKey struct{} @@ -59,7 +57,6 @@ func GetContext(ctx context.Context, k string) (string, bool) { } val, ok := md[strings.ToLower(k)] - log.Infof("GET CONTEXT KEY %s, VALUE %s, md %#+v", k, val, md) return val, ok } @@ -93,7 +90,6 @@ func RequestToContext(r *http.Request) context.Context { md := Metadata{} for k, v := range r.Header { - log.Infof("KEY %s, VALUE %s", k, v) md[strings.ToLower(k)] = strings.Join(v, ",") } From 6d9006a7e641f199804bf721e42d21371fed2969 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Thu, 10 Oct 2024 22:15:58 -0700 Subject: [PATCH 07/42] refactor: add some json annotes --- telemetry/trace/domain.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/telemetry/trace/domain.go b/telemetry/trace/domain.go index 165f811..1425747 100644 --- a/telemetry/trace/domain.go +++ b/telemetry/trace/domain.go @@ -3,11 +3,11 @@ package trace import "time" type Span struct { - Name string - Id string - Parent string - Trace string - Started time.Time - Duration time.Duration - Metadata map[string]string + Name string `json:"name"` + Id string `json:"id"` + Parent string `json:"parent"` + Trace string `json:"trace"` + Started time.Time `json:"started"` + Duration time.Duration `json:"duration"` + Metadata map[string]string `json:"metadata"` } From ded195ccdcac7f99665c34137347d8404a560ebc Mon Sep 17 00:00:00 2001 From: w-h-a Date: Fri, 11 Oct 2024 15:47:52 -0700 Subject: [PATCH 08/42] refactor: reading from secret store should take ctx --- sidecar/custom/sidecar.go | 30 +++++++++++++++++++++++++++++- sidecar/sidecar.go | 3 ++- telemetry/trace/domain.go | 4 +++- telemetry/trace/trace.go | 10 +++++++++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 4e4a291..6e822ae 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -13,6 +13,7 @@ import ( "github.com/w-h-a/pkg/sidecar" "github.com/w-h-a/pkg/store" "github.com/w-h-a/pkg/telemetry/log" + "github.com/w-h-a/pkg/telemetry/trace" "github.com/w-h-a/pkg/utils/datautils" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -181,18 +182,45 @@ func (s *customSidecar) UnsubscribeFromBroker(brokerId string) error { return nil } -func (s *customSidecar) ReadFromSecretStore(secretStore string, name string) (*sidecar.Secret, error) { +func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*sidecar.Secret, error) { + tracer := trace.GetTracer() + + if tracer == nil { + log.Error("failed to get tracer") + return nil, trace.ErrNotFound + } + + _, span, err := tracer.Start( + ctx, + "customSidecar.ReadFromSecretStore", + map[string]string{ + "secretStore": secretStore, + "name": name, + "error": "", + }, + ) + if err != nil { + log.Errorf("failed to start span: %v", err) + return nil, trace.ErrStart + } + sc, ok := s.options.Secrets[secretStore] if !ok { log.Warnf("secret store %s was not found", secretStore) + span.Metadata["error"] = fmt.Sprintf("secret store %s was not found", secretStore) + tracer.Finish(span) return nil, sidecar.ErrComponentNotFound } mp, err := sc.GetSecret(name) if err != nil { + span.Metadata["error"] = err.Error() + tracer.Finish(span) return nil, err } + tracer.Finish(span) + return &sidecar.Secret{ Data: mp, }, nil diff --git a/sidecar/sidecar.go b/sidecar/sidecar.go index fe6dea9..1d1bf68 100644 --- a/sidecar/sidecar.go +++ b/sidecar/sidecar.go @@ -1,6 +1,7 @@ package sidecar import ( + "context" "errors" "github.com/w-h-a/pkg/store" @@ -20,6 +21,6 @@ type Sidecar interface { WriteEventToBroker(event *Event) error ReadEventsFromBroker(broker string) UnsubscribeFromBroker(broker string) error - ReadFromSecretStore(secretStore string, name string) (*Secret, error) + ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*Secret, error) String() string } diff --git a/telemetry/trace/domain.go b/telemetry/trace/domain.go index 1425747..58a0895 100644 --- a/telemetry/trace/domain.go +++ b/telemetry/trace/domain.go @@ -1,6 +1,8 @@ package trace -import "time" +import ( + "time" +) type Span struct { Name string `json:"name"` diff --git a/telemetry/trace/trace.go b/telemetry/trace/trace.go index b094da9..e84a549 100644 --- a/telemetry/trace/trace.go +++ b/telemetry/trace/trace.go @@ -1,6 +1,14 @@ package trace -import "context" +import ( + "context" + "errors" +) + +var ( + ErrNotFound = errors.New("not found") + ErrStart = errors.New("failed to start span") +) var tracer Trace From 4e20b8807194ac8bf1ae1075efd23a25a0e6c817 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sat, 12 Oct 2024 14:36:37 -0700 Subject: [PATCH 09/42] refactor: default to memory instead of error --- sidecar/custom/sidecar.go | 6 ++++-- telemetry/trace/trace.go | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 6e822ae..e081a76 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -14,6 +14,7 @@ import ( "github.com/w-h-a/pkg/store" "github.com/w-h-a/pkg/telemetry/log" "github.com/w-h-a/pkg/telemetry/trace" + "github.com/w-h-a/pkg/telemetry/trace/memory" "github.com/w-h-a/pkg/utils/datautils" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -186,8 +187,9 @@ func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore str tracer := trace.GetTracer() if tracer == nil { - log.Error("failed to get tracer") - return nil, trace.ErrNotFound + log.Error("setting default memory tracer") + tracer = memory.NewTrace() + trace.SetTracer(tracer) } _, span, err := tracer.Start( diff --git a/telemetry/trace/trace.go b/telemetry/trace/trace.go index e84a549..b5d417a 100644 --- a/telemetry/trace/trace.go +++ b/telemetry/trace/trace.go @@ -6,8 +6,7 @@ import ( ) var ( - ErrNotFound = errors.New("not found") - ErrStart = errors.New("failed to start span") + ErrStart = errors.New("failed to start span") ) var tracer Trace From 2fdf70b991630dde52b573244c3e9676374a8a37 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 08:24:12 -0700 Subject: [PATCH 10/42] feat: otel based memory tracer --- go.mod | 7 +- go.sum | 15 +++- proto/trace/trace.pb.go | 55 +++++------- proto/trace/trace.proto | 5 +- sidecar/custom/sidecar.go | 40 ++++----- sidecar/options.go | 8 ++ telemetry/tracev2/domain.go | 16 ++++ telemetry/tracev2/memory/exporter.go | 63 ++++++++++++++ telemetry/tracev2/memory/options.go | 35 ++++++++ telemetry/tracev2/memory/span.go | 50 +++++++++++ telemetry/tracev2/memory/trace.go | 123 +++++++++++++++++++++++++++ telemetry/tracev2/options.go | 78 +++++++++++++++++ telemetry/tracev2/span.go | 8 ++ telemetry/tracev2/trace.go | 21 +++++ telemetry/tracev2/utils.go | 36 ++++++++ 15 files changed, 498 insertions(+), 62 deletions(-) create mode 100644 telemetry/tracev2/domain.go create mode 100644 telemetry/tracev2/memory/exporter.go create mode 100644 telemetry/tracev2/memory/options.go create mode 100644 telemetry/tracev2/memory/span.go create mode 100644 telemetry/tracev2/memory/trace.go create mode 100644 telemetry/tracev2/options.go create mode 100644 telemetry/tracev2/span.go create mode 100644 telemetry/tracev2/trace.go create mode 100644 telemetry/tracev2/utils.go diff --git a/go.mod b/go.mod index 481bc6c..62ae0e7 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,9 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/stretchr/testify v1.9.0 github.com/w-h-a/crd v0.1.0 + go.opentelemetry.io/otel v1.31.0 + go.opentelemetry.io/otel/sdk v1.31.0 + go.opentelemetry.io/otel/trace v1.31.0 golang.org/x/crypto v0.26.0 golang.org/x/text v0.17.0 google.golang.org/grpc v1.65.0 @@ -44,6 +47,7 @@ require ( github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.4 // indirect @@ -64,9 +68,10 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/x448/float16 v0.8.4 // indirect + go.opentelemetry.io/otel/metric v1.31.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.24.0 // indirect + golang.org/x/sys v0.26.0 // indirect golang.org/x/term v0.23.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect diff --git a/go.sum b/go.sum index 35d36db..5239e55 100644 --- a/go.sum +++ b/go.sum @@ -41,8 +41,11 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= @@ -132,6 +135,14 @@ 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/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= +go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk= +go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -153,8 +164,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/proto/trace/trace.pb.go b/proto/trace/trace.pb.go index 58f3a99..7ac17c4 100644 --- a/proto/trace/trace.pb.go +++ b/proto/trace/trace.pb.go @@ -31,7 +31,7 @@ type Span struct { Parent string `protobuf:"bytes,3,opt,name=parent,proto3" json:"parent,omitempty"` Trace string `protobuf:"bytes,4,opt,name=trace,proto3" json:"trace,omitempty"` Started uint64 `protobuf:"varint,5,opt,name=started,proto3" json:"started,omitempty"` - Duration uint64 `protobuf:"varint,6,opt,name=duration,proto3" json:"duration,omitempty"` + Ended uint64 `protobuf:"varint,6,opt,name=ended,proto3" json:"ended,omitempty"` Metadata map[string]string `protobuf:"bytes,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } @@ -102,9 +102,9 @@ func (x *Span) GetStarted() uint64 { return 0 } -func (x *Span) GetDuration() uint64 { +func (x *Span) GetEnded() uint64 { if x != nil { - return x.Duration + return x.Ended } return 0 } @@ -122,8 +122,7 @@ type TraceRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Count uint64 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` + Count uint64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` } func (x *TraceRequest) Reset() { @@ -158,13 +157,6 @@ func (*TraceRequest) Descriptor() ([]byte, []int) { return file_proto_trace_trace_proto_rawDescGZIP(), []int{1} } -func (x *TraceRequest) GetId() string { - if x != nil { - return x.Id - } - return "" -} - func (x *TraceRequest) GetCount() uint64 { if x != nil { return x.Count @@ -224,32 +216,31 @@ var File_proto_trace_trace_proto protoreflect.FileDescriptor var file_proto_trace_trace_proto_rawDesc = []byte{ 0x0a, 0x17, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, - 0x22, 0x82, 0x02, 0x0a, 0x04, 0x53, 0x70, 0x61, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, + 0x22, 0xfc, 0x01, 0x0a, 0x04, 0x53, 0x70, 0x61, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x73, 0x74, - 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x12, 0x35, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x07, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x61, 0x6e, - 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, - 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x34, 0x0a, 0x0c, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x32, 0x0a, 0x0d, 0x54, - 0x72, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, - 0x73, 0x70, 0x61, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x74, 0x72, - 0x61, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x61, 0x6e, 0x52, 0x05, 0x73, 0x70, 0x61, 0x6e, 0x73, 0x42, - 0x22, 0x5a, 0x20, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, - 0x68, 0x2d, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, - 0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x64, 0x65, 0x64, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x6e, 0x64, 0x65, 0x64, 0x12, 0x35, 0x0a, 0x08, 0x6d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, + 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x61, 0x6e, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, + 0x24, 0x0a, 0x0c, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x32, 0x0a, 0x0d, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x73, 0x70, 0x61, 0x6e, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x53, 0x70, + 0x61, 0x6e, 0x52, 0x05, 0x73, 0x70, 0x61, 0x6e, 0x73, 0x42, 0x22, 0x5a, 0x20, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, 0x70, 0x6b, + 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/trace/trace.proto b/proto/trace/trace.proto index 7f8468a..011c3f5 100644 --- a/proto/trace/trace.proto +++ b/proto/trace/trace.proto @@ -11,14 +11,13 @@ message Span { string parent = 3; string trace = 4; uint64 started = 5; - uint64 duration = 6; + uint64 ended = 6; map metadata = 7; } // trace request/response message TraceRequest { - string id = 1; - uint64 count = 2; + uint64 count = 1; } message TraceResponse { diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index e081a76..bba7092 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -13,8 +13,7 @@ import ( "github.com/w-h-a/pkg/sidecar" "github.com/w-h-a/pkg/store" "github.com/w-h-a/pkg/telemetry/log" - "github.com/w-h-a/pkg/telemetry/trace" - "github.com/w-h-a/pkg/telemetry/trace/memory" + "github.com/w-h-a/pkg/telemetry/tracev2" "github.com/w-h-a/pkg/utils/datautils" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -184,44 +183,37 @@ func (s *customSidecar) UnsubscribeFromBroker(brokerId string) error { } func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*sidecar.Secret, error) { - tracer := trace.GetTracer() + // TODO: make sure we have a tracer - if tracer == nil { - log.Error("setting default memory tracer") - tracer = memory.NewTrace() - trace.SetTracer(tracer) - } - - _, span, err := tracer.Start( - ctx, - "customSidecar.ReadFromSecretStore", - map[string]string{ - "secretStore": secretStore, - "name": name, - "error": "", - }, - ) + _, span, err := s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") if err != nil { log.Errorf("failed to start span: %v", err) - return nil, trace.ErrStart + return nil, tracev2.ErrStart } + s.options.Tracer.AddMetadata(span, map[string]string{ + "secretStore": secretStore, + "name": name, + }) + sc, ok := s.options.Secrets[secretStore] if !ok { log.Warnf("secret store %s was not found", secretStore) - span.Metadata["error"] = fmt.Sprintf("secret store %s was not found", secretStore) - tracer.Finish(span) + // TODO: update status of span + s.options.Tracer.Finish(span) return nil, sidecar.ErrComponentNotFound } mp, err := sc.GetSecret(name) if err != nil { - span.Metadata["error"] = err.Error() - tracer.Finish(span) + // TODO: update status of span + s.options.Tracer.Finish(span) return nil, err } - tracer.Finish(span) + // TODO: update status of span + + s.options.Tracer.Finish(span) return &sidecar.Secret{ Data: mp, diff --git a/sidecar/options.go b/sidecar/options.go index e7460e3..4f600cd 100644 --- a/sidecar/options.go +++ b/sidecar/options.go @@ -7,6 +7,7 @@ import ( "github.com/w-h-a/pkg/client" "github.com/w-h-a/pkg/security/secret" "github.com/w-h-a/pkg/store" + "github.com/w-h-a/pkg/telemetry/tracev2" ) type SidecarOption func(o *SidecarOptions) @@ -20,6 +21,7 @@ type SidecarOptions struct { Stores map[string]store.Store Brokers map[string]broker.Broker Secrets map[string]secret.Secret + Tracer tracev2.Trace Context context.Context } @@ -76,6 +78,12 @@ func SidecarWithSecrets(s map[string]secret.Secret) SidecarOption { } } +func SidecarWithTracer(tr tracev2.Trace) SidecarOption { + return func(o *SidecarOptions) { + o.Tracer = tr + } +} + func NewSidecarOptions(opts ...SidecarOption) SidecarOptions { options := SidecarOptions{ Stores: map[string]store.Store{}, diff --git a/telemetry/tracev2/domain.go b/telemetry/tracev2/domain.go new file mode 100644 index 0000000..3a245a7 --- /dev/null +++ b/telemetry/tracev2/domain.go @@ -0,0 +1,16 @@ +package tracev2 + +import ( + "time" +) + +// TODO: status +type SpanData struct { + Name string + Id string + Parent string + Trace string + Started time.Time + Ended time.Time + Metadata map[string]string +} diff --git a/telemetry/tracev2/memory/exporter.go b/telemetry/tracev2/memory/exporter.go new file mode 100644 index 0000000..7918b25 --- /dev/null +++ b/telemetry/tracev2/memory/exporter.go @@ -0,0 +1,63 @@ +package memory + +import ( + "context" + + "github.com/w-h-a/pkg/telemetry/buffer" + "github.com/w-h-a/pkg/telemetry/tracev2" + "go.opentelemetry.io/otel/attribute" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/trace" +) + +type memoryExporter struct { + buffer buffer.Buffer +} + +func (e *memoryExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error { + spanData := []*tracev2.SpanData{} + + for _, s := range spans { + var parentSpanId trace.SpanID + + if s.Parent().IsValid() { + parentSpanId = s.Parent().SpanID() + } + + metadata := map[string]string{} + + for _, attr := range s.Attributes() { + if attr.Value.Type() != attribute.STRING { + continue + } + metadata[string(attr.Key)] = attr.Value.AsString() + } + + data := &tracev2.SpanData{ + Name: s.Name(), + Id: s.SpanContext().SpanID().String(), + Parent: parentSpanId.String(), + Trace: s.SpanContext().TraceID().String(), + Started: s.StartTime(), + Ended: s.EndTime(), + Metadata: metadata, + } + + spanData = append(spanData, data) + } + + for _, d := range spanData { + e.buffer.Put(d) + } + + return nil +} + +// TODO? +func (e *memoryExporter) Shutdown(ctx context.Context) error { + return nil +} + +func NewExporter(buffer buffer.Buffer) sdktrace.SpanExporter { + return &memoryExporter{buffer} +} diff --git a/telemetry/tracev2/memory/options.go b/telemetry/tracev2/memory/options.go new file mode 100644 index 0000000..7878b79 --- /dev/null +++ b/telemetry/tracev2/memory/options.go @@ -0,0 +1,35 @@ +package memory + +import ( + "context" + + "github.com/w-h-a/pkg/telemetry/buffer" + "github.com/w-h-a/pkg/telemetry/tracev2" + "go.opentelemetry.io/otel/trace" +) + +type bufferKey struct{} + +func TraceWithBuffer(b buffer.Buffer) tracev2.TraceOption { + return func(o *tracev2.TraceOptions) { + o.Context = context.WithValue(o.Context, b, bufferKey{}) + } +} + +func GetBufferFromContext(ctx context.Context) (buffer.Buffer, bool) { + b, ok := ctx.Value(bufferKey{}).(buffer.Buffer) + return b, ok +} + +type spanKey struct{} + +func SpanWithSpan(s trace.Span) tracev2.SpanOption { + return func(o *tracev2.SpanOptions) { + o.Context = context.WithValue(o.Context, s, spanKey{}) + } +} + +func GetSpanFromContext(ctx context.Context) (trace.Span, bool) { + s, ok := ctx.Value(spanKey{}).(trace.Span) + return s, ok +} diff --git a/telemetry/tracev2/memory/span.go b/telemetry/tracev2/memory/span.go new file mode 100644 index 0000000..614a5eb --- /dev/null +++ b/telemetry/tracev2/memory/span.go @@ -0,0 +1,50 @@ +package memory + +import ( + "github.com/w-h-a/pkg/telemetry/tracev2" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" +) + +type memorySpan struct { + options tracev2.SpanOptions + span trace.Span +} + +func (s *memorySpan) Options() tracev2.SpanOptions { + return s.options +} + +func (s *memorySpan) AddMetadata(md map[string]string) { + attrs := []attribute.KeyValue{} + + for k, v := range md { + attrs = append(attrs, attribute.String(k, v)) + } + + if len(attrs) > 0 { + s.span.SetAttributes(attrs...) + } +} + +func (s *memorySpan) Finish() { + s.span.End() +} + +func (s *memorySpan) String() string { + return "memory" +} + +func NewSpan(opts ...tracev2.SpanOption) tracev2.Span { + options := tracev2.NewSpanOptions(opts...) + + s := &memorySpan{ + options: options, + } + + if span, ok := GetSpanFromContext(options.Context); ok { + s.span = span + } + + return s +} diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go new file mode 100644 index 0000000..dc9be2a --- /dev/null +++ b/telemetry/tracev2/memory/trace.go @@ -0,0 +1,123 @@ +package memory + +import ( + "context" + + "github.com/w-h-a/pkg/telemetry/buffer" + "github.com/w-h-a/pkg/telemetry/log" + "github.com/w-h-a/pkg/telemetry/tracev2" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/trace" +) + +type memoryTrace struct { + options tracev2.TraceOptions + tracer trace.Tracer + buffer buffer.Buffer +} + +func (t *memoryTrace) Options() tracev2.TraceOptions { + return t.options +} + +func (t *memoryTrace) Start(ctx context.Context, name string) (context.Context, tracev2.Span, error) { + // TODO: make sure we're enabled + + parentCtxCfg := trace.SpanContextConfig{} + + parentData, err := tracev2.SpanDataFromContext(ctx) + if err != nil { + newCtx, memorySpan := t.start(ctx, name, parentCtxCfg) + return newCtx, memorySpan, err + } + + parentCtxCfg.TraceID, err = trace.TraceIDFromHex(parentData.Trace) + if err != nil { + newCtx, memorySpan := t.start(ctx, name, parentCtxCfg) + return newCtx, memorySpan, err + } + + parentCtxCfg.SpanID, err = trace.SpanIDFromHex(parentData.Id) + if err != nil { + newCtx, memorySpan := t.start(ctx, name, parentCtxCfg) + return newCtx, memorySpan, err + } + + newCtx, memorySpan := t.start(ctx, name, parentCtxCfg) + + return newCtx, memorySpan, nil +} + +func (t *memoryTrace) AddMetadata(span tracev2.Span, md map[string]string) { + if span == nil { + return + } + + if len(md) > 0 { + span.AddMetadata(md) + } +} + +func (t *memoryTrace) Finish(span tracev2.Span) { + span.Finish() +} + +func (t *memoryTrace) Read(opts ...tracev2.ReadOption) ([]*tracev2.SpanData, error) { + options := tracev2.NewReadOptions(opts...) + + var entries []*buffer.Entry + + if options.Count > 0 { + entries = t.buffer.Get(options.Count) + } else { + entries = t.buffer.Get(t.buffer.Options().Size) + } + + spans := []*tracev2.SpanData{} + + for _, entry := range entries { + span := entry.Value.(*tracev2.SpanData) + + spans = append(spans, span) + } + + return spans, nil +} + +func (t *memoryTrace) String() string { + return "memory" +} + +func (t *memoryTrace) start(ctx context.Context, name string, parentCtxCfg trace.SpanContextConfig) (context.Context, tracev2.Span) { + parentSpanCtx := trace.NewSpanContext(parentCtxCfg) + + ctx = trace.ContextWithRemoteSpanContext(ctx, parentSpanCtx) + + newCtx, span := t.tracer.Start(ctx, name) + + opts := []tracev2.SpanOption{ + tracev2.SpanWithName(name), + SpanWithSpan(span), + } + + memorySpan := NewSpan(opts...) + + return newCtx, memorySpan +} + +func NewTrace(opts ...tracev2.TraceOption) tracev2.Trace { + options := tracev2.NewTraceOptions(opts...) + + t := &memoryTrace{ + options: options, + tracer: otel.Tracer(options.Name), + } + + if b, ok := GetBufferFromContext(options.Context); ok && b != nil { + t.buffer = b + } else { + log.Fatalf("no buffer was given") + } + + return t +} diff --git a/telemetry/tracev2/options.go b/telemetry/tracev2/options.go new file mode 100644 index 0000000..867c23d --- /dev/null +++ b/telemetry/tracev2/options.go @@ -0,0 +1,78 @@ +package tracev2 + +import "context" + +type TraceOption func(o *TraceOptions) + +type TraceOptions struct { + Name string + Context context.Context +} + +func TraceWithName(name string) TraceOption { + return func(o *TraceOptions) { + o.Name = name + } +} + +func NewTraceOptions(opts ...TraceOption) TraceOptions { + options := TraceOptions{ + Context: context.Background(), + } + + for _, fn := range opts { + fn(&options) + } + + return options +} + +type SpanOption func(o *SpanOptions) + +type SpanOptions struct { + Name string + Context context.Context +} + +func SpanWithName(name string) SpanOption { + return func(o *SpanOptions) { + o.Name = name + } +} + +func NewSpanOptions(opts ...SpanOption) SpanOptions { + options := SpanOptions{ + Context: context.Background(), + } + + for _, fn := range opts { + fn(&options) + } + + return options +} + +type ReadOption func(o *ReadOptions) + +type ReadOptions struct { + Count int + Context context.Context +} + +func ReadWithCount(c int) ReadOption { + return func(o *ReadOptions) { + o.Count = c + } +} + +func NewReadOptions(opts ...ReadOption) ReadOptions { + options := ReadOptions{ + Context: context.Background(), + } + + for _, fn := range opts { + fn(&options) + } + + return options +} diff --git a/telemetry/tracev2/span.go b/telemetry/tracev2/span.go new file mode 100644 index 0000000..e0540fc --- /dev/null +++ b/telemetry/tracev2/span.go @@ -0,0 +1,8 @@ +package tracev2 + +type Span interface { + Options() SpanOptions + AddMetadata(md map[string]string) + Finish() + String() string +} diff --git a/telemetry/tracev2/trace.go b/telemetry/tracev2/trace.go new file mode 100644 index 0000000..60e3082 --- /dev/null +++ b/telemetry/tracev2/trace.go @@ -0,0 +1,21 @@ +package tracev2 + +import ( + "context" + "errors" +) + +var ( + ErrStart = errors.New("failed to start span") +) + +// TODO: status +type Trace interface { + Options() TraceOptions + // TODO: add cfg argument to check for whether tracing is enabled + Start(ctx context.Context, name string) (context.Context, Span, error) + AddMetadata(span Span, md map[string]string) + Finish(span Span) + Read(opts ...ReadOption) ([]*SpanData, error) + String() string +} diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go new file mode 100644 index 0000000..efc4010 --- /dev/null +++ b/telemetry/tracev2/utils.go @@ -0,0 +1,36 @@ +package tracev2 + +import ( + "context" + "encoding/json" + + "github.com/w-h-a/pkg/utils/metadatautils" +) + +const ( + spanDataKey = "trace-spanData" +) + +func ContextWithSpanData(ctx context.Context, spanData *SpanData) (context.Context, error) { + bytes, err := json.Marshal(spanData) + if err != nil { + return ctx, err + } + + return metadatautils.SetContext(ctx, spanDataKey, string(bytes)), nil +} + +func SpanDataFromContext(ctx context.Context) (*SpanData, error) { + str, ok := metadatautils.GetContext(ctx, spanDataKey) + if !ok { + return nil, nil + } + + s := &SpanData{} + + if err := json.Unmarshal([]byte(str), s); err != nil { + return nil, err + } + + return s, nil +} From 4aeb6a12e0fefe70dc07741d6e460aa375053cca Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 08:53:16 -0700 Subject: [PATCH 11/42] feat: expose span data --- telemetry/tracev2/domain.go | 14 +++++++------- telemetry/tracev2/memory/span.go | 8 ++++++++ telemetry/tracev2/span.go | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/telemetry/tracev2/domain.go b/telemetry/tracev2/domain.go index 3a245a7..0707bca 100644 --- a/telemetry/tracev2/domain.go +++ b/telemetry/tracev2/domain.go @@ -6,11 +6,11 @@ import ( // TODO: status type SpanData struct { - Name string - Id string - Parent string - Trace string - Started time.Time - Ended time.Time - Metadata map[string]string + Name string `json:"name"` + Id string `json:"id"` + Parent string `json:"parent"` + Trace string `json:"trace"` + Started time.Time `json:"started"` + Ended time.Time `json:"ended"` + Metadata map[string]string `json:"metadata"` } diff --git a/telemetry/tracev2/memory/span.go b/telemetry/tracev2/memory/span.go index 614a5eb..fee2895 100644 --- a/telemetry/tracev2/memory/span.go +++ b/telemetry/tracev2/memory/span.go @@ -15,6 +15,14 @@ func (s *memorySpan) Options() tracev2.SpanOptions { return s.options } +func (s *memorySpan) SpanData() *tracev2.SpanData { + return &tracev2.SpanData{ + Name: s.options.Name, + Id: s.span.SpanContext().SpanID().String(), + Trace: s.span.SpanContext().TraceID().String(), + } +} + func (s *memorySpan) AddMetadata(md map[string]string) { attrs := []attribute.KeyValue{} diff --git a/telemetry/tracev2/span.go b/telemetry/tracev2/span.go index e0540fc..f2ea57d 100644 --- a/telemetry/tracev2/span.go +++ b/telemetry/tracev2/span.go @@ -2,6 +2,7 @@ package tracev2 type Span interface { Options() SpanOptions + SpanData() *SpanData AddMetadata(md map[string]string) Finish() String() string From 1b323600a604627dc0ec0a0c13a629d35ca2b01e Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 09:41:43 -0700 Subject: [PATCH 12/42] refactor: move buffer to utils for profit --- telemetry/buffer/buffer.go | 12 ---- telemetry/buffer/domain.go | 8 --- telemetry/buffer/memory/memory.go | 69 ------------------- telemetry/buffer/options.go | 29 -------- telemetry/log/memory/log.go | 13 ++-- telemetry/log/memory/log_test.go | 2 +- telemetry/trace/memory/trace.go | 13 ++-- telemetry/tracev2/memory/exporter.go | 6 +- telemetry/tracev2/memory/options.go | 8 +-- telemetry/tracev2/memory/trace.go | 8 +-- utils/memoryutils/memory_utils.go | 62 +++++++++++++++++ .../memoryutils/memory_utils.test.go | 7 +- 12 files changed, 89 insertions(+), 148 deletions(-) delete mode 100644 telemetry/buffer/buffer.go delete mode 100644 telemetry/buffer/domain.go delete mode 100644 telemetry/buffer/memory/memory.go delete mode 100644 telemetry/buffer/options.go create mode 100644 utils/memoryutils/memory_utils.go rename telemetry/buffer/memory/memory_test.go => utils/memoryutils/memory_utils.test.go (78%) diff --git a/telemetry/buffer/buffer.go b/telemetry/buffer/buffer.go deleted file mode 100644 index 2a7834f..0000000 --- a/telemetry/buffer/buffer.go +++ /dev/null @@ -1,12 +0,0 @@ -package buffer - -var ( - defaultSize = 1024 -) - -type Buffer interface { - Options() BufferOptions - Put(v interface{}) - Get(n int) []*Entry - String() string -} diff --git a/telemetry/buffer/domain.go b/telemetry/buffer/domain.go deleted file mode 100644 index 78ca85c..0000000 --- a/telemetry/buffer/domain.go +++ /dev/null @@ -1,8 +0,0 @@ -package buffer - -import "time" - -type Entry struct { - Value interface{} - Timestamp time.Time -} diff --git a/telemetry/buffer/memory/memory.go b/telemetry/buffer/memory/memory.go deleted file mode 100644 index 90b4ef3..0000000 --- a/telemetry/buffer/memory/memory.go +++ /dev/null @@ -1,69 +0,0 @@ -package memory - -import ( - "sync" - "time" - - "github.com/w-h-a/pkg/telemetry/buffer" -) - -type memoryBuffer struct { - options buffer.BufferOptions - mtx sync.RWMutex - entries []*buffer.Entry -} - -func (m *memoryBuffer) Options() buffer.BufferOptions { - return m.options -} - -func (m *memoryBuffer) Put(v interface{}) { - m.mtx.Lock() - defer m.mtx.Unlock() - - // make the entry - entry := &buffer.Entry{ - Value: v, - Timestamp: time.Now(), - } - - // append the entry - m.entries = append(m.entries, entry) - - // if the length of the entries is greater than the - // specified size, then trim down the buffer by 1 - if len(m.entries) > m.options.Size { - m.entries = m.entries[1:] - } -} - -func (m *memoryBuffer) Get(n int) []*buffer.Entry { - m.mtx.RLock() - defer m.mtx.RUnlock() - - // reset bad inputs - if n > len(m.entries) || n < 0 { - n = len(m.entries) - } - - // create a delta - delta := len(m.entries) - n - - return m.entries[delta:] -} - -func (m *memoryBuffer) String() string { - return "memory" -} - -func NewBuffer(opts ...buffer.BufferOption) buffer.Buffer { - options := buffer.NewBufferOptions(opts...) - - b := &memoryBuffer{ - options: options, - mtx: sync.RWMutex{}, - entries: []*buffer.Entry{}, - } - - return b -} diff --git a/telemetry/buffer/options.go b/telemetry/buffer/options.go deleted file mode 100644 index 74c2cb5..0000000 --- a/telemetry/buffer/options.go +++ /dev/null @@ -1,29 +0,0 @@ -package buffer - -import "context" - -type BufferOption func(o *BufferOptions) - -type BufferOptions struct { - Size int - Context context.Context -} - -func BufferWithSize(s int) BufferOption { - return func(o *BufferOptions) { - o.Size = s - } -} - -func NewBufferOptions(opts ...BufferOption) BufferOptions { - options := BufferOptions{ - Context: context.Background(), - Size: defaultSize, - } - - for _, fn := range opts { - fn(&options) - } - - return options -} diff --git a/telemetry/log/memory/log.go b/telemetry/log/memory/log.go index dcee4ec..d72d2d9 100644 --- a/telemetry/log/memory/log.go +++ b/telemetry/log/memory/log.go @@ -3,14 +3,13 @@ package memory import ( golog "log" - "github.com/w-h-a/pkg/telemetry/buffer" - "github.com/w-h-a/pkg/telemetry/buffer/memory" "github.com/w-h-a/pkg/telemetry/log" + "github.com/w-h-a/pkg/utils/memoryutils" ) type memoryLog struct { options log.LogOptions - buffer buffer.Buffer + buffer *memoryutils.Buffer } func (l *memoryLog) Options() log.LogOptions { @@ -30,12 +29,12 @@ func (l *memoryLog) Write(rec log.Record) error { func (l *memoryLog) Read(opts ...log.ReadOption) ([]log.Record, error) { options := log.NewReadOptions(opts...) - var entries []*buffer.Entry + var entries []*memoryutils.Entry if options.Count > 0 { entries = l.buffer.Get(options.Count) } else { - entries = l.buffer.Get(l.buffer.Options().Size) + entries = l.buffer.Get(l.buffer.Size) } records := []log.Record{} @@ -64,9 +63,9 @@ func NewLog(opts ...log.LogOption) log.Log { } if s, ok := GetSizeFromContext(options.Context); ok && s > 0 { - l.buffer = memory.NewBuffer(buffer.BufferWithSize(s)) + l.buffer = memoryutils.NewBuffer(s) } else { - l.buffer = memory.NewBuffer() + l.buffer = memoryutils.NewBuffer(1024) } return l diff --git a/telemetry/log/memory/log_test.go b/telemetry/log/memory/log_test.go index 299243e..3c608cf 100644 --- a/telemetry/log/memory/log_test.go +++ b/telemetry/log/memory/log_test.go @@ -14,7 +14,7 @@ func TestLogger(t *testing.T) { service := "service.namespace" logger := NewLog(log.LogWithPrefix(service), log.LogWithLevel(log.LevelDebug), LogWithSize(size)) - require.Equal(t, size, logger.(*memoryLog).buffer.Options().Size) + require.Equal(t, size, logger.(*memoryLog).buffer.Size) log.SetLogger(logger) diff --git a/telemetry/trace/memory/trace.go b/telemetry/trace/memory/trace.go index 3090584..6c4a0cf 100644 --- a/telemetry/trace/memory/trace.go +++ b/telemetry/trace/memory/trace.go @@ -5,14 +5,13 @@ import ( "time" "github.com/google/uuid" - "github.com/w-h-a/pkg/telemetry/buffer" - "github.com/w-h-a/pkg/telemetry/buffer/memory" "github.com/w-h-a/pkg/telemetry/trace" + "github.com/w-h-a/pkg/utils/memoryutils" ) type memoryTrace struct { options trace.TraceOptions - buffer buffer.Buffer + buffer *memoryutils.Buffer } func (t *memoryTrace) Options() trace.TraceOptions { @@ -61,12 +60,12 @@ func (t *memoryTrace) Finish(span *trace.Span) error { func (t *memoryTrace) Read(opts ...trace.ReadOption) ([]*trace.Span, error) { options := trace.NewReadOptions(opts...) - var entries []*buffer.Entry + var entries []*memoryutils.Entry if options.Count > 0 { entries = t.buffer.Get(options.Count) } else { - entries = t.buffer.Get(t.buffer.Options().Size) + entries = t.buffer.Get(t.buffer.Size) } spans := []*trace.Span{} @@ -96,9 +95,9 @@ func NewTrace(opts ...trace.TraceOption) trace.Trace { } if s, ok := GetSizeFromContext(options.Context); ok && s > 0 { - t.buffer = memory.NewBuffer(buffer.BufferWithSize(s)) + t.buffer = memoryutils.NewBuffer(s) } else { - t.buffer = memory.NewBuffer() + t.buffer = memoryutils.NewBuffer(1024) } return t diff --git a/telemetry/tracev2/memory/exporter.go b/telemetry/tracev2/memory/exporter.go index 7918b25..48bb407 100644 --- a/telemetry/tracev2/memory/exporter.go +++ b/telemetry/tracev2/memory/exporter.go @@ -3,15 +3,15 @@ package memory import ( "context" - "github.com/w-h-a/pkg/telemetry/buffer" "github.com/w-h-a/pkg/telemetry/tracev2" + "github.com/w-h-a/pkg/utils/memoryutils" "go.opentelemetry.io/otel/attribute" sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/trace" ) type memoryExporter struct { - buffer buffer.Buffer + buffer *memoryutils.Buffer } func (e *memoryExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error { @@ -58,6 +58,6 @@ func (e *memoryExporter) Shutdown(ctx context.Context) error { return nil } -func NewExporter(buffer buffer.Buffer) sdktrace.SpanExporter { +func NewExporter(buffer *memoryutils.Buffer) sdktrace.SpanExporter { return &memoryExporter{buffer} } diff --git a/telemetry/tracev2/memory/options.go b/telemetry/tracev2/memory/options.go index 7878b79..c2ab267 100644 --- a/telemetry/tracev2/memory/options.go +++ b/telemetry/tracev2/memory/options.go @@ -3,21 +3,21 @@ package memory import ( "context" - "github.com/w-h-a/pkg/telemetry/buffer" "github.com/w-h-a/pkg/telemetry/tracev2" + "github.com/w-h-a/pkg/utils/memoryutils" "go.opentelemetry.io/otel/trace" ) type bufferKey struct{} -func TraceWithBuffer(b buffer.Buffer) tracev2.TraceOption { +func TraceWithBuffer(b *memoryutils.Buffer) tracev2.TraceOption { return func(o *tracev2.TraceOptions) { o.Context = context.WithValue(o.Context, b, bufferKey{}) } } -func GetBufferFromContext(ctx context.Context) (buffer.Buffer, bool) { - b, ok := ctx.Value(bufferKey{}).(buffer.Buffer) +func GetBufferFromContext(ctx context.Context) (*memoryutils.Buffer, bool) { + b, ok := ctx.Value(bufferKey{}).(*memoryutils.Buffer) return b, ok } diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index dc9be2a..7368865 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -3,9 +3,9 @@ package memory import ( "context" - "github.com/w-h-a/pkg/telemetry/buffer" "github.com/w-h-a/pkg/telemetry/log" "github.com/w-h-a/pkg/telemetry/tracev2" + "github.com/w-h-a/pkg/utils/memoryutils" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" ) @@ -13,7 +13,7 @@ import ( type memoryTrace struct { options tracev2.TraceOptions tracer trace.Tracer - buffer buffer.Buffer + buffer *memoryutils.Buffer } func (t *memoryTrace) Options() tracev2.TraceOptions { @@ -65,12 +65,12 @@ func (t *memoryTrace) Finish(span tracev2.Span) { func (t *memoryTrace) Read(opts ...tracev2.ReadOption) ([]*tracev2.SpanData, error) { options := tracev2.NewReadOptions(opts...) - var entries []*buffer.Entry + var entries []*memoryutils.Entry if options.Count > 0 { entries = t.buffer.Get(options.Count) } else { - entries = t.buffer.Get(t.buffer.Options().Size) + entries = t.buffer.Get(t.buffer.Size) } spans := []*tracev2.SpanData{} diff --git a/utils/memoryutils/memory_utils.go b/utils/memoryutils/memory_utils.go new file mode 100644 index 0000000..74feb76 --- /dev/null +++ b/utils/memoryutils/memory_utils.go @@ -0,0 +1,62 @@ +package memoryutils + +import ( + "sync" + "time" +) + +type Buffer struct { + Size int + mtx sync.RWMutex + entries []*Entry +} + +type Entry struct { + Value interface{} + Timestamp time.Time +} + +func (m *Buffer) Put(v interface{}) { + m.mtx.Lock() + defer m.mtx.Unlock() + + // make the entry + entry := &Entry{ + Value: v, + Timestamp: time.Now(), + } + + // append the entry + m.entries = append(m.entries, entry) + + // if the length of the entries is greater than the + // specified size, then trim down the buffer by 1 + if len(m.entries) > m.Size { + m.entries = m.entries[1:] + } +} + +func (m *Buffer) Get(n int) []*Entry { + m.mtx.RLock() + defer m.mtx.RUnlock() + + // reset bad inputs + if n > len(m.entries) || n < 0 { + n = len(m.entries) + } + + // create a delta + delta := len(m.entries) - n + + return m.entries[delta:] +} + +func NewBuffer(size int) *Buffer { + b := &Buffer{ + Size: size, + mtx: sync.RWMutex{}, + entries: []*Entry{}, + } + + return b +} diff --git a/telemetry/buffer/memory/memory_test.go b/utils/memoryutils/memory_utils.test.go similarity index 78% rename from telemetry/buffer/memory/memory_test.go rename to utils/memoryutils/memory_utils.test.go index 9d6c3c0..3edbe09 100644 --- a/telemetry/buffer/memory/memory_test.go +++ b/utils/memoryutils/memory_utils.test.go @@ -1,14 +1,13 @@ -package memory +package memoryutils import ( "testing" "github.com/stretchr/testify/require" - "github.com/w-h-a/pkg/telemetry/buffer" ) func TestMemoryBuffer(t *testing.T) { - b := NewBuffer(buffer.BufferWithSize(10)) + b := NewBuffer(10) b.Put("foo") @@ -17,7 +16,7 @@ func TestMemoryBuffer(t *testing.T) { val := entries[0].Value.(string) require.Equal(t, "foo", val) - b = NewBuffer(buffer.BufferWithSize(10)) + b = NewBuffer(10) for i := 0; i < 10; i++ { b.Put(i) From 5f36a7d9993c7e60ed181e6e9cdf0c854ee4be67 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 13:38:04 -0700 Subject: [PATCH 13/42] chore: debug --- telemetry/tracev2/memory/trace.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index 7368865..90143b7 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -113,7 +113,13 @@ func NewTrace(opts ...tracev2.TraceOption) tracev2.Trace { tracer: otel.Tracer(options.Name), } - if b, ok := GetBufferFromContext(options.Context); ok && b != nil { + b, ok := GetBufferFromContext(options.Context) + + log.Infof("MY CTX %+#v", options.Context) + + log.Infof("MY buffer %+#v", b) + + if ok && b != nil { t.buffer = b } else { log.Fatalf("no buffer was given") From 6248be49a994fe2921426fad3e4ed9ad900e7428 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 14:06:42 -0700 Subject: [PATCH 14/42] fix: bugs --- sidecar/custom/sidecar.go | 15 ++--- telemetry/tracev2/memory/options.go | 16 +----- telemetry/tracev2/memory/span.go | 58 ------------------- telemetry/tracev2/memory/trace.go | 87 +++++++++++++++-------------- telemetry/tracev2/options.go | 25 --------- telemetry/tracev2/span.go | 9 --- telemetry/tracev2/trace.go | 11 +--- telemetry/tracev2/utils.go | 36 ------------ 8 files changed, 55 insertions(+), 202 deletions(-) delete mode 100644 telemetry/tracev2/memory/span.go delete mode 100644 telemetry/tracev2/span.go delete mode 100644 telemetry/tracev2/utils.go diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index bba7092..74431a6 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -13,7 +13,6 @@ import ( "github.com/w-h-a/pkg/sidecar" "github.com/w-h-a/pkg/store" "github.com/w-h-a/pkg/telemetry/log" - "github.com/w-h-a/pkg/telemetry/tracev2" "github.com/w-h-a/pkg/utils/datautils" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -185,13 +184,9 @@ func (s *customSidecar) UnsubscribeFromBroker(brokerId string) error { func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*sidecar.Secret, error) { // TODO: make sure we have a tracer - _, span, err := s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") - if err != nil { - log.Errorf("failed to start span: %v", err) - return nil, tracev2.ErrStart - } + _ = s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") - s.options.Tracer.AddMetadata(span, map[string]string{ + s.options.Tracer.AddMetadata(map[string]string{ "secretStore": secretStore, "name": name, }) @@ -200,20 +195,20 @@ func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore str if !ok { log.Warnf("secret store %s was not found", secretStore) // TODO: update status of span - s.options.Tracer.Finish(span) + s.options.Tracer.Finish() return nil, sidecar.ErrComponentNotFound } mp, err := sc.GetSecret(name) if err != nil { // TODO: update status of span - s.options.Tracer.Finish(span) + s.options.Tracer.Finish() return nil, err } // TODO: update status of span - s.options.Tracer.Finish(span) + s.options.Tracer.Finish() return &sidecar.Secret{ Data: mp, diff --git a/telemetry/tracev2/memory/options.go b/telemetry/tracev2/memory/options.go index c2ab267..bef14ca 100644 --- a/telemetry/tracev2/memory/options.go +++ b/telemetry/tracev2/memory/options.go @@ -5,14 +5,13 @@ import ( "github.com/w-h-a/pkg/telemetry/tracev2" "github.com/w-h-a/pkg/utils/memoryutils" - "go.opentelemetry.io/otel/trace" ) type bufferKey struct{} func TraceWithBuffer(b *memoryutils.Buffer) tracev2.TraceOption { return func(o *tracev2.TraceOptions) { - o.Context = context.WithValue(o.Context, b, bufferKey{}) + o.Context = context.WithValue(o.Context, bufferKey{}, b) } } @@ -20,16 +19,3 @@ func GetBufferFromContext(ctx context.Context) (*memoryutils.Buffer, bool) { b, ok := ctx.Value(bufferKey{}).(*memoryutils.Buffer) return b, ok } - -type spanKey struct{} - -func SpanWithSpan(s trace.Span) tracev2.SpanOption { - return func(o *tracev2.SpanOptions) { - o.Context = context.WithValue(o.Context, s, spanKey{}) - } -} - -func GetSpanFromContext(ctx context.Context) (trace.Span, bool) { - s, ok := ctx.Value(spanKey{}).(trace.Span) - return s, ok -} diff --git a/telemetry/tracev2/memory/span.go b/telemetry/tracev2/memory/span.go deleted file mode 100644 index fee2895..0000000 --- a/telemetry/tracev2/memory/span.go +++ /dev/null @@ -1,58 +0,0 @@ -package memory - -import ( - "github.com/w-h-a/pkg/telemetry/tracev2" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" -) - -type memorySpan struct { - options tracev2.SpanOptions - span trace.Span -} - -func (s *memorySpan) Options() tracev2.SpanOptions { - return s.options -} - -func (s *memorySpan) SpanData() *tracev2.SpanData { - return &tracev2.SpanData{ - Name: s.options.Name, - Id: s.span.SpanContext().SpanID().String(), - Trace: s.span.SpanContext().TraceID().String(), - } -} - -func (s *memorySpan) AddMetadata(md map[string]string) { - attrs := []attribute.KeyValue{} - - for k, v := range md { - attrs = append(attrs, attribute.String(k, v)) - } - - if len(attrs) > 0 { - s.span.SetAttributes(attrs...) - } -} - -func (s *memorySpan) Finish() { - s.span.End() -} - -func (s *memorySpan) String() string { - return "memory" -} - -func NewSpan(opts ...tracev2.SpanOption) tracev2.Span { - options := tracev2.NewSpanOptions(opts...) - - s := &memorySpan{ - options: options, - } - - if span, ok := GetSpanFromContext(options.Context); ok { - s.span = span - } - - return s -} diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index 90143b7..a9b5f30 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -2,64 +2,83 @@ package memory import ( "context" + "sync" "github.com/w-h-a/pkg/telemetry/log" "github.com/w-h-a/pkg/telemetry/tracev2" "github.com/w-h-a/pkg/utils/memoryutils" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) type memoryTrace struct { options tracev2.TraceOptions tracer trace.Tracer + span trace.Span buffer *memoryutils.Buffer + mtx sync.RWMutex } func (t *memoryTrace) Options() tracev2.TraceOptions { return t.options } -func (t *memoryTrace) Start(ctx context.Context, name string) (context.Context, tracev2.Span, error) { +func (t *memoryTrace) Start(ctx context.Context, name string) context.Context { // TODO: make sure we're enabled + t.mtx.Lock() + defer t.mtx.Unlock() + parentCtxCfg := trace.SpanContextConfig{} - parentData, err := tracev2.SpanDataFromContext(ctx) - if err != nil { - newCtx, memorySpan := t.start(ctx, name, parentCtxCfg) - return newCtx, memorySpan, err + if t.span == nil { + newCtx, span := t.start(ctx, name, parentCtxCfg) + t.span = span + return newCtx } - parentCtxCfg.TraceID, err = trace.TraceIDFromHex(parentData.Trace) - if err != nil { - newCtx, memorySpan := t.start(ctx, name, parentCtxCfg) - return newCtx, memorySpan, err - } + parentCtxCfg.TraceID = t.span.SpanContext().TraceID() - parentCtxCfg.SpanID, err = trace.SpanIDFromHex(parentData.Id) - if err != nil { - newCtx, memorySpan := t.start(ctx, name, parentCtxCfg) - return newCtx, memorySpan, err - } + parentCtxCfg.SpanID = t.span.SpanContext().SpanID() - newCtx, memorySpan := t.start(ctx, name, parentCtxCfg) + newCtx, span := t.start(ctx, name, parentCtxCfg) - return newCtx, memorySpan, nil + t.span = span + + return newCtx } -func (t *memoryTrace) AddMetadata(span tracev2.Span, md map[string]string) { - if span == nil { +func (t *memoryTrace) AddMetadata(md map[string]string) { + t.mtx.Lock() + defer t.mtx.Unlock() + + if t.span == nil { return } - if len(md) > 0 { - span.AddMetadata(md) + if len(md) == 0 { + return } + + attrs := []attribute.KeyValue{} + + for k, v := range md { + attrs = append(attrs, attribute.String(k, v)) + } + + if len(attrs) == 0 { + return + } + + t.span.SetAttributes(attrs...) } -func (t *memoryTrace) Finish(span tracev2.Span) { - span.Finish() +func (t *memoryTrace) Finish() { + t.mtx.Lock() + defer t.mtx.Unlock() + + t.span.End() } func (t *memoryTrace) Read(opts ...tracev2.ReadOption) ([]*tracev2.SpanData, error) { @@ -88,21 +107,12 @@ func (t *memoryTrace) String() string { return "memory" } -func (t *memoryTrace) start(ctx context.Context, name string, parentCtxCfg trace.SpanContextConfig) (context.Context, tracev2.Span) { +func (t *memoryTrace) start(ctx context.Context, name string, parentCtxCfg trace.SpanContextConfig) (context.Context, trace.Span) { parentSpanCtx := trace.NewSpanContext(parentCtxCfg) ctx = trace.ContextWithRemoteSpanContext(ctx, parentSpanCtx) - newCtx, span := t.tracer.Start(ctx, name) - - opts := []tracev2.SpanOption{ - tracev2.SpanWithName(name), - SpanWithSpan(span), - } - - memorySpan := NewSpan(opts...) - - return newCtx, memorySpan + return t.tracer.Start(ctx, name) } func NewTrace(opts ...tracev2.TraceOption) tracev2.Trace { @@ -111,15 +121,10 @@ func NewTrace(opts ...tracev2.TraceOption) tracev2.Trace { t := &memoryTrace{ options: options, tracer: otel.Tracer(options.Name), + mtx: sync.RWMutex{}, } - b, ok := GetBufferFromContext(options.Context) - - log.Infof("MY CTX %+#v", options.Context) - - log.Infof("MY buffer %+#v", b) - - if ok && b != nil { + if b, ok := GetBufferFromContext(options.Context); ok && b != nil { t.buffer = b } else { log.Fatalf("no buffer was given") diff --git a/telemetry/tracev2/options.go b/telemetry/tracev2/options.go index 867c23d..871de5f 100644 --- a/telemetry/tracev2/options.go +++ b/telemetry/tracev2/options.go @@ -27,31 +27,6 @@ func NewTraceOptions(opts ...TraceOption) TraceOptions { return options } -type SpanOption func(o *SpanOptions) - -type SpanOptions struct { - Name string - Context context.Context -} - -func SpanWithName(name string) SpanOption { - return func(o *SpanOptions) { - o.Name = name - } -} - -func NewSpanOptions(opts ...SpanOption) SpanOptions { - options := SpanOptions{ - Context: context.Background(), - } - - for _, fn := range opts { - fn(&options) - } - - return options -} - type ReadOption func(o *ReadOptions) type ReadOptions struct { diff --git a/telemetry/tracev2/span.go b/telemetry/tracev2/span.go deleted file mode 100644 index f2ea57d..0000000 --- a/telemetry/tracev2/span.go +++ /dev/null @@ -1,9 +0,0 @@ -package tracev2 - -type Span interface { - Options() SpanOptions - SpanData() *SpanData - AddMetadata(md map[string]string) - Finish() - String() string -} diff --git a/telemetry/tracev2/trace.go b/telemetry/tracev2/trace.go index 60e3082..8e54e7b 100644 --- a/telemetry/tracev2/trace.go +++ b/telemetry/tracev2/trace.go @@ -2,20 +2,15 @@ package tracev2 import ( "context" - "errors" -) - -var ( - ErrStart = errors.New("failed to start span") ) // TODO: status type Trace interface { Options() TraceOptions // TODO: add cfg argument to check for whether tracing is enabled - Start(ctx context.Context, name string) (context.Context, Span, error) - AddMetadata(span Span, md map[string]string) - Finish(span Span) + Start(ctx context.Context, name string) context.Context + AddMetadata(md map[string]string) + Finish() Read(opts ...ReadOption) ([]*SpanData, error) String() string } diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go deleted file mode 100644 index efc4010..0000000 --- a/telemetry/tracev2/utils.go +++ /dev/null @@ -1,36 +0,0 @@ -package tracev2 - -import ( - "context" - "encoding/json" - - "github.com/w-h-a/pkg/utils/metadatautils" -) - -const ( - spanDataKey = "trace-spanData" -) - -func ContextWithSpanData(ctx context.Context, spanData *SpanData) (context.Context, error) { - bytes, err := json.Marshal(spanData) - if err != nil { - return ctx, err - } - - return metadatautils.SetContext(ctx, spanDataKey, string(bytes)), nil -} - -func SpanDataFromContext(ctx context.Context) (*SpanData, error) { - str, ok := metadatautils.GetContext(ctx, spanDataKey) - if !ok { - return nil, nil - } - - s := &SpanData{} - - if err := json.Unmarshal([]byte(str), s); err != nil { - return nil, err - } - - return s, nil -} From 269158b25c5c6a0581705d66ddf622f27ac4e6c5 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 14:46:17 -0700 Subject: [PATCH 15/42] feat: add some traceparent utils --- telemetry/tracev2/memory/trace.go | 6 ++++++ telemetry/tracev2/utils.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 telemetry/tracev2/utils.go diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index a9b5f30..fecd14b 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -33,8 +33,14 @@ func (t *memoryTrace) Start(ctx context.Context, name string) context.Context { parentCtxCfg := trace.SpanContextConfig{} if t.span == nil { + if traceparent, ok := tracev2.TraceParentFromContext(ctx); ok { + parentCtxCfg.TraceID = traceparent + } + newCtx, span := t.start(ctx, name, parentCtxCfg) + t.span = span + return newCtx } diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go new file mode 100644 index 0000000..67b2e85 --- /dev/null +++ b/telemetry/tracev2/utils.go @@ -0,0 +1,28 @@ +package tracev2 + +import ( + "context" + + "github.com/w-h-a/pkg/utils/metadatautils" +) + +const ( + traceParentKey = "traceparent" +) + +func ContextWithTraceParent(ctx context.Context, traceparent [16]byte) (context.Context, error) { + return metadatautils.MergeContext(ctx, map[string]string{ + traceParentKey: string(traceparent[:]), + }, true), nil +} + +func TraceParentFromContext(ctx context.Context) (traceparent [16]byte, found bool) { + traceId, ok := metadatautils.GetContext(ctx, traceParentKey) + if !ok { + return + } + + copy(traceparent[:], traceId) + + return +} From 730fac5b83bdc6f62b861451b484d44576832ef8 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 14:52:51 -0700 Subject: [PATCH 16/42] chore: debug --- telemetry/tracev2/memory/trace.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index fecd14b..cd538f9 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -33,9 +33,11 @@ func (t *memoryTrace) Start(ctx context.Context, name string) context.Context { parentCtxCfg := trace.SpanContextConfig{} if t.span == nil { + log.Infof("HERE IS MY ctx %+#v", ctx) if traceparent, ok := tracev2.TraceParentFromContext(ctx); ok { parentCtxCfg.TraceID = traceparent } + log.Infof("HERE IS MY CFG %+#v", parentCtxCfg) newCtx, span := t.start(ctx, name, parentCtxCfg) From f661a375bb58668ca15f73d92c9484476e7609be Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 15:01:34 -0700 Subject: [PATCH 17/42] chore: debug --- telemetry/tracev2/utils.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go index 67b2e85..38a15c3 100644 --- a/telemetry/tracev2/utils.go +++ b/telemetry/tracev2/utils.go @@ -3,6 +3,7 @@ package tracev2 import ( "context" + "github.com/w-h-a/pkg/telemetry/log" "github.com/w-h-a/pkg/utils/metadatautils" ) @@ -22,7 +23,11 @@ func TraceParentFromContext(ctx context.Context) (traceparent [16]byte, found bo return } + log.Infof("TRACE ID", traceId) + copy(traceparent[:], traceId) + log.Infof("TRACE PARENT %+#v", traceparent) + return } From d2e14d97f244cbe7583eeba2645cb06d468bc365 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 15:09:14 -0700 Subject: [PATCH 18/42] chore: debug --- telemetry/tracev2/memory/trace.go | 2 -- telemetry/tracev2/utils.go | 9 ++------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index cd538f9..fecd14b 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -33,11 +33,9 @@ func (t *memoryTrace) Start(ctx context.Context, name string) context.Context { parentCtxCfg := trace.SpanContextConfig{} if t.span == nil { - log.Infof("HERE IS MY ctx %+#v", ctx) if traceparent, ok := tracev2.TraceParentFromContext(ctx); ok { parentCtxCfg.TraceID = traceparent } - log.Infof("HERE IS MY CFG %+#v", parentCtxCfg) newCtx, span := t.start(ctx, name, parentCtxCfg) diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go index 38a15c3..765db79 100644 --- a/telemetry/tracev2/utils.go +++ b/telemetry/tracev2/utils.go @@ -3,7 +3,6 @@ package tracev2 import ( "context" - "github.com/w-h-a/pkg/telemetry/log" "github.com/w-h-a/pkg/utils/metadatautils" ) @@ -18,16 +17,12 @@ func ContextWithTraceParent(ctx context.Context, traceparent [16]byte) (context. } func TraceParentFromContext(ctx context.Context) (traceparent [16]byte, found bool) { - traceId, ok := metadatautils.GetContext(ctx, traceParentKey) - if !ok { + traceId, found := metadatautils.GetContext(ctx, traceParentKey) + if !found { return } - log.Infof("TRACE ID", traceId) - copy(traceparent[:], traceId) - log.Infof("TRACE PARENT %+#v", traceparent) - return } From 028bc24e613b08985c67e8024b1407d24edbb198 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 15:43:24 -0700 Subject: [PATCH 19/42] refactor: trace interface again --- sidecar/custom/sidecar.go | 10 +++--- telemetry/tracev2/memory/trace.go | 51 +++++++++++++++++++------------ telemetry/tracev2/trace.go | 4 +-- telemetry/tracev2/utils.go | 36 ++++++++++++++++++++++ 4 files changed, 74 insertions(+), 27 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 74431a6..af0571e 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -184,9 +184,9 @@ func (s *customSidecar) UnsubscribeFromBroker(brokerId string) error { func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*sidecar.Secret, error) { // TODO: make sure we have a tracer - _ = s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") + newCtx := s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") - s.options.Tracer.AddMetadata(map[string]string{ + s.options.Tracer.AddMetadata(newCtx, map[string]string{ "secretStore": secretStore, "name": name, }) @@ -195,20 +195,20 @@ func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore str if !ok { log.Warnf("secret store %s was not found", secretStore) // TODO: update status of span - s.options.Tracer.Finish() + s.options.Tracer.Finish(newCtx) return nil, sidecar.ErrComponentNotFound } mp, err := sc.GetSecret(name) if err != nil { // TODO: update status of span - s.options.Tracer.Finish() + s.options.Tracer.Finish(newCtx) return nil, err } // TODO: update status of span - s.options.Tracer.Finish() + s.options.Tracer.Finish(newCtx) return &sidecar.Secret{ Data: mp, diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index fecd14b..a8e6073 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -15,7 +15,7 @@ import ( type memoryTrace struct { options tracev2.TraceOptions tracer trace.Tracer - span trace.Span + spans map[string]trace.Span buffer *memoryutils.Buffer mtx sync.RWMutex } @@ -32,34 +32,35 @@ func (t *memoryTrace) Start(ctx context.Context, name string) context.Context { parentCtxCfg := trace.SpanContextConfig{} - if t.span == nil { - if traceparent, ok := tracev2.TraceParentFromContext(ctx); ok { - parentCtxCfg.TraceID = traceparent - } - - newCtx, span := t.start(ctx, name, parentCtxCfg) - - t.span = span - - return newCtx + if spanparent, ok := tracev2.SpanParentFromContext(ctx); ok { + parentCtxCfg.SpanID = spanparent } - parentCtxCfg.TraceID = t.span.SpanContext().TraceID() + if traceparent, ok := tracev2.TraceParentFromContext(ctx); ok { + parentCtxCfg.TraceID = traceparent + } - parentCtxCfg.SpanID = t.span.SpanContext().SpanID() + ctx, span := t.start(ctx, name, parentCtxCfg) - newCtx, span := t.start(ctx, name, parentCtxCfg) + t.spans[span.SpanContext().SpanID().String()] = span - t.span = span + newCtx, _ := tracev2.ContextWithSpan(ctx, span.SpanContext().SpanID()) return newCtx } -func (t *memoryTrace) AddMetadata(md map[string]string) { +func (t *memoryTrace) AddMetadata(ctx context.Context, md map[string]string) { t.mtx.Lock() defer t.mtx.Unlock() - if t.span == nil { + span, found := tracev2.SpanFromContext(ctx) + if !found { + return + } + + key := string(span[:]) + + if t.spans[key] == nil { return } @@ -77,14 +78,23 @@ func (t *memoryTrace) AddMetadata(md map[string]string) { return } - t.span.SetAttributes(attrs...) + t.spans[key].SetAttributes(attrs...) } -func (t *memoryTrace) Finish() { +func (t *memoryTrace) Finish(ctx context.Context) { t.mtx.Lock() defer t.mtx.Unlock() - t.span.End() + span, found := tracev2.SpanFromContext(ctx) + if !found { + return + } + + key := string(span[:]) + + t.spans[key].End() + + delete(t.spans, key) } func (t *memoryTrace) Read(opts ...tracev2.ReadOption) ([]*tracev2.SpanData, error) { @@ -127,6 +137,7 @@ func NewTrace(opts ...tracev2.TraceOption) tracev2.Trace { t := &memoryTrace{ options: options, tracer: otel.Tracer(options.Name), + spans: map[string]trace.Span{}, mtx: sync.RWMutex{}, } diff --git a/telemetry/tracev2/trace.go b/telemetry/tracev2/trace.go index 8e54e7b..8a3b951 100644 --- a/telemetry/tracev2/trace.go +++ b/telemetry/tracev2/trace.go @@ -9,8 +9,8 @@ type Trace interface { Options() TraceOptions // TODO: add cfg argument to check for whether tracing is enabled Start(ctx context.Context, name string) context.Context - AddMetadata(md map[string]string) - Finish() + AddMetadata(ctx context.Context, md map[string]string) + Finish(ctx context.Context) Read(opts ...ReadOption) ([]*SpanData, error) String() string } diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go index 765db79..94a8926 100644 --- a/telemetry/tracev2/utils.go +++ b/telemetry/tracev2/utils.go @@ -8,6 +8,8 @@ import ( const ( traceParentKey = "traceparent" + spanParentKey = "spanparent" + spanKey = "span" ) func ContextWithTraceParent(ctx context.Context, traceparent [16]byte) (context.Context, error) { @@ -26,3 +28,37 @@ func TraceParentFromContext(ctx context.Context) (traceparent [16]byte, found bo return } + +func ContextWithSpanParent(ctx context.Context, spanparent [8]byte) (context.Context, error) { + return metadatautils.MergeContext(ctx, map[string]string{ + spanParentKey: string(spanparent[:]), + }, true), nil +} + +func SpanParentFromContext(ctx context.Context) (spanparent [8]byte, found bool) { + spanId, found := metadatautils.GetContext(ctx, spanParentKey) + if !found { + return + } + + copy(spanparent[:], spanId) + + return +} + +func ContextWithSpan(ctx context.Context, span [8]byte) (context.Context, error) { + return metadatautils.MergeContext(ctx, map[string]string{ + spanKey: string(span[:]), + }, true), nil +} + +func SpanFromContext(ctx context.Context) (span [8]byte, found bool) { + spanId, found := metadatautils.GetContext(ctx, spanKey) + if !found { + return + } + + copy(span[:], spanId) + + return +} From e7314665f22841b199179e55104703c1b570b537 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 16:46:17 -0700 Subject: [PATCH 20/42] chore: debug --- telemetry/tracev2/memory/trace.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index a8e6073..278ea03 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -46,6 +46,8 @@ func (t *memoryTrace) Start(ctx context.Context, name string) context.Context { newCtx, _ := tracev2.ContextWithSpan(ctx, span.SpanContext().SpanID()) + log.Infof("MY CTX %+#v", newCtx) + return newCtx } From 165437dee521c4188194ac599c5252671afbcffb Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 16:53:22 -0700 Subject: [PATCH 21/42] refactor: trace interface again --- sidecar/custom/sidecar.go | 10 ++++----- telemetry/tracev2/memory/trace.go | 36 ++++++++++--------------------- telemetry/tracev2/trace.go | 6 +++--- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index af0571e..c6aec68 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -184,9 +184,9 @@ func (s *customSidecar) UnsubscribeFromBroker(brokerId string) error { func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*sidecar.Secret, error) { // TODO: make sure we have a tracer - newCtx := s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") + _, spanId := s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") - s.options.Tracer.AddMetadata(newCtx, map[string]string{ + s.options.Tracer.AddMetadata(spanId, map[string]string{ "secretStore": secretStore, "name": name, }) @@ -195,20 +195,20 @@ func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore str if !ok { log.Warnf("secret store %s was not found", secretStore) // TODO: update status of span - s.options.Tracer.Finish(newCtx) + s.options.Tracer.Finish(spanId) return nil, sidecar.ErrComponentNotFound } mp, err := sc.GetSecret(name) if err != nil { // TODO: update status of span - s.options.Tracer.Finish(newCtx) + s.options.Tracer.Finish(spanId) return nil, err } // TODO: update status of span - s.options.Tracer.Finish(newCtx) + s.options.Tracer.Finish(spanId) return &sidecar.Secret{ Data: mp, diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index 278ea03..99f9063 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -24,7 +24,7 @@ func (t *memoryTrace) Options() tracev2.TraceOptions { return t.options } -func (t *memoryTrace) Start(ctx context.Context, name string) context.Context { +func (t *memoryTrace) Start(ctx context.Context, name string) (context.Context, string) { // TODO: make sure we're enabled t.mtx.Lock() @@ -42,27 +42,20 @@ func (t *memoryTrace) Start(ctx context.Context, name string) context.Context { ctx, span := t.start(ctx, name, parentCtxCfg) - t.spans[span.SpanContext().SpanID().String()] = span + key := span.SpanContext().SpanID().String() - newCtx, _ := tracev2.ContextWithSpan(ctx, span.SpanContext().SpanID()) + t.spans[key] = span - log.Infof("MY CTX %+#v", newCtx) + newCtx, _ := tracev2.ContextWithSpan(ctx, span.SpanContext().SpanID()) - return newCtx + return newCtx, key } -func (t *memoryTrace) AddMetadata(ctx context.Context, md map[string]string) { +func (t *memoryTrace) AddMetadata(span string, md map[string]string) { t.mtx.Lock() defer t.mtx.Unlock() - span, found := tracev2.SpanFromContext(ctx) - if !found { - return - } - - key := string(span[:]) - - if t.spans[key] == nil { + if t.spans[span] == nil { return } @@ -80,23 +73,16 @@ func (t *memoryTrace) AddMetadata(ctx context.Context, md map[string]string) { return } - t.spans[key].SetAttributes(attrs...) + t.spans[span].SetAttributes(attrs...) } -func (t *memoryTrace) Finish(ctx context.Context) { +func (t *memoryTrace) Finish(span string) { t.mtx.Lock() defer t.mtx.Unlock() - span, found := tracev2.SpanFromContext(ctx) - if !found { - return - } - - key := string(span[:]) - - t.spans[key].End() + t.spans[span].End() - delete(t.spans, key) + delete(t.spans, span) } func (t *memoryTrace) Read(opts ...tracev2.ReadOption) ([]*tracev2.SpanData, error) { diff --git a/telemetry/tracev2/trace.go b/telemetry/tracev2/trace.go index 8a3b951..f3a7d3c 100644 --- a/telemetry/tracev2/trace.go +++ b/telemetry/tracev2/trace.go @@ -8,9 +8,9 @@ import ( type Trace interface { Options() TraceOptions // TODO: add cfg argument to check for whether tracing is enabled - Start(ctx context.Context, name string) context.Context - AddMetadata(ctx context.Context, md map[string]string) - Finish(ctx context.Context) + Start(ctx context.Context, name string) (context.Context, string) + AddMetadata(span string, md map[string]string) + Finish(span string) Read(opts ...ReadOption) ([]*SpanData, error) String() string } From d905c1bfa3734d292c03a2e46c200f4e1faaf73a Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 17:01:13 -0700 Subject: [PATCH 22/42] fix: make sure to set span parent --- telemetry/tracev2/memory/trace.go | 2 +- telemetry/tracev2/utils.go | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index 99f9063..e3ff723 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -46,7 +46,7 @@ func (t *memoryTrace) Start(ctx context.Context, name string) (context.Context, t.spans[key] = span - newCtx, _ := tracev2.ContextWithSpan(ctx, span.SpanContext().SpanID()) + newCtx, _ := tracev2.ContextWithSpanParent(ctx, span.SpanContext().SpanID()) return newCtx, key } diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go index 94a8926..6eeee99 100644 --- a/telemetry/tracev2/utils.go +++ b/telemetry/tracev2/utils.go @@ -45,20 +45,3 @@ func SpanParentFromContext(ctx context.Context) (spanparent [8]byte, found bool) return } - -func ContextWithSpan(ctx context.Context, span [8]byte) (context.Context, error) { - return metadatautils.MergeContext(ctx, map[string]string{ - spanKey: string(span[:]), - }, true), nil -} - -func SpanFromContext(ctx context.Context) (span [8]byte, found bool) { - spanId, found := metadatautils.GetContext(ctx, spanKey) - if !found { - return - } - - copy(span[:], spanId) - - return -} From 8b33a00ebe6e19e35d624adf7b1f697f1d22ef53 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 17:29:30 -0700 Subject: [PATCH 23/42] refactor: make buffer prettier --- telemetry/log/memory/log.go | 6 +++--- telemetry/log/memory/log_test.go | 2 +- telemetry/trace/memory/trace.go | 6 +++--- telemetry/tracev2/memory/trace.go | 2 +- telemetry/tracev2/utils.go | 1 - utils/memoryutils/memory_utils.go | 18 ++++++++++++++---- utils/memoryutils/memory_utils.test.go | 4 ++-- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/telemetry/log/memory/log.go b/telemetry/log/memory/log.go index d72d2d9..14938e5 100644 --- a/telemetry/log/memory/log.go +++ b/telemetry/log/memory/log.go @@ -34,7 +34,7 @@ func (l *memoryLog) Read(opts ...log.ReadOption) ([]log.Record, error) { if options.Count > 0 { entries = l.buffer.Get(options.Count) } else { - entries = l.buffer.Get(l.buffer.Size) + entries = l.buffer.Get(l.buffer.Options().Size) } records := []log.Record{} @@ -63,9 +63,9 @@ func NewLog(opts ...log.LogOption) log.Log { } if s, ok := GetSizeFromContext(options.Context); ok && s > 0 { - l.buffer = memoryutils.NewBuffer(s) + l.buffer = memoryutils.NewBuffer(memoryutils.BufferWithSize(s)) } else { - l.buffer = memoryutils.NewBuffer(1024) + l.buffer = memoryutils.NewBuffer() } return l diff --git a/telemetry/log/memory/log_test.go b/telemetry/log/memory/log_test.go index 3c608cf..299243e 100644 --- a/telemetry/log/memory/log_test.go +++ b/telemetry/log/memory/log_test.go @@ -14,7 +14,7 @@ func TestLogger(t *testing.T) { service := "service.namespace" logger := NewLog(log.LogWithPrefix(service), log.LogWithLevel(log.LevelDebug), LogWithSize(size)) - require.Equal(t, size, logger.(*memoryLog).buffer.Size) + require.Equal(t, size, logger.(*memoryLog).buffer.Options().Size) log.SetLogger(logger) diff --git a/telemetry/trace/memory/trace.go b/telemetry/trace/memory/trace.go index 6c4a0cf..d853a7d 100644 --- a/telemetry/trace/memory/trace.go +++ b/telemetry/trace/memory/trace.go @@ -65,7 +65,7 @@ func (t *memoryTrace) Read(opts ...trace.ReadOption) ([]*trace.Span, error) { if options.Count > 0 { entries = t.buffer.Get(options.Count) } else { - entries = t.buffer.Get(t.buffer.Size) + entries = t.buffer.Get(t.buffer.Options().Size) } spans := []*trace.Span{} @@ -95,9 +95,9 @@ func NewTrace(opts ...trace.TraceOption) trace.Trace { } if s, ok := GetSizeFromContext(options.Context); ok && s > 0 { - t.buffer = memoryutils.NewBuffer(s) + t.buffer = memoryutils.NewBuffer(memoryutils.BufferWithSize(s)) } else { - t.buffer = memoryutils.NewBuffer(1024) + t.buffer = memoryutils.NewBuffer() } return t diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index e3ff723..4ac8fe5 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -93,7 +93,7 @@ func (t *memoryTrace) Read(opts ...tracev2.ReadOption) ([]*tracev2.SpanData, err if options.Count > 0 { entries = t.buffer.Get(options.Count) } else { - entries = t.buffer.Get(t.buffer.Size) + entries = t.buffer.Get(t.buffer.Options().Size) } spans := []*tracev2.SpanData{} diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go index 6eeee99..c30f548 100644 --- a/telemetry/tracev2/utils.go +++ b/telemetry/tracev2/utils.go @@ -9,7 +9,6 @@ import ( const ( traceParentKey = "traceparent" spanParentKey = "spanparent" - spanKey = "span" ) func ContextWithTraceParent(ctx context.Context, traceparent [16]byte) (context.Context, error) { diff --git a/utils/memoryutils/memory_utils.go b/utils/memoryutils/memory_utils.go index 74feb76..8bc9662 100644 --- a/utils/memoryutils/memory_utils.go +++ b/utils/memoryutils/memory_utils.go @@ -5,8 +5,12 @@ import ( "time" ) +var ( + defaultSize = 1024 +) + type Buffer struct { - Size int + options BufferOptions mtx sync.RWMutex entries []*Entry } @@ -16,6 +20,10 @@ type Entry struct { Timestamp time.Time } +func (m *Buffer) Options() BufferOptions { + return m.options +} + func (m *Buffer) Put(v interface{}) { m.mtx.Lock() defer m.mtx.Unlock() @@ -31,7 +39,7 @@ func (m *Buffer) Put(v interface{}) { // if the length of the entries is greater than the // specified size, then trim down the buffer by 1 - if len(m.entries) > m.Size { + if len(m.entries) > m.options.Size { m.entries = m.entries[1:] } } @@ -51,9 +59,11 @@ func (m *Buffer) Get(n int) []*Entry { return m.entries[delta:] } -func NewBuffer(size int) *Buffer { +func NewBuffer(opts ...BufferOption) *Buffer { + options := NewBufferOptions(opts...) + b := &Buffer{ - Size: size, + options: options, mtx: sync.RWMutex{}, entries: []*Entry{}, } diff --git a/utils/memoryutils/memory_utils.test.go b/utils/memoryutils/memory_utils.test.go index 3edbe09..cf684c4 100644 --- a/utils/memoryutils/memory_utils.test.go +++ b/utils/memoryutils/memory_utils.test.go @@ -7,7 +7,7 @@ import ( ) func TestMemoryBuffer(t *testing.T) { - b := NewBuffer(10) + b := NewBuffer(BufferWithSize(10)) b.Put("foo") @@ -16,7 +16,7 @@ func TestMemoryBuffer(t *testing.T) { val := entries[0].Value.(string) require.Equal(t, "foo", val) - b = NewBuffer(10) + b = NewBuffer(BufferWithSize(10)) for i := 0; i < 10; i++ { b.Put(i) From fd9a1bad9ed8270e9ffab0c1e3399040b5874393 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Sun, 13 Oct 2024 17:31:59 -0700 Subject: [PATCH 24/42] chore: don't forget to check that in --- utils/memoryutils/options.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 utils/memoryutils/options.go diff --git a/utils/memoryutils/options.go b/utils/memoryutils/options.go new file mode 100644 index 0000000..2ab3eee --- /dev/null +++ b/utils/memoryutils/options.go @@ -0,0 +1,25 @@ +package memoryutils + +type BufferOption func(o *BufferOptions) + +type BufferOptions struct { + Size int +} + +func BufferWithSize(size int) BufferOption { + return func(o *BufferOptions) { + o.Size = size + } +} + +func NewBufferOptions(opts ...BufferOption) BufferOptions { + options := BufferOptions{ + Size: defaultSize, + } + + for _, fn := range opts { + fn(&options) + } + + return options +} From fd59b111f661e2ec60323477f810b5a561749ce6 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 08:09:21 -0700 Subject: [PATCH 25/42] chore: clean up --- serverv2/http/server_test.go | 3 ++- sidecar/custom/sidecar.go | 2 -- telemetry/log/memory/log.go | 6 +++--- telemetry/log/memory/log_test.go | 3 ++- telemetry/log/memory/options.go | 13 +++++++------ telemetry/tracev2/memory/trace.go | 2 -- telemetry/tracev2/trace.go | 1 - 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/serverv2/http/server_test.go b/serverv2/http/server_test.go index 0d11c3c..b5a693a 100644 --- a/serverv2/http/server_test.go +++ b/serverv2/http/server_test.go @@ -10,10 +10,11 @@ import ( "github.com/w-h-a/pkg/serverv2" "github.com/w-h-a/pkg/telemetry/log" "github.com/w-h-a/pkg/telemetry/log/memory" + "github.com/w-h-a/pkg/utils/memoryutils" ) func TestHttpServer(t *testing.T) { - logger := memory.NewLog() + logger := memory.NewLog(memory.LogWithBuffer(memoryutils.NewBuffer())) log.SetLogger(logger) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index c6aec68..e4a85fd 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -182,8 +182,6 @@ func (s *customSidecar) UnsubscribeFromBroker(brokerId string) error { } func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*sidecar.Secret, error) { - // TODO: make sure we have a tracer - _, spanId := s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") s.options.Tracer.AddMetadata(spanId, map[string]string{ diff --git a/telemetry/log/memory/log.go b/telemetry/log/memory/log.go index 14938e5..08a63d5 100644 --- a/telemetry/log/memory/log.go +++ b/telemetry/log/memory/log.go @@ -62,10 +62,10 @@ func NewLog(opts ...log.LogOption) log.Log { options: options, } - if s, ok := GetSizeFromContext(options.Context); ok && s > 0 { - l.buffer = memoryutils.NewBuffer(memoryutils.BufferWithSize(s)) + if b, ok := GetBufferFromContext(options.Context); ok && b != nil { + l.buffer = b } else { - l.buffer = memoryutils.NewBuffer() + log.Fatalf("no buffer was given") } return l diff --git a/telemetry/log/memory/log_test.go b/telemetry/log/memory/log_test.go index 299243e..4f3a5bb 100644 --- a/telemetry/log/memory/log_test.go +++ b/telemetry/log/memory/log_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/w-h-a/pkg/telemetry/log" + "github.com/w-h-a/pkg/utils/memoryutils" ) func TestLogger(t *testing.T) { @@ -13,7 +14,7 @@ func TestLogger(t *testing.T) { service := "service.namespace" - logger := NewLog(log.LogWithPrefix(service), log.LogWithLevel(log.LevelDebug), LogWithSize(size)) + logger := NewLog(log.LogWithPrefix(service), log.LogWithLevel(log.LevelDebug), LogWithBuffer(memoryutils.NewBuffer(memoryutils.BufferWithSize(size)))) require.Equal(t, size, logger.(*memoryLog).buffer.Options().Size) log.SetLogger(logger) diff --git a/telemetry/log/memory/options.go b/telemetry/log/memory/options.go index 378f36d..97665aa 100644 --- a/telemetry/log/memory/options.go +++ b/telemetry/log/memory/options.go @@ -4,17 +4,18 @@ import ( "context" "github.com/w-h-a/pkg/telemetry/log" + "github.com/w-h-a/pkg/utils/memoryutils" ) -type sizeKey struct{} +type bufferKey struct{} -func LogWithSize(s int) log.LogOption { +func LogWithBuffer(b *memoryutils.Buffer) log.LogOption { return func(o *log.LogOptions) { - o.Context = context.WithValue(o.Context, sizeKey{}, s) + o.Context = context.WithValue(o.Context, bufferKey{}, b) } } -func GetSizeFromContext(ctx context.Context) (int, bool) { - s, ok := ctx.Value(sizeKey{}).(int) - return s, ok +func GetBufferFromContext(ctx context.Context) (*memoryutils.Buffer, bool) { + b, ok := ctx.Value(bufferKey{}).(*memoryutils.Buffer) + return b, ok } diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index 4ac8fe5..4120ef5 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -25,8 +25,6 @@ func (t *memoryTrace) Options() tracev2.TraceOptions { } func (t *memoryTrace) Start(ctx context.Context, name string) (context.Context, string) { - // TODO: make sure we're enabled - t.mtx.Lock() defer t.mtx.Unlock() diff --git a/telemetry/tracev2/trace.go b/telemetry/tracev2/trace.go index f3a7d3c..ac0ab8c 100644 --- a/telemetry/tracev2/trace.go +++ b/telemetry/tracev2/trace.go @@ -7,7 +7,6 @@ import ( // TODO: status type Trace interface { Options() TraceOptions - // TODO: add cfg argument to check for whether tracing is enabled Start(ctx context.Context, name string) (context.Context, string) AddMetadata(span string, md map[string]string) Finish(span string) From c6d76a94ca056b914d395ce21b7f735ff2f9cfb3 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 08:59:42 -0700 Subject: [PATCH 26/42] feat: add status --- sidecar/custom/sidecar.go | 6 +++--- telemetry/tracev2/domain.go | 7 ++++++- telemetry/tracev2/memory/exporter.go | 6 ++++++ telemetry/tracev2/memory/trace.go | 12 ++++++++++++ telemetry/tracev2/trace.go | 2 +- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index e4a85fd..0a892d5 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -192,19 +192,19 @@ func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore str sc, ok := s.options.Secrets[secretStore] if !ok { log.Warnf("secret store %s was not found", secretStore) - // TODO: update status of span + s.options.Tracer.UpdateStatus(spanId, 400, fmt.Sprintf("secret store %s was not found", secretStore)) s.options.Tracer.Finish(spanId) return nil, sidecar.ErrComponentNotFound } mp, err := sc.GetSecret(name) if err != nil { - // TODO: update status of span + s.options.Tracer.UpdateStatus(spanId, 500, fmt.Sprintf("failed to get secret: %v", err)) s.options.Tracer.Finish(spanId) return nil, err } - // TODO: update status of span + s.options.Tracer.UpdateStatus(spanId, 200, "succeeded in retrieving secret") s.options.Tracer.Finish(spanId) diff --git a/telemetry/tracev2/domain.go b/telemetry/tracev2/domain.go index 0707bca..cca581a 100644 --- a/telemetry/tracev2/domain.go +++ b/telemetry/tracev2/domain.go @@ -4,7 +4,6 @@ import ( "time" ) -// TODO: status type SpanData struct { Name string `json:"name"` Id string `json:"id"` @@ -13,4 +12,10 @@ type SpanData struct { Started time.Time `json:"started"` Ended time.Time `json:"ended"` Metadata map[string]string `json:"metadata"` + Status Status `json:"status"` +} + +type Status struct { + Code uint32 + Description string } diff --git a/telemetry/tracev2/memory/exporter.go b/telemetry/tracev2/memory/exporter.go index 48bb407..f7d6d4c 100644 --- a/telemetry/tracev2/memory/exporter.go +++ b/telemetry/tracev2/memory/exporter.go @@ -33,6 +33,11 @@ func (e *memoryExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadO metadata[string(attr.Key)] = attr.Value.AsString() } + status := tracev2.Status{ + Code: uint32(s.Status().Code), + Description: s.Status().Description, + } + data := &tracev2.SpanData{ Name: s.Name(), Id: s.SpanContext().SpanID().String(), @@ -41,6 +46,7 @@ func (e *memoryExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadO Started: s.StartTime(), Ended: s.EndTime(), Metadata: metadata, + Status: status, } spanData = append(spanData, data) diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index 4120ef5..040992c 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -9,6 +9,7 @@ import ( "github.com/w-h-a/pkg/utils/memoryutils" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" ) @@ -74,6 +75,17 @@ func (t *memoryTrace) AddMetadata(span string, md map[string]string) { t.spans[span].SetAttributes(attrs...) } +func (t *memoryTrace) UpdateStatus(span string, code uint32, description string) { + t.mtx.Lock() + defer t.mtx.Unlock() + + if code >= 400 { + t.spans[span].SetStatus(codes.Error, description) + } else { + t.spans[span].SetStatus(codes.Ok, description) + } +} + func (t *memoryTrace) Finish(span string) { t.mtx.Lock() defer t.mtx.Unlock() diff --git a/telemetry/tracev2/trace.go b/telemetry/tracev2/trace.go index ac0ab8c..1c9d843 100644 --- a/telemetry/tracev2/trace.go +++ b/telemetry/tracev2/trace.go @@ -4,11 +4,11 @@ import ( "context" ) -// TODO: status type Trace interface { Options() TraceOptions Start(ctx context.Context, name string) (context.Context, string) AddMetadata(span string, md map[string]string) + UpdateStatus(span string, code uint32, description string) Finish(span string) Read(opts ...ReadOption) ([]*SpanData, error) String() string From 15f9908311165d0ebac6edbf2ed5223d9ef50b31 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 09:05:11 -0700 Subject: [PATCH 27/42] refactor: status --- telemetry/tracev2/domain.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telemetry/tracev2/domain.go b/telemetry/tracev2/domain.go index cca581a..23e202b 100644 --- a/telemetry/tracev2/domain.go +++ b/telemetry/tracev2/domain.go @@ -16,6 +16,6 @@ type SpanData struct { } type Status struct { - Code uint32 - Description string + Code uint32 `json:"code"` + Description string `json:"description"` } From 728a1a4814909372157a0521bed1841303763441 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 09:53:39 -0700 Subject: [PATCH 28/42] feat: add ctx --- sidecar/custom/sidecar.go | 124 ++++++++++++++++++++++++++---- sidecar/sidecar.go | 14 ++-- telemetry/tracev2/memory/trace.go | 8 +- 3 files changed, 121 insertions(+), 25 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 0a892d5..7fb3e43 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -28,14 +28,26 @@ func (s *customSidecar) Options() sidecar.SidecarOptions { return s.options } -func (s *customSidecar) SaveStateToStore(state *sidecar.State) error { +func (s *customSidecar) SaveStateToStore(ctx context.Context, state *sidecar.State) error { + _, spanId := s.options.Tracer.Start(ctx, "customSidecar.SaveStateToStore") + defer s.options.Tracer.Finish(spanId) + + records, _ := json.Marshal(state.Records) + + s.options.Tracer.AddMetadata(spanId, map[string]string{ + "storeId": state.StoreId, + "records": string(records), + }) + if len(state.Records) == 0 { + s.options.Tracer.UpdateStatus(spanId, 2, "success") return nil } st, ok := s.options.Stores[state.StoreId] if !ok { log.Warnf("store %s was not found", state.StoreId) + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("store %s was not found", state.StoreId)) return sidecar.ErrComponentNotFound } @@ -48,82 +60,143 @@ func (s *customSidecar) SaveStateToStore(state *sidecar.State) error { bs, err := datautils.Stringify(data) if err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return err } storeRecord.Value = bs if err := st.Write(storeRecord); err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return err } } + s.options.Tracer.UpdateStatus(spanId, 2, "success") + return nil } -func (c *customSidecar) ListStateFromStore(storeId string) ([]*store.Record, error) { - st, ok := c.options.Stores[storeId] +func (s *customSidecar) ListStateFromStore(ctx context.Context, storeId string) ([]*store.Record, error) { + _, spanId := s.options.Tracer.Start(ctx, "customSidecar.ListStateFromStore") + defer s.options.Tracer.Finish(spanId) + + s.options.Tracer.AddMetadata(spanId, map[string]string{ + "storeId": storeId, + }) + + st, ok := s.options.Stores[storeId] if !ok { log.Warnf("store %s was not found", storeId) + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("store %s was not found", storeId)) return nil, sidecar.ErrComponentNotFound } // TODO: limit + offset recs, err := st.Read("", store.ReadWithPrefix()) if err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return nil, err } + s.options.Tracer.UpdateStatus(spanId, 2, "success") + return recs, nil } -func (s *customSidecar) SingleStateFromStore(storeId, key string) ([]*store.Record, error) { +func (s *customSidecar) SingleStateFromStore(ctx context.Context, storeId, key string) ([]*store.Record, error) { + _, spanId := s.options.Tracer.Start(ctx, "customSidecar.SingleStateFromStore") + defer s.options.Tracer.Finish(spanId) + + s.options.Tracer.AddMetadata(spanId, map[string]string{ + "storeId": storeId, + "key": key, + }) + st, ok := s.options.Stores[storeId] if !ok { log.Warnf("store %s was not found", storeId) + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("store %s was not found", storeId)) return nil, sidecar.ErrComponentNotFound } recs, err := st.Read(key) if err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return nil, err } + s.options.Tracer.UpdateStatus(spanId, 2, "success") + return recs, nil } -func (s *customSidecar) RemoveStateFromStore(storeId, key string) error { +func (s *customSidecar) RemoveStateFromStore(ctx context.Context, storeId, key string) error { + _, spanId := s.options.Tracer.Start(ctx, "customSidecar.RemoveStateFromStore") + defer s.options.Tracer.Finish(spanId) + + s.options.Tracer.AddMetadata(spanId, map[string]string{ + "storeId": storeId, + "key": key, + }) + st, ok := s.options.Stores[storeId] if !ok { log.Warnf("store %s was not found", storeId) + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("store %s was not found", storeId)) return sidecar.ErrComponentNotFound } if err := st.Delete(key); err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return err } + s.options.Tracer.UpdateStatus(spanId, 2, "success") + return nil } -func (s *customSidecar) WriteEventToBroker(event *sidecar.Event) error { +func (s *customSidecar) WriteEventToBroker(ctx context.Context, event *sidecar.Event) error { + _, spanId := s.options.Tracer.Start(ctx, "customSidecar.WriteEventToBroker") + defer s.options.Tracer.Finish(spanId) + + data, _ := json.Marshal(event.Data) + + s.options.Tracer.AddMetadata(spanId, map[string]string{ + "eventName": event.EventName, + "data": string(data), + }) + bk, ok := s.options.Brokers[event.EventName] if !ok { log.Warnf("broker %s was not found", event.EventName) + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("broker %s was not found", event.EventName)) return sidecar.ErrComponentNotFound } if err := bk.Publish(event.Data, *bk.Options().PublishOptions); err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return err } + s.options.Tracer.UpdateStatus(spanId, 2, "success") + return nil } -func (s *customSidecar) ReadEventsFromBroker(brokerId string) { +func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId string) { + _, spanId := s.options.Tracer.Start(ctx, "customSidecar.ReadEventsFromBroker") + defer s.options.Tracer.Finish(spanId) + + s.options.Tracer.AddMetadata(spanId, map[string]string{ + "brokerId": brokerId, + }) + bk, ok := s.options.Brokers[brokerId] if !ok { log.Warnf("broker %s was not found", brokerId) + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("broker %s was not found", brokerId)) return } @@ -133,14 +206,23 @@ func (s *customSidecar) ReadEventsFromBroker(brokerId string) { if ok { log.Warnf("a subscriber for broker %s was already found", brokerId) s.mtx.RUnlock() + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("a subscriber for broker %s was already found", brokerId)) return } s.mtx.RUnlock() sub := bk.Subscribe(func(b []byte) error { + _, spanId := s.options.Tracer.Start(context.Background(), fmt.Sprintf("%s.Handler", brokerId)) + defer s.options.Tracer.Finish(spanId) + + s.options.Tracer.AddMetadata(spanId, map[string]string{ + "data": string(b), + }) + var body interface{} if err := json.Unmarshal(b, &body); err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return err } @@ -149,6 +231,8 @@ func (s *customSidecar) ReadEventsFromBroker(brokerId string) { Data: body, } + s.options.Tracer.UpdateStatus(spanId, 2, "success") + return s.sendEventToService(event) }, *bk.Options().SubscribeOptions) @@ -156,20 +240,31 @@ func (s *customSidecar) ReadEventsFromBroker(brokerId string) { defer s.mtx.Unlock() s.subscribers[brokerId] = sub + + s.options.Tracer.UpdateStatus(spanId, 2, "success") } -func (s *customSidecar) UnsubscribeFromBroker(brokerId string) error { +func (s *customSidecar) UnsubscribeFromBroker(ctx context.Context, brokerId string) error { + _, spanId := s.options.Tracer.Start(ctx, "customSidecar.UnsubscribeFromBroker") + defer s.options.Tracer.Finish(spanId) + + s.options.Tracer.AddMetadata(spanId, map[string]string{ + "brokerId": brokerId, + }) + s.mtx.RLock() sub, ok := s.subscribers[brokerId] if !ok { s.mtx.RUnlock() + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("broker %s was not found", brokerId)) return nil } s.mtx.RUnlock() if err := sub.Unsubscribe(); err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return err } @@ -178,11 +273,14 @@ func (s *customSidecar) UnsubscribeFromBroker(brokerId string) error { delete(s.subscribers, brokerId) + s.options.Tracer.UpdateStatus(spanId, 2, "success") + return nil } func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*sidecar.Secret, error) { _, spanId := s.options.Tracer.Start(ctx, "customSidecar.ReadFromSecretStore") + defer s.options.Tracer.Finish(spanId) s.options.Tracer.AddMetadata(spanId, map[string]string{ "secretStore": secretStore, @@ -192,21 +290,17 @@ func (s *customSidecar) ReadFromSecretStore(ctx context.Context, secretStore str sc, ok := s.options.Secrets[secretStore] if !ok { log.Warnf("secret store %s was not found", secretStore) - s.options.Tracer.UpdateStatus(spanId, 400, fmt.Sprintf("secret store %s was not found", secretStore)) - s.options.Tracer.Finish(spanId) + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("secret store %s was not found", secretStore)) return nil, sidecar.ErrComponentNotFound } mp, err := sc.GetSecret(name) if err != nil { - s.options.Tracer.UpdateStatus(spanId, 500, fmt.Sprintf("failed to get secret: %v", err)) - s.options.Tracer.Finish(spanId) + s.options.Tracer.UpdateStatus(spanId, 1, fmt.Sprintf("failed to get secret: %v", err)) return nil, err } - s.options.Tracer.UpdateStatus(spanId, 200, "succeeded in retrieving secret") - - s.options.Tracer.Finish(spanId) + s.options.Tracer.UpdateStatus(spanId, 2, "success") return &sidecar.Secret{ Data: mp, diff --git a/sidecar/sidecar.go b/sidecar/sidecar.go index 1d1bf68..5213af8 100644 --- a/sidecar/sidecar.go +++ b/sidecar/sidecar.go @@ -14,13 +14,13 @@ var ( type Sidecar interface { Options() SidecarOptions - SaveStateToStore(state *State) error - ListStateFromStore(store string) ([]*store.Record, error) - SingleStateFromStore(store, key string) ([]*store.Record, error) - RemoveStateFromStore(store, key string) error - WriteEventToBroker(event *Event) error - ReadEventsFromBroker(broker string) - UnsubscribeFromBroker(broker string) error + SaveStateToStore(ctx context.Context, state *State) error + ListStateFromStore(ctx context.Context, store string) ([]*store.Record, error) + SingleStateFromStore(ctx context.Context, store, key string) ([]*store.Record, error) + RemoveStateFromStore(ctx context.Context, store, key string) error + WriteEventToBroker(ctx context.Context, event *Event) error + ReadEventsFromBroker(ctx context.Context, broker string) + UnsubscribeFromBroker(ctx context.Context, broker string) error ReadFromSecretStore(ctx context.Context, secretStore string, name string) (*Secret, error) String() string } diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index 040992c..45e1a51 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -79,10 +79,12 @@ func (t *memoryTrace) UpdateStatus(span string, code uint32, description string) t.mtx.Lock() defer t.mtx.Unlock() - if code >= 400 { - t.spans[span].SetStatus(codes.Error, description) - } else { + switch code { + case 2: t.spans[span].SetStatus(codes.Ok, description) + case 1: + t.spans[span].SetStatus(codes.Error, description) + default: } } From 1dc8515f1cba85040367d67b1e8e09ea4d55d374 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 10:50:31 -0700 Subject: [PATCH 29/42] fix: do not forget to add the trace to md --- telemetry/tracev2/memory/trace.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telemetry/tracev2/memory/trace.go b/telemetry/tracev2/memory/trace.go index 45e1a51..633c3ff 100644 --- a/telemetry/tracev2/memory/trace.go +++ b/telemetry/tracev2/memory/trace.go @@ -45,7 +45,9 @@ func (t *memoryTrace) Start(ctx context.Context, name string) (context.Context, t.spans[key] = span - newCtx, _ := tracev2.ContextWithSpanParent(ctx, span.SpanContext().SpanID()) + intermediateCtx, _ := tracev2.ContextWithSpanParent(ctx, span.SpanContext().SpanID()) + + newCtx, _ := tracev2.ContextWithTraceParent(intermediateCtx, span.SpanContext().TraceID()) return newCtx, key } From 638e9081c01643d307764bcf7a836cfab443756e Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 16:19:25 -0700 Subject: [PATCH 30/42] refactor: make tracing better for pubsub --- proto/sidecar/sidecar.pb.go | 370 ++++++++++++++++++++++-------------- proto/sidecar/sidecar.proto | 5 + security/authn/utils.go | 6 +- sidecar/custom/sidecar.go | 44 +++-- sidecar/domain.go | 9 +- sidecar/utils.go | 9 +- telemetry/tracev2/utils.go | 12 +- 7 files changed, 285 insertions(+), 170 deletions(-) diff --git a/proto/sidecar/sidecar.pb.go b/proto/sidecar/sidecar.pb.go index 29f510a..f345fd8 100644 --- a/proto/sidecar/sidecar.pb.go +++ b/proto/sidecar/sidecar.pb.go @@ -27,8 +27,8 @@ type Event struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - EventName string `protobuf:"bytes,1,opt,name=eventName,proto3" json:"eventName,omitempty"` - Data *anypb.Any `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + EventName string `protobuf:"bytes,1,opt,name=eventName,proto3" json:"eventName,omitempty"` + Payload *Payload `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` } func (x *Event) Reset() { @@ -70,7 +70,62 @@ func (x *Event) GetEventName() string { return "" } -func (x *Event) GetData() *anypb.Any { +func (x *Event) GetPayload() *Payload { + if x != nil { + return x.Payload + } + return nil +} + +type Payload struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Metadata map[string]string `protobuf:"bytes,1,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Data *anypb.Any `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` +} + +func (x *Payload) Reset() { + *x = Payload{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_sidecar_sidecar_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Payload) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Payload) ProtoMessage() {} + +func (x *Payload) ProtoReflect() protoreflect.Message { + mi := &file_proto_sidecar_sidecar_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Payload.ProtoReflect.Descriptor instead. +func (*Payload) Descriptor() ([]byte, []int) { + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{1} +} + +func (x *Payload) GetMetadata() map[string]string { + if x != nil { + return x.Metadata + } + return nil +} + +func (x *Payload) GetData() *anypb.Any { if x != nil { return x.Data } @@ -89,7 +144,7 @@ type KeyVal struct { func (x *KeyVal) Reset() { *x = KeyVal{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[1] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -102,7 +157,7 @@ func (x *KeyVal) String() string { func (*KeyVal) ProtoMessage() {} func (x *KeyVal) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[1] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -115,7 +170,7 @@ func (x *KeyVal) ProtoReflect() protoreflect.Message { // Deprecated: Use KeyVal.ProtoReflect.Descriptor instead. func (*KeyVal) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{1} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{2} } func (x *KeyVal) GetKey() string { @@ -143,7 +198,7 @@ type Secret struct { func (x *Secret) Reset() { *x = Secret{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[2] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -156,7 +211,7 @@ func (x *Secret) String() string { func (*Secret) ProtoMessage() {} func (x *Secret) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[2] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -169,7 +224,7 @@ func (x *Secret) ProtoReflect() protoreflect.Message { // Deprecated: Use Secret.ProtoReflect.Descriptor instead. func (*Secret) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{2} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{3} } func (x *Secret) GetData() map[string]string { @@ -192,7 +247,7 @@ type PostStateRequest struct { func (x *PostStateRequest) Reset() { *x = PostStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[3] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -205,7 +260,7 @@ func (x *PostStateRequest) String() string { func (*PostStateRequest) ProtoMessage() {} func (x *PostStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[3] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -218,7 +273,7 @@ func (x *PostStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PostStateRequest.ProtoReflect.Descriptor instead. func (*PostStateRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{3} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{4} } func (x *PostStateRequest) GetStoreId() string { @@ -244,7 +299,7 @@ type PostStateResponse struct { func (x *PostStateResponse) Reset() { *x = PostStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[4] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -257,7 +312,7 @@ func (x *PostStateResponse) String() string { func (*PostStateResponse) ProtoMessage() {} func (x *PostStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[4] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -270,7 +325,7 @@ func (x *PostStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PostStateResponse.ProtoReflect.Descriptor instead. func (*PostStateResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{4} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{5} } // sidecar list state request/response @@ -285,7 +340,7 @@ type ListStateRequest struct { func (x *ListStateRequest) Reset() { *x = ListStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[5] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -298,7 +353,7 @@ func (x *ListStateRequest) String() string { func (*ListStateRequest) ProtoMessage() {} func (x *ListStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[5] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -311,7 +366,7 @@ func (x *ListStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListStateRequest.ProtoReflect.Descriptor instead. func (*ListStateRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{5} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{6} } func (x *ListStateRequest) GetStoreId() string { @@ -332,7 +387,7 @@ type ListStateResponse struct { func (x *ListStateResponse) Reset() { *x = ListStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[6] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -345,7 +400,7 @@ func (x *ListStateResponse) String() string { func (*ListStateResponse) ProtoMessage() {} func (x *ListStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[6] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -358,7 +413,7 @@ func (x *ListStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListStateResponse.ProtoReflect.Descriptor instead. func (*ListStateResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{6} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{7} } func (x *ListStateResponse) GetRecords() []*KeyVal { @@ -381,7 +436,7 @@ type GetStateRequest struct { func (x *GetStateRequest) Reset() { *x = GetStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[7] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -394,7 +449,7 @@ func (x *GetStateRequest) String() string { func (*GetStateRequest) ProtoMessage() {} func (x *GetStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[7] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -407,7 +462,7 @@ func (x *GetStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetStateRequest.ProtoReflect.Descriptor instead. func (*GetStateRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{7} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{8} } func (x *GetStateRequest) GetStoreId() string { @@ -435,7 +490,7 @@ type GetStateResponse struct { func (x *GetStateResponse) Reset() { *x = GetStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[8] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -448,7 +503,7 @@ func (x *GetStateResponse) String() string { func (*GetStateResponse) ProtoMessage() {} func (x *GetStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[8] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -461,7 +516,7 @@ func (x *GetStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetStateResponse.ProtoReflect.Descriptor instead. func (*GetStateResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{8} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{9} } func (x *GetStateResponse) GetRecords() []*KeyVal { @@ -484,7 +539,7 @@ type DeleteStateRequest struct { func (x *DeleteStateRequest) Reset() { *x = DeleteStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[9] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -497,7 +552,7 @@ func (x *DeleteStateRequest) String() string { func (*DeleteStateRequest) ProtoMessage() {} func (x *DeleteStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[9] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -510,7 +565,7 @@ func (x *DeleteStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteStateRequest.ProtoReflect.Descriptor instead. func (*DeleteStateRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{9} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{10} } func (x *DeleteStateRequest) GetStoreId() string { @@ -536,7 +591,7 @@ type DeleteStateResponse struct { func (x *DeleteStateResponse) Reset() { *x = DeleteStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[10] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -549,7 +604,7 @@ func (x *DeleteStateResponse) String() string { func (*DeleteStateResponse) ProtoMessage() {} func (x *DeleteStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[10] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -562,7 +617,7 @@ func (x *DeleteStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteStateResponse.ProtoReflect.Descriptor instead. func (*DeleteStateResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{10} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{11} } // sidecar publish request/response @@ -577,7 +632,7 @@ type PublishRequest struct { func (x *PublishRequest) Reset() { *x = PublishRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[11] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -590,7 +645,7 @@ func (x *PublishRequest) String() string { func (*PublishRequest) ProtoMessage() {} func (x *PublishRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[11] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -603,7 +658,7 @@ func (x *PublishRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PublishRequest.ProtoReflect.Descriptor instead. func (*PublishRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{11} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{12} } func (x *PublishRequest) GetEvent() *Event { @@ -622,7 +677,7 @@ type PublishResponse struct { func (x *PublishResponse) Reset() { *x = PublishResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[12] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -635,7 +690,7 @@ func (x *PublishResponse) String() string { func (*PublishResponse) ProtoMessage() {} func (x *PublishResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[12] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -648,7 +703,7 @@ func (x *PublishResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PublishResponse.ProtoReflect.Descriptor instead. func (*PublishResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{12} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{13} } // sidecar get secret request/response @@ -664,7 +719,7 @@ type GetSecretRequest struct { func (x *GetSecretRequest) Reset() { *x = GetSecretRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[13] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -677,7 +732,7 @@ func (x *GetSecretRequest) String() string { func (*GetSecretRequest) ProtoMessage() {} func (x *GetSecretRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[13] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -690,7 +745,7 @@ func (x *GetSecretRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetSecretRequest.ProtoReflect.Descriptor instead. func (*GetSecretRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{13} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{14} } func (x *GetSecretRequest) GetSecretId() string { @@ -718,7 +773,7 @@ type GetSecretResponse struct { func (x *GetSecretResponse) Reset() { *x = GetSecretResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[14] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -731,7 +786,7 @@ func (x *GetSecretResponse) String() string { func (*GetSecretResponse) ProtoMessage() {} func (x *GetSecretResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[14] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -744,7 +799,7 @@ func (x *GetSecretResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetSecretResponse.ProtoReflect.Descriptor instead. func (*GetSecretResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{14} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{15} } func (x *GetSecretResponse) GetSecret() *Secret { @@ -761,66 +816,77 @@ var file_proto_sidecar_sidecar_proto_rawDesc = []byte{ 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x4f, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x76, + 0x6f, 0x22, 0x51, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, - 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x64, 0x61, - 0x74, 0x61, 0x22, 0x46, 0x0a, 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2a, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x41, 0x6e, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x70, 0x0a, 0x06, 0x53, 0x65, - 0x63, 0x72, 0x65, 0x74, 0x12, 0x2d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, - 0x72, 0x65, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x64, - 0x61, 0x74, 0x61, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, - 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, - 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, 0x10, - 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x72, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, - 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x4c, 0x69, - 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, - 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x22, 0x3e, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, - 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, - 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, - 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, - 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, - 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3d, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, 0x74, - 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x72, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, + 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, + 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x69, 0x64, 0x65, + 0x63, 0x61, 0x72, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x07, 0x70, 0x61, 0x79, + 0x6c, 0x6f, 0x61, 0x64, 0x22, 0xac, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, + 0x12, 0x3a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x50, 0x61, 0x79, + 0x6c, 0x6f, 0x61, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x28, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, + 0x02, 0x38, 0x01, 0x22, 0x46, 0x0a, 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x2a, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x70, 0x0a, 0x06, 0x53, + 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, 0x2d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, + 0x63, 0x72, 0x65, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, + 0x10, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x72, + 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x40, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x4c, + 0x69, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x22, 0x3e, 0x0a, 0x11, 0x4c, 0x69, 0x73, + 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, + 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, + 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x15, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, - 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x36, 0x0a, 0x0e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x24, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x0e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, - 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, 0x62, 0x6c, 0x69, - 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x0a, 0x10, 0x47, 0x65, - 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, - 0x0a, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3c, 0x0a, 0x11, - 0x47, 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x27, 0x0a, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, 0x72, - 0x65, 0x74, 0x52, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x42, 0x24, 0x5a, 0x22, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, 0x70, - 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3d, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, + 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, + 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, + 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x40, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x15, 0x0a, 0x13, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x36, 0x0a, 0x0e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x24, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, 0x62, 0x6c, + 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x0a, 0x10, 0x47, + 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3c, 0x0a, + 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x27, 0x0a, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, + 0x72, 0x65, 0x74, 0x52, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x42, 0x24, 0x5a, 0x22, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, + 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, + 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -835,40 +901,44 @@ func file_proto_sidecar_sidecar_proto_rawDescGZIP() []byte { return file_proto_sidecar_sidecar_proto_rawDescData } -var file_proto_sidecar_sidecar_proto_msgTypes = make([]protoimpl.MessageInfo, 16) +var file_proto_sidecar_sidecar_proto_msgTypes = make([]protoimpl.MessageInfo, 18) var file_proto_sidecar_sidecar_proto_goTypes = []interface{}{ (*Event)(nil), // 0: sidecar.Event - (*KeyVal)(nil), // 1: sidecar.KeyVal - (*Secret)(nil), // 2: sidecar.Secret - (*PostStateRequest)(nil), // 3: sidecar.PostStateRequest - (*PostStateResponse)(nil), // 4: sidecar.PostStateResponse - (*ListStateRequest)(nil), // 5: sidecar.ListStateRequest - (*ListStateResponse)(nil), // 6: sidecar.ListStateResponse - (*GetStateRequest)(nil), // 7: sidecar.GetStateRequest - (*GetStateResponse)(nil), // 8: sidecar.GetStateResponse - (*DeleteStateRequest)(nil), // 9: sidecar.DeleteStateRequest - (*DeleteStateResponse)(nil), // 10: sidecar.DeleteStateResponse - (*PublishRequest)(nil), // 11: sidecar.PublishRequest - (*PublishResponse)(nil), // 12: sidecar.PublishResponse - (*GetSecretRequest)(nil), // 13: sidecar.GetSecretRequest - (*GetSecretResponse)(nil), // 14: sidecar.GetSecretResponse - nil, // 15: sidecar.Secret.DataEntry - (*anypb.Any)(nil), // 16: google.protobuf.Any + (*Payload)(nil), // 1: sidecar.Payload + (*KeyVal)(nil), // 2: sidecar.KeyVal + (*Secret)(nil), // 3: sidecar.Secret + (*PostStateRequest)(nil), // 4: sidecar.PostStateRequest + (*PostStateResponse)(nil), // 5: sidecar.PostStateResponse + (*ListStateRequest)(nil), // 6: sidecar.ListStateRequest + (*ListStateResponse)(nil), // 7: sidecar.ListStateResponse + (*GetStateRequest)(nil), // 8: sidecar.GetStateRequest + (*GetStateResponse)(nil), // 9: sidecar.GetStateResponse + (*DeleteStateRequest)(nil), // 10: sidecar.DeleteStateRequest + (*DeleteStateResponse)(nil), // 11: sidecar.DeleteStateResponse + (*PublishRequest)(nil), // 12: sidecar.PublishRequest + (*PublishResponse)(nil), // 13: sidecar.PublishResponse + (*GetSecretRequest)(nil), // 14: sidecar.GetSecretRequest + (*GetSecretResponse)(nil), // 15: sidecar.GetSecretResponse + nil, // 16: sidecar.Payload.MetadataEntry + nil, // 17: sidecar.Secret.DataEntry + (*anypb.Any)(nil), // 18: google.protobuf.Any } var file_proto_sidecar_sidecar_proto_depIdxs = []int32{ - 16, // 0: sidecar.Event.data:type_name -> google.protobuf.Any - 16, // 1: sidecar.KeyVal.value:type_name -> google.protobuf.Any - 15, // 2: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry - 1, // 3: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal - 1, // 4: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal - 1, // 5: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal - 0, // 6: sidecar.PublishRequest.event:type_name -> sidecar.Event - 2, // 7: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret - 8, // [8:8] is the sub-list for method output_type - 8, // [8:8] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 1, // 0: sidecar.Event.payload:type_name -> sidecar.Payload + 16, // 1: sidecar.Payload.metadata:type_name -> sidecar.Payload.MetadataEntry + 18, // 2: sidecar.Payload.data:type_name -> google.protobuf.Any + 18, // 3: sidecar.KeyVal.value:type_name -> google.protobuf.Any + 17, // 4: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry + 2, // 5: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal + 2, // 6: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal + 2, // 7: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal + 0, // 8: sidecar.PublishRequest.event:type_name -> sidecar.Event + 3, // 9: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret + 10, // [10:10] is the sub-list for method output_type + 10, // [10:10] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_proto_sidecar_sidecar_proto_init() } @@ -890,7 +960,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*KeyVal); i { + switch v := v.(*Payload); i { case 0: return &v.state case 1: @@ -902,7 +972,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Secret); i { + switch v := v.(*KeyVal); i { case 0: return &v.state case 1: @@ -914,7 +984,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PostStateRequest); i { + switch v := v.(*Secret); i { case 0: return &v.state case 1: @@ -926,7 +996,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PostStateResponse); i { + switch v := v.(*PostStateRequest); i { case 0: return &v.state case 1: @@ -938,7 +1008,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListStateRequest); i { + switch v := v.(*PostStateResponse); i { case 0: return &v.state case 1: @@ -950,7 +1020,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListStateResponse); i { + switch v := v.(*ListStateRequest); i { case 0: return &v.state case 1: @@ -962,7 +1032,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetStateRequest); i { + switch v := v.(*ListStateResponse); i { case 0: return &v.state case 1: @@ -974,7 +1044,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetStateResponse); i { + switch v := v.(*GetStateRequest); i { case 0: return &v.state case 1: @@ -986,7 +1056,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DeleteStateRequest); i { + switch v := v.(*GetStateResponse); i { case 0: return &v.state case 1: @@ -998,7 +1068,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DeleteStateResponse); i { + switch v := v.(*DeleteStateRequest); i { case 0: return &v.state case 1: @@ -1010,7 +1080,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PublishRequest); i { + switch v := v.(*DeleteStateResponse); i { case 0: return &v.state case 1: @@ -1022,7 +1092,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PublishResponse); i { + switch v := v.(*PublishRequest); i { case 0: return &v.state case 1: @@ -1034,7 +1104,7 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetSecretRequest); i { + switch v := v.(*PublishResponse); i { case 0: return &v.state case 1: @@ -1046,6 +1116,18 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetSecretRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_sidecar_sidecar_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetSecretResponse); i { case 0: return &v.state @@ -1064,7 +1146,7 @@ func file_proto_sidecar_sidecar_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_sidecar_sidecar_proto_rawDesc, NumEnums: 0, - NumMessages: 16, + NumMessages: 18, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/sidecar/sidecar.proto b/proto/sidecar/sidecar.proto index 1fa9861..e4e404f 100644 --- a/proto/sidecar/sidecar.proto +++ b/proto/sidecar/sidecar.proto @@ -9,6 +9,11 @@ import "google/protobuf/any.proto"; // domain message Event { string eventName = 1; + Payload payload = 2; +} + +message Payload { + map metadata = 1; google.protobuf.Any data = 2; } diff --git a/security/authn/utils.go b/security/authn/utils.go index 6fd84c8..102e667 100644 --- a/security/authn/utils.go +++ b/security/authn/utils.go @@ -8,7 +8,7 @@ import ( ) const ( - accountKey = "auth-account" + AccountKey = "auth-account" ) func ContextWithAccount(ctx context.Context, account *Account) (context.Context, error) { @@ -17,11 +17,11 @@ func ContextWithAccount(ctx context.Context, account *Account) (context.Context, return ctx, err } - return metadatautils.SetContext(ctx, accountKey, string(bytes)), nil + return metadatautils.SetContext(ctx, AccountKey, string(bytes)), nil } func AccountFromContext(ctx context.Context) (*Account, error) { - str, ok := metadatautils.GetContext(ctx, accountKey) + str, ok := metadatautils.GetContext(ctx, AccountKey) if !ok { return nil, nil } diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 7fb3e43..b86aba1 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -13,6 +13,7 @@ import ( "github.com/w-h-a/pkg/sidecar" "github.com/w-h-a/pkg/store" "github.com/w-h-a/pkg/telemetry/log" + "github.com/w-h-a/pkg/telemetry/tracev2" "github.com/w-h-a/pkg/utils/datautils" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -158,14 +159,21 @@ func (s *customSidecar) RemoveStateFromStore(ctx context.Context, storeId, key s } func (s *customSidecar) WriteEventToBroker(ctx context.Context, event *sidecar.Event) error { - _, spanId := s.options.Tracer.Start(ctx, "customSidecar.WriteEventToBroker") + newCtx, spanId := s.options.Tracer.Start(ctx, "customSidecar.WriteEventToBroker") defer s.options.Tracer.Finish(spanId) - data, _ := json.Marshal(event.Data) + if traceparent, found := tracev2.TraceParentFromContext(newCtx); found { + if len(event.Payload.Metadata) == 0 { + event.Payload.Metadata = map[string]string{} + } + event.Payload.Metadata["traceparent"] = string(traceparent[:]) + } + + payload, _ := json.Marshal(event.Payload) s.options.Tracer.AddMetadata(spanId, map[string]string{ "eventName": event.EventName, - "data": string(data), + "data": string(payload), }) bk, ok := s.options.Brokers[event.EventName] @@ -175,7 +183,7 @@ func (s *customSidecar) WriteEventToBroker(ctx context.Context, event *sidecar.E return sidecar.ErrComponentNotFound } - if err := bk.Publish(event.Data, *bk.Options().PublishOptions); err != nil { + if err := bk.Publish(event.Payload, *bk.Options().PublishOptions); err != nil { s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return err } @@ -213,22 +221,34 @@ func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId strin s.mtx.RUnlock() sub := bk.Subscribe(func(b []byte) error { - _, spanId := s.options.Tracer.Start(context.Background(), fmt.Sprintf("%s.Handler", brokerId)) + var payload sidecar.Payload + if err := json.Unmarshal(b, &payload); err != nil { + s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) + return err + } + + var traceparent [16]byte + + var spanId string + + if len(payload.Metadata) > 0 && len(payload.Metadata[tracev2.TraceParentKey]) > 0 { + copy(traceparent[:], payload.Metadata[tracev2.TraceParentKey]) + ctx, _ := tracev2.ContextWithTraceParent(context.Background(), traceparent) + _, spanId = s.options.Tracer.Start(ctx, fmt.Sprintf("%s.Handler", brokerId)) + } else { + _, spanId = s.options.Tracer.Start(context.Background(), fmt.Sprintf("%s.Handler", brokerId)) + } + defer s.options.Tracer.Finish(spanId) s.options.Tracer.AddMetadata(spanId, map[string]string{ + "brokerId": brokerId, "data": string(b), }) - var body interface{} - if err := json.Unmarshal(b, &body); err != nil { - s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) - return err - } - event := &sidecar.Event{ EventName: brokerId, - Data: body, + Payload: payload, } s.options.Tracer.UpdateStatus(spanId, 2, "success") diff --git a/sidecar/domain.go b/sidecar/domain.go index a947d0c..ed94879 100644 --- a/sidecar/domain.go +++ b/sidecar/domain.go @@ -1,8 +1,13 @@ package sidecar type Event struct { - EventName string `json:"eventName,omitempty"` - Data interface{} `json:"data,omitempty"` + EventName string `json:"eventName,omitempty"` + Payload Payload `json:"payload,omitempty"` +} + +type Payload struct { + Metadata map[string]string `json:"metadata,omitempty"` + Data interface{} `json:"data,omitempty"` } type State struct { diff --git a/sidecar/utils.go b/sidecar/utils.go index da43f63..33a20fc 100644 --- a/sidecar/utils.go +++ b/sidecar/utils.go @@ -8,15 +8,18 @@ import ( ) func SerializeEvent(event *Event) (*pb.Event, error) { - bs, err := json.Marshal(event.Data) + bs, err := json.Marshal(event.Payload) if err != nil { return nil, err } return &pb.Event{ EventName: event.EventName, - Data: &anypb.Any{ - Value: bs, + Payload: &pb.Payload{ + Metadata: event.Payload.Metadata, + Data: &anypb.Any{ + Value: bs, + }, }, }, nil } diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go index c30f548..a7ca6c1 100644 --- a/telemetry/tracev2/utils.go +++ b/telemetry/tracev2/utils.go @@ -7,18 +7,18 @@ import ( ) const ( - traceParentKey = "traceparent" - spanParentKey = "spanparent" + TraceParentKey = "traceparent" + SpanParentKey = "spanparent" ) func ContextWithTraceParent(ctx context.Context, traceparent [16]byte) (context.Context, error) { return metadatautils.MergeContext(ctx, map[string]string{ - traceParentKey: string(traceparent[:]), + TraceParentKey: string(traceparent[:]), }, true), nil } func TraceParentFromContext(ctx context.Context) (traceparent [16]byte, found bool) { - traceId, found := metadatautils.GetContext(ctx, traceParentKey) + traceId, found := metadatautils.GetContext(ctx, TraceParentKey) if !found { return } @@ -30,12 +30,12 @@ func TraceParentFromContext(ctx context.Context) (traceparent [16]byte, found bo func ContextWithSpanParent(ctx context.Context, spanparent [8]byte) (context.Context, error) { return metadatautils.MergeContext(ctx, map[string]string{ - spanParentKey: string(spanparent[:]), + SpanParentKey: string(spanparent[:]), }, true), nil } func SpanParentFromContext(ctx context.Context) (spanparent [8]byte, found bool) { - spanId, found := metadatautils.GetContext(ctx, spanParentKey) + spanId, found := metadatautils.GetContext(ctx, SpanParentKey) if !found { return } From 2b651dff7cccba912cae26d19ee920b795cb5650 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 16:40:34 -0700 Subject: [PATCH 31/42] fix: serialization --- sidecar/custom/sidecar.go | 2 +- sidecar/utils.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index b86aba1..373569c 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -243,7 +243,7 @@ func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId strin s.options.Tracer.AddMetadata(spanId, map[string]string{ "brokerId": brokerId, - "data": string(b), + "data": string(b), }) event := &sidecar.Event{ diff --git a/sidecar/utils.go b/sidecar/utils.go index 33a20fc..7aa1de6 100644 --- a/sidecar/utils.go +++ b/sidecar/utils.go @@ -8,7 +8,7 @@ import ( ) func SerializeEvent(event *Event) (*pb.Event, error) { - bs, err := json.Marshal(event.Payload) + bs, err := json.Marshal(event.Payload.Data) if err != nil { return nil, err } From fe2c3f7dcda80df1ea948f9f2af06d17681c658e Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 18:09:56 -0700 Subject: [PATCH 32/42] fix: publish event --- proto/sidecar/sidecar.pb.go | 150 ++++++++++++++++++------------------ proto/sidecar/sidecar.proto | 2 +- sidecar/domain.go | 2 +- sidecar/utils.go | 12 +-- 4 files changed, 77 insertions(+), 89 deletions(-) diff --git a/proto/sidecar/sidecar.pb.go b/proto/sidecar/sidecar.pb.go index f345fd8..36d72f8 100644 --- a/proto/sidecar/sidecar.pb.go +++ b/proto/sidecar/sidecar.pb.go @@ -83,7 +83,7 @@ type Payload struct { unknownFields protoimpl.UnknownFields Metadata map[string]string `protobuf:"bytes,1,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Data *anypb.Any `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` } func (x *Payload) Reset() { @@ -125,7 +125,7 @@ func (x *Payload) GetMetadata() map[string]string { return nil } -func (x *Payload) GetData() *anypb.Any { +func (x *Payload) GetData() []byte { if x != nil { return x.Data } @@ -821,72 +821,71 @@ var file_proto_sidecar_sidecar_proto_rawDesc = []byte{ 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x07, 0x70, 0x61, 0x79, - 0x6c, 0x6f, 0x61, 0x64, 0x22, 0xac, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, + 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x96, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x3a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x28, 0x0a, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, - 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, - 0x02, 0x38, 0x01, 0x22, 0x46, 0x0a, 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x2a, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x70, 0x0a, 0x06, 0x53, - 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, 0x2d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, - 0x63, 0x72, 0x65, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, + 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, - 0x10, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x72, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, - 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, - 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x4c, - 0x69, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x22, 0x3e, 0x0a, 0x11, 0x4c, 0x69, 0x73, - 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, - 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, - 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0f, 0x47, 0x65, 0x74, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, - 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, - 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3d, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, - 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, - 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, - 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x40, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, - 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x15, 0x0a, 0x13, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x36, 0x0a, 0x0e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x24, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, 0x62, 0x6c, - 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x0a, 0x10, 0x47, - 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3c, 0x0a, - 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x27, 0x0a, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, - 0x72, 0x65, 0x74, 0x52, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x42, 0x24, 0x5a, 0x22, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, - 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, - 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x46, 0x0a, + 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2a, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x70, 0x0a, 0x06, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, + 0x2d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, + 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x2e, 0x44, + 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x37, + 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, 0x10, 0x50, 0x6f, 0x73, 0x74, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, + 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, + 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, + 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, + 0x22, 0x13, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, + 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, + 0x65, 0x49, 0x64, 0x22, 0x3e, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, + 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, + 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, + 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x22, 0x3d, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, + 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, + 0x73, 0x22, 0x40, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, + 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x22, 0x15, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x36, 0x0a, 0x0e, 0x50, 0x75, + 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x05, + 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x69, + 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, + 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x63, + 0x72, 0x65, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x63, + 0x72, 0x65, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3c, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, + 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x06, + 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, + 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x06, 0x73, + 0x65, 0x63, 0x72, 0x65, 0x74, 0x42, 0x24, 0x5a, 0x22, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -926,19 +925,18 @@ var file_proto_sidecar_sidecar_proto_goTypes = []interface{}{ var file_proto_sidecar_sidecar_proto_depIdxs = []int32{ 1, // 0: sidecar.Event.payload:type_name -> sidecar.Payload 16, // 1: sidecar.Payload.metadata:type_name -> sidecar.Payload.MetadataEntry - 18, // 2: sidecar.Payload.data:type_name -> google.protobuf.Any - 18, // 3: sidecar.KeyVal.value:type_name -> google.protobuf.Any - 17, // 4: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry - 2, // 5: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal - 2, // 6: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal - 2, // 7: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal - 0, // 8: sidecar.PublishRequest.event:type_name -> sidecar.Event - 3, // 9: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret - 10, // [10:10] is the sub-list for method output_type - 10, // [10:10] is the sub-list for method input_type - 10, // [10:10] is the sub-list for extension type_name - 10, // [10:10] is the sub-list for extension extendee - 0, // [0:10] is the sub-list for field type_name + 18, // 2: sidecar.KeyVal.value:type_name -> google.protobuf.Any + 17, // 3: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry + 2, // 4: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal + 2, // 5: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal + 2, // 6: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal + 0, // 7: sidecar.PublishRequest.event:type_name -> sidecar.Event + 3, // 8: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret + 9, // [9:9] is the sub-list for method output_type + 9, // [9:9] is the sub-list for method input_type + 9, // [9:9] is the sub-list for extension type_name + 9, // [9:9] is the sub-list for extension extendee + 0, // [0:9] is the sub-list for field type_name } func init() { file_proto_sidecar_sidecar_proto_init() } diff --git a/proto/sidecar/sidecar.proto b/proto/sidecar/sidecar.proto index e4e404f..f192b33 100644 --- a/proto/sidecar/sidecar.proto +++ b/proto/sidecar/sidecar.proto @@ -14,7 +14,7 @@ message Event { message Payload { map metadata = 1; - google.protobuf.Any data = 2; + bytes data = 2; } message KeyVal { diff --git a/sidecar/domain.go b/sidecar/domain.go index ed94879..3e78425 100644 --- a/sidecar/domain.go +++ b/sidecar/domain.go @@ -7,7 +7,7 @@ type Event struct { type Payload struct { Metadata map[string]string `json:"metadata,omitempty"` - Data interface{} `json:"data,omitempty"` + Data []byte `json:"data,omitempty"` } type State struct { diff --git a/sidecar/utils.go b/sidecar/utils.go index 7aa1de6..f647ec7 100644 --- a/sidecar/utils.go +++ b/sidecar/utils.go @@ -1,25 +1,15 @@ package sidecar import ( - "encoding/json" - pb "github.com/w-h-a/pkg/proto/sidecar" - "google.golang.org/protobuf/types/known/anypb" ) func SerializeEvent(event *Event) (*pb.Event, error) { - bs, err := json.Marshal(event.Payload.Data) - if err != nil { - return nil, err - } - return &pb.Event{ EventName: event.EventName, Payload: &pb.Payload{ Metadata: event.Payload.Metadata, - Data: &anypb.Any{ - Value: bs, - }, + Data: event.Payload.Data, }, }, nil } From dcff95ae4ac653c94984ac3cb2ef702875aa1800 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 18:53:14 -0700 Subject: [PATCH 33/42] chore: debug --- sidecar/custom/sidecar.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 373569c..be6f250 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -173,7 +173,7 @@ func (s *customSidecar) WriteEventToBroker(ctx context.Context, event *sidecar.E s.options.Tracer.AddMetadata(spanId, map[string]string{ "eventName": event.EventName, - "data": string(payload), + "payload": string(payload), }) bk, ok := s.options.Brokers[event.EventName] @@ -243,7 +243,7 @@ func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId strin s.options.Tracer.AddMetadata(spanId, map[string]string{ "brokerId": brokerId, - "data": string(b), + "payload": string(b), }) event := &sidecar.Event{ From d7114db38cb394bdc41a8ae56212b5f2cf8925fd Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 19:40:32 -0700 Subject: [PATCH 34/42] chore: debug --- proto/sidecar/sidecar.pb.go | 150 ++++++++++++++++++------------------ proto/sidecar/sidecar.proto | 2 +- sidecar/domain.go | 2 +- sidecar/utils.go | 9 ++- 4 files changed, 86 insertions(+), 77 deletions(-) diff --git a/proto/sidecar/sidecar.pb.go b/proto/sidecar/sidecar.pb.go index 36d72f8..f345fd8 100644 --- a/proto/sidecar/sidecar.pb.go +++ b/proto/sidecar/sidecar.pb.go @@ -83,7 +83,7 @@ type Payload struct { unknownFields protoimpl.UnknownFields Metadata map[string]string `protobuf:"bytes,1,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + Data *anypb.Any `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` } func (x *Payload) Reset() { @@ -125,7 +125,7 @@ func (x *Payload) GetMetadata() map[string]string { return nil } -func (x *Payload) GetData() []byte { +func (x *Payload) GetData() *anypb.Any { if x != nil { return x.Data } @@ -821,71 +821,72 @@ var file_proto_sidecar_sidecar_proto_rawDesc = []byte{ 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x07, 0x70, 0x61, 0x79, - 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x96, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, + 0x6c, 0x6f, 0x61, 0x64, 0x22, 0xac, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x3a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, + 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x28, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, + 0x02, 0x38, 0x01, 0x22, 0x46, 0x0a, 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x2a, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x70, 0x0a, 0x06, 0x53, + 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, 0x2d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, + 0x63, 0x72, 0x65, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x46, 0x0a, - 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2a, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x70, 0x0a, 0x06, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, - 0x2d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, - 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x2e, 0x44, - 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x37, - 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, 0x10, 0x50, 0x6f, 0x73, 0x74, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, - 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, - 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, - 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, - 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, - 0x22, 0x13, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, - 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, - 0x65, 0x49, 0x64, 0x22, 0x3e, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, - 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, - 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, - 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, - 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, - 0x65, 0x79, 0x22, 0x3d, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, - 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, - 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, - 0x73, 0x22, 0x40, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, - 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, - 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x22, 0x15, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x36, 0x0a, 0x0e, 0x50, 0x75, - 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x05, - 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x69, - 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, - 0x6e, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, - 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x63, - 0x72, 0x65, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x63, - 0x72, 0x65, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3c, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, - 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x06, - 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, - 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x06, 0x73, - 0x65, 0x63, 0x72, 0x65, 0x74, 0x42, 0x24, 0x5a, 0x22, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, + 0x10, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x72, + 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, + 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, + 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x4c, + 0x69, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x22, 0x3e, 0x0a, 0x11, 0x4c, 0x69, 0x73, + 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, + 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, + 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0f, 0x47, 0x65, 0x74, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, + 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, + 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3d, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, + 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, + 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, + 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x40, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x15, 0x0a, 0x13, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x36, 0x0a, 0x0e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x24, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, 0x62, 0x6c, + 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x0a, 0x10, 0x47, + 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3c, 0x0a, + 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x27, 0x0a, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, + 0x72, 0x65, 0x74, 0x52, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x42, 0x24, 0x5a, 0x22, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, + 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, + 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -925,18 +926,19 @@ var file_proto_sidecar_sidecar_proto_goTypes = []interface{}{ var file_proto_sidecar_sidecar_proto_depIdxs = []int32{ 1, // 0: sidecar.Event.payload:type_name -> sidecar.Payload 16, // 1: sidecar.Payload.metadata:type_name -> sidecar.Payload.MetadataEntry - 18, // 2: sidecar.KeyVal.value:type_name -> google.protobuf.Any - 17, // 3: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry - 2, // 4: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal - 2, // 5: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal - 2, // 6: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal - 0, // 7: sidecar.PublishRequest.event:type_name -> sidecar.Event - 3, // 8: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret - 9, // [9:9] is the sub-list for method output_type - 9, // [9:9] is the sub-list for method input_type - 9, // [9:9] is the sub-list for extension type_name - 9, // [9:9] is the sub-list for extension extendee - 0, // [0:9] is the sub-list for field type_name + 18, // 2: sidecar.Payload.data:type_name -> google.protobuf.Any + 18, // 3: sidecar.KeyVal.value:type_name -> google.protobuf.Any + 17, // 4: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry + 2, // 5: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal + 2, // 6: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal + 2, // 7: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal + 0, // 8: sidecar.PublishRequest.event:type_name -> sidecar.Event + 3, // 9: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret + 10, // [10:10] is the sub-list for method output_type + 10, // [10:10] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_proto_sidecar_sidecar_proto_init() } diff --git a/proto/sidecar/sidecar.proto b/proto/sidecar/sidecar.proto index f192b33..e4e404f 100644 --- a/proto/sidecar/sidecar.proto +++ b/proto/sidecar/sidecar.proto @@ -14,7 +14,7 @@ message Event { message Payload { map metadata = 1; - bytes data = 2; + google.protobuf.Any data = 2; } message KeyVal { diff --git a/sidecar/domain.go b/sidecar/domain.go index 3e78425..ed94879 100644 --- a/sidecar/domain.go +++ b/sidecar/domain.go @@ -7,7 +7,7 @@ type Event struct { type Payload struct { Metadata map[string]string `json:"metadata,omitempty"` - Data []byte `json:"data,omitempty"` + Data interface{} `json:"data,omitempty"` } type State struct { diff --git a/sidecar/utils.go b/sidecar/utils.go index f647ec7..ebce9db 100644 --- a/sidecar/utils.go +++ b/sidecar/utils.go @@ -1,15 +1,22 @@ package sidecar import ( + "encoding/json" + pb "github.com/w-h-a/pkg/proto/sidecar" + "google.golang.org/protobuf/types/known/anypb" ) func SerializeEvent(event *Event) (*pb.Event, error) { + bs, _ := json.Marshal(event.Payload.Data) + return &pb.Event{ EventName: event.EventName, Payload: &pb.Payload{ Metadata: event.Payload.Metadata, - Data: event.Payload.Data, + Data: &anypb.Any{ + Value: bs, + }, }, }, nil } From 02241572d5ae2de1c924dc0e1a49544c0de0e680 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 20:43:05 -0700 Subject: [PATCH 35/42] refactor: try something else --- proto/sidecar/sidecar.pb.go | 270 +++++++++++++----------------------- proto/sidecar/sidecar.proto | 7 +- sidecar/custom/sidecar.go | 12 +- sidecar/domain.go | 9 +- sidecar/utils.go | 15 +- 5 files changed, 111 insertions(+), 202 deletions(-) diff --git a/proto/sidecar/sidecar.pb.go b/proto/sidecar/sidecar.pb.go index f345fd8..3914a8c 100644 --- a/proto/sidecar/sidecar.pb.go +++ b/proto/sidecar/sidecar.pb.go @@ -27,8 +27,8 @@ type Event struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - EventName string `protobuf:"bytes,1,opt,name=eventName,proto3" json:"eventName,omitempty"` - Payload *Payload `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` + EventName string `protobuf:"bytes,1,opt,name=eventName,proto3" json:"eventName,omitempty"` + Payload []*KeyVal `protobuf:"bytes,2,rep,name=payload,proto3" json:"payload,omitempty"` } func (x *Event) Reset() { @@ -70,68 +70,13 @@ func (x *Event) GetEventName() string { return "" } -func (x *Event) GetPayload() *Payload { +func (x *Event) GetPayload() []*KeyVal { if x != nil { return x.Payload } return nil } -type Payload struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Metadata map[string]string `protobuf:"bytes,1,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Data *anypb.Any `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` -} - -func (x *Payload) Reset() { - *x = Payload{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Payload) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Payload) ProtoMessage() {} - -func (x *Payload) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Payload.ProtoReflect.Descriptor instead. -func (*Payload) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{1} -} - -func (x *Payload) GetMetadata() map[string]string { - if x != nil { - return x.Metadata - } - return nil -} - -func (x *Payload) GetData() *anypb.Any { - if x != nil { - return x.Data - } - return nil -} - type KeyVal struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -144,7 +89,7 @@ type KeyVal struct { func (x *KeyVal) Reset() { *x = KeyVal{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[2] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -157,7 +102,7 @@ func (x *KeyVal) String() string { func (*KeyVal) ProtoMessage() {} func (x *KeyVal) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[2] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -170,7 +115,7 @@ func (x *KeyVal) ProtoReflect() protoreflect.Message { // Deprecated: Use KeyVal.ProtoReflect.Descriptor instead. func (*KeyVal) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{2} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{1} } func (x *KeyVal) GetKey() string { @@ -198,7 +143,7 @@ type Secret struct { func (x *Secret) Reset() { *x = Secret{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[3] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -211,7 +156,7 @@ func (x *Secret) String() string { func (*Secret) ProtoMessage() {} func (x *Secret) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[3] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -224,7 +169,7 @@ func (x *Secret) ProtoReflect() protoreflect.Message { // Deprecated: Use Secret.ProtoReflect.Descriptor instead. func (*Secret) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{3} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{2} } func (x *Secret) GetData() map[string]string { @@ -247,7 +192,7 @@ type PostStateRequest struct { func (x *PostStateRequest) Reset() { *x = PostStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[4] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -260,7 +205,7 @@ func (x *PostStateRequest) String() string { func (*PostStateRequest) ProtoMessage() {} func (x *PostStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[4] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -273,7 +218,7 @@ func (x *PostStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PostStateRequest.ProtoReflect.Descriptor instead. func (*PostStateRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{4} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{3} } func (x *PostStateRequest) GetStoreId() string { @@ -299,7 +244,7 @@ type PostStateResponse struct { func (x *PostStateResponse) Reset() { *x = PostStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[5] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -312,7 +257,7 @@ func (x *PostStateResponse) String() string { func (*PostStateResponse) ProtoMessage() {} func (x *PostStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[5] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -325,7 +270,7 @@ func (x *PostStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PostStateResponse.ProtoReflect.Descriptor instead. func (*PostStateResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{5} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{4} } // sidecar list state request/response @@ -340,7 +285,7 @@ type ListStateRequest struct { func (x *ListStateRequest) Reset() { *x = ListStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[6] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -353,7 +298,7 @@ func (x *ListStateRequest) String() string { func (*ListStateRequest) ProtoMessage() {} func (x *ListStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[6] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -366,7 +311,7 @@ func (x *ListStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListStateRequest.ProtoReflect.Descriptor instead. func (*ListStateRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{6} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{5} } func (x *ListStateRequest) GetStoreId() string { @@ -387,7 +332,7 @@ type ListStateResponse struct { func (x *ListStateResponse) Reset() { *x = ListStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[7] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -400,7 +345,7 @@ func (x *ListStateResponse) String() string { func (*ListStateResponse) ProtoMessage() {} func (x *ListStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[7] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -413,7 +358,7 @@ func (x *ListStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListStateResponse.ProtoReflect.Descriptor instead. func (*ListStateResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{7} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{6} } func (x *ListStateResponse) GetRecords() []*KeyVal { @@ -436,7 +381,7 @@ type GetStateRequest struct { func (x *GetStateRequest) Reset() { *x = GetStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[8] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -449,7 +394,7 @@ func (x *GetStateRequest) String() string { func (*GetStateRequest) ProtoMessage() {} func (x *GetStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[8] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -462,7 +407,7 @@ func (x *GetStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetStateRequest.ProtoReflect.Descriptor instead. func (*GetStateRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{8} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{7} } func (x *GetStateRequest) GetStoreId() string { @@ -490,7 +435,7 @@ type GetStateResponse struct { func (x *GetStateResponse) Reset() { *x = GetStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[9] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -503,7 +448,7 @@ func (x *GetStateResponse) String() string { func (*GetStateResponse) ProtoMessage() {} func (x *GetStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[9] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -516,7 +461,7 @@ func (x *GetStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetStateResponse.ProtoReflect.Descriptor instead. func (*GetStateResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{9} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{8} } func (x *GetStateResponse) GetRecords() []*KeyVal { @@ -539,7 +484,7 @@ type DeleteStateRequest struct { func (x *DeleteStateRequest) Reset() { *x = DeleteStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[10] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -552,7 +497,7 @@ func (x *DeleteStateRequest) String() string { func (*DeleteStateRequest) ProtoMessage() {} func (x *DeleteStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[10] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -565,7 +510,7 @@ func (x *DeleteStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteStateRequest.ProtoReflect.Descriptor instead. func (*DeleteStateRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{10} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{9} } func (x *DeleteStateRequest) GetStoreId() string { @@ -591,7 +536,7 @@ type DeleteStateResponse struct { func (x *DeleteStateResponse) Reset() { *x = DeleteStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[11] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -604,7 +549,7 @@ func (x *DeleteStateResponse) String() string { func (*DeleteStateResponse) ProtoMessage() {} func (x *DeleteStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[11] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -617,7 +562,7 @@ func (x *DeleteStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteStateResponse.ProtoReflect.Descriptor instead. func (*DeleteStateResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{11} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{10} } // sidecar publish request/response @@ -632,7 +577,7 @@ type PublishRequest struct { func (x *PublishRequest) Reset() { *x = PublishRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[12] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -645,7 +590,7 @@ func (x *PublishRequest) String() string { func (*PublishRequest) ProtoMessage() {} func (x *PublishRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[12] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -658,7 +603,7 @@ func (x *PublishRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PublishRequest.ProtoReflect.Descriptor instead. func (*PublishRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{12} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{11} } func (x *PublishRequest) GetEvent() *Event { @@ -677,7 +622,7 @@ type PublishResponse struct { func (x *PublishResponse) Reset() { *x = PublishResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[13] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -690,7 +635,7 @@ func (x *PublishResponse) String() string { func (*PublishResponse) ProtoMessage() {} func (x *PublishResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[13] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -703,7 +648,7 @@ func (x *PublishResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PublishResponse.ProtoReflect.Descriptor instead. func (*PublishResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{13} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{12} } // sidecar get secret request/response @@ -719,7 +664,7 @@ type GetSecretRequest struct { func (x *GetSecretRequest) Reset() { *x = GetSecretRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[14] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -732,7 +677,7 @@ func (x *GetSecretRequest) String() string { func (*GetSecretRequest) ProtoMessage() {} func (x *GetSecretRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[14] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -745,7 +690,7 @@ func (x *GetSecretRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetSecretRequest.ProtoReflect.Descriptor instead. func (*GetSecretRequest) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{14} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{13} } func (x *GetSecretRequest) GetSecretId() string { @@ -773,7 +718,7 @@ type GetSecretResponse struct { func (x *GetSecretResponse) Reset() { *x = GetSecretResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[15] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -786,7 +731,7 @@ func (x *GetSecretResponse) String() string { func (*GetSecretResponse) ProtoMessage() {} func (x *GetSecretResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_sidecar_sidecar_proto_msgTypes[15] + mi := &file_proto_sidecar_sidecar_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -799,7 +744,7 @@ func (x *GetSecretResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetSecretResponse.ProtoReflect.Descriptor instead. func (*GetSecretResponse) Descriptor() ([]byte, []int) { - return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{15} + return file_proto_sidecar_sidecar_proto_rawDescGZIP(), []int{14} } func (x *GetSecretResponse) GetSecret() *Secret { @@ -816,23 +761,12 @@ var file_proto_sidecar_sidecar_proto_rawDesc = []byte{ 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x51, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x76, + 0x6f, 0x22, 0x50, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, - 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, - 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x69, 0x64, 0x65, - 0x63, 0x61, 0x72, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x07, 0x70, 0x61, 0x79, - 0x6c, 0x6f, 0x61, 0x64, 0x22, 0xac, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, - 0x12, 0x3a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x50, 0x61, 0x79, - 0x6c, 0x6f, 0x61, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x28, 0x0a, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, - 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, - 0x02, 0x38, 0x01, 0x22, 0x46, 0x0a, 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, + 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, + 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, + 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, + 0x6f, 0x61, 0x64, 0x22, 0x46, 0x0a, 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2a, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, @@ -901,44 +835,40 @@ func file_proto_sidecar_sidecar_proto_rawDescGZIP() []byte { return file_proto_sidecar_sidecar_proto_rawDescData } -var file_proto_sidecar_sidecar_proto_msgTypes = make([]protoimpl.MessageInfo, 18) +var file_proto_sidecar_sidecar_proto_msgTypes = make([]protoimpl.MessageInfo, 16) var file_proto_sidecar_sidecar_proto_goTypes = []interface{}{ (*Event)(nil), // 0: sidecar.Event - (*Payload)(nil), // 1: sidecar.Payload - (*KeyVal)(nil), // 2: sidecar.KeyVal - (*Secret)(nil), // 3: sidecar.Secret - (*PostStateRequest)(nil), // 4: sidecar.PostStateRequest - (*PostStateResponse)(nil), // 5: sidecar.PostStateResponse - (*ListStateRequest)(nil), // 6: sidecar.ListStateRequest - (*ListStateResponse)(nil), // 7: sidecar.ListStateResponse - (*GetStateRequest)(nil), // 8: sidecar.GetStateRequest - (*GetStateResponse)(nil), // 9: sidecar.GetStateResponse - (*DeleteStateRequest)(nil), // 10: sidecar.DeleteStateRequest - (*DeleteStateResponse)(nil), // 11: sidecar.DeleteStateResponse - (*PublishRequest)(nil), // 12: sidecar.PublishRequest - (*PublishResponse)(nil), // 13: sidecar.PublishResponse - (*GetSecretRequest)(nil), // 14: sidecar.GetSecretRequest - (*GetSecretResponse)(nil), // 15: sidecar.GetSecretResponse - nil, // 16: sidecar.Payload.MetadataEntry - nil, // 17: sidecar.Secret.DataEntry - (*anypb.Any)(nil), // 18: google.protobuf.Any + (*KeyVal)(nil), // 1: sidecar.KeyVal + (*Secret)(nil), // 2: sidecar.Secret + (*PostStateRequest)(nil), // 3: sidecar.PostStateRequest + (*PostStateResponse)(nil), // 4: sidecar.PostStateResponse + (*ListStateRequest)(nil), // 5: sidecar.ListStateRequest + (*ListStateResponse)(nil), // 6: sidecar.ListStateResponse + (*GetStateRequest)(nil), // 7: sidecar.GetStateRequest + (*GetStateResponse)(nil), // 8: sidecar.GetStateResponse + (*DeleteStateRequest)(nil), // 9: sidecar.DeleteStateRequest + (*DeleteStateResponse)(nil), // 10: sidecar.DeleteStateResponse + (*PublishRequest)(nil), // 11: sidecar.PublishRequest + (*PublishResponse)(nil), // 12: sidecar.PublishResponse + (*GetSecretRequest)(nil), // 13: sidecar.GetSecretRequest + (*GetSecretResponse)(nil), // 14: sidecar.GetSecretResponse + nil, // 15: sidecar.Secret.DataEntry + (*anypb.Any)(nil), // 16: google.protobuf.Any } var file_proto_sidecar_sidecar_proto_depIdxs = []int32{ - 1, // 0: sidecar.Event.payload:type_name -> sidecar.Payload - 16, // 1: sidecar.Payload.metadata:type_name -> sidecar.Payload.MetadataEntry - 18, // 2: sidecar.Payload.data:type_name -> google.protobuf.Any - 18, // 3: sidecar.KeyVal.value:type_name -> google.protobuf.Any - 17, // 4: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry - 2, // 5: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal - 2, // 6: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal - 2, // 7: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal - 0, // 8: sidecar.PublishRequest.event:type_name -> sidecar.Event - 3, // 9: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret - 10, // [10:10] is the sub-list for method output_type - 10, // [10:10] is the sub-list for method input_type - 10, // [10:10] is the sub-list for extension type_name - 10, // [10:10] is the sub-list for extension extendee - 0, // [0:10] is the sub-list for field type_name + 1, // 0: sidecar.Event.payload:type_name -> sidecar.KeyVal + 16, // 1: sidecar.KeyVal.value:type_name -> google.protobuf.Any + 15, // 2: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry + 1, // 3: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal + 1, // 4: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal + 1, // 5: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal + 0, // 6: sidecar.PublishRequest.event:type_name -> sidecar.Event + 2, // 7: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret + 8, // [8:8] is the sub-list for method output_type + 8, // [8:8] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_proto_sidecar_sidecar_proto_init() } @@ -960,18 +890,6 @@ func file_proto_sidecar_sidecar_proto_init() { } } file_proto_sidecar_sidecar_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Payload); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_sidecar_sidecar_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*KeyVal); i { case 0: return &v.state @@ -983,7 +901,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Secret); i { case 0: return &v.state @@ -995,7 +913,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PostStateRequest); i { case 0: return &v.state @@ -1007,7 +925,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PostStateResponse); i { case 0: return &v.state @@ -1019,7 +937,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListStateRequest); i { case 0: return &v.state @@ -1031,7 +949,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListStateResponse); i { case 0: return &v.state @@ -1043,7 +961,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetStateRequest); i { case 0: return &v.state @@ -1055,7 +973,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetStateResponse); i { case 0: return &v.state @@ -1067,7 +985,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*DeleteStateRequest); i { case 0: return &v.state @@ -1079,7 +997,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*DeleteStateResponse); i { case 0: return &v.state @@ -1091,7 +1009,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PublishRequest); i { case 0: return &v.state @@ -1103,7 +1021,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PublishResponse); i { case 0: return &v.state @@ -1115,7 +1033,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetSecretRequest); i { case 0: return &v.state @@ -1127,7 +1045,7 @@ func file_proto_sidecar_sidecar_proto_init() { return nil } } - file_proto_sidecar_sidecar_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + file_proto_sidecar_sidecar_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetSecretResponse); i { case 0: return &v.state @@ -1146,7 +1064,7 @@ func file_proto_sidecar_sidecar_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_sidecar_sidecar_proto_rawDesc, NumEnums: 0, - NumMessages: 18, + NumMessages: 16, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/sidecar/sidecar.proto b/proto/sidecar/sidecar.proto index e4e404f..6a78470 100644 --- a/proto/sidecar/sidecar.proto +++ b/proto/sidecar/sidecar.proto @@ -9,12 +9,7 @@ import "google/protobuf/any.proto"; // domain message Event { string eventName = 1; - Payload payload = 2; -} - -message Payload { - map metadata = 1; - google.protobuf.Any data = 2; + repeated KeyVal payload = 2; } message KeyVal { diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index be6f250..7942b5e 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -163,10 +163,9 @@ func (s *customSidecar) WriteEventToBroker(ctx context.Context, event *sidecar.E defer s.options.Tracer.Finish(spanId) if traceparent, found := tracev2.TraceParentFromContext(newCtx); found { - if len(event.Payload.Metadata) == 0 { - event.Payload.Metadata = map[string]string{} + if _, ok := event.Payload[tracev2.TraceParentKey].(string); !ok { + event.Payload[tracev2.TraceParentKey] = string(traceparent[:]) } - event.Payload.Metadata["traceparent"] = string(traceparent[:]) } payload, _ := json.Marshal(event.Payload) @@ -221,7 +220,8 @@ func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId strin s.mtx.RUnlock() sub := bk.Subscribe(func(b []byte) error { - var payload sidecar.Payload + var payload map[string]interface{} + if err := json.Unmarshal(b, &payload); err != nil { s.options.Tracer.UpdateStatus(spanId, 1, err.Error()) return err @@ -231,8 +231,8 @@ func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId strin var spanId string - if len(payload.Metadata) > 0 && len(payload.Metadata[tracev2.TraceParentKey]) > 0 { - copy(traceparent[:], payload.Metadata[tracev2.TraceParentKey]) + if _, ok := payload[tracev2.TraceParentKey].(string); ok { + copy(traceparent[:], payload[tracev2.TraceParentKey].(string)) ctx, _ := tracev2.ContextWithTraceParent(context.Background(), traceparent) _, spanId = s.options.Tracer.Start(ctx, fmt.Sprintf("%s.Handler", brokerId)) } else { diff --git a/sidecar/domain.go b/sidecar/domain.go index ed94879..bf402a1 100644 --- a/sidecar/domain.go +++ b/sidecar/domain.go @@ -1,13 +1,8 @@ package sidecar type Event struct { - EventName string `json:"eventName,omitempty"` - Payload Payload `json:"payload,omitempty"` -} - -type Payload struct { - Metadata map[string]string `json:"metadata,omitempty"` - Data interface{} `json:"data,omitempty"` + EventName string `json:"eventName,omitempty"` + Payload map[string]interface{} `json:"payload,omitempty"` } type State struct { diff --git a/sidecar/utils.go b/sidecar/utils.go index ebce9db..4bd4a49 100644 --- a/sidecar/utils.go +++ b/sidecar/utils.go @@ -8,15 +8,16 @@ import ( ) func SerializeEvent(event *Event) (*pb.Event, error) { - bs, _ := json.Marshal(event.Payload.Data) + kvs := []*pb.KeyVal{} + + for k, v := range event.Payload { + bytes, _ := json.Marshal(v) + kv := &pb.KeyVal{Key: k, Value: &anypb.Any{Value: bytes}} + kvs = append(kvs, kv) + } return &pb.Event{ EventName: event.EventName, - Payload: &pb.Payload{ - Metadata: event.Payload.Metadata, - Data: &anypb.Any{ - Value: bs, - }, - }, + Payload: kvs, }, nil } From 9fb0c6144067b86e9e1c3072e6582666c72b7b07 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 21:14:03 -0700 Subject: [PATCH 36/42] refactor: have grpc use bytes --- proto/sidecar/sidecar.pb.go | 140 ++++++++++++++++++------------------ proto/sidecar/sidecar.proto | 2 +- sidecar/utils.go | 11 +-- 3 files changed, 72 insertions(+), 81 deletions(-) diff --git a/proto/sidecar/sidecar.pb.go b/proto/sidecar/sidecar.pb.go index 3914a8c..ca47559 100644 --- a/proto/sidecar/sidecar.pb.go +++ b/proto/sidecar/sidecar.pb.go @@ -27,8 +27,8 @@ type Event struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - EventName string `protobuf:"bytes,1,opt,name=eventName,proto3" json:"eventName,omitempty"` - Payload []*KeyVal `protobuf:"bytes,2,rep,name=payload,proto3" json:"payload,omitempty"` + EventName string `protobuf:"bytes,1,opt,name=eventName,proto3" json:"eventName,omitempty"` + Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` } func (x *Event) Reset() { @@ -70,7 +70,7 @@ func (x *Event) GetEventName() string { return "" } -func (x *Event) GetPayload() []*KeyVal { +func (x *Event) GetPayload() []byte { if x != nil { return x.Payload } @@ -761,66 +761,65 @@ var file_proto_sidecar_sidecar_proto_rawDesc = []byte{ 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x50, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x76, + 0x6f, 0x22, 0x3f, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, - 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, - 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, - 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, - 0x6f, 0x61, 0x64, 0x22, 0x46, 0x0a, 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x2a, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x70, 0x0a, 0x06, 0x53, - 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, 0x2d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, - 0x63, 0x72, 0x65, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, - 0x10, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x72, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, + 0x76, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, + 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, + 0x61, 0x64, 0x22, 0x46, 0x0a, 0x06, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2a, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x41, 0x6e, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x70, 0x0a, 0x06, 0x53, 0x65, + 0x63, 0x72, 0x65, 0x74, 0x12, 0x2d, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, + 0x72, 0x65, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x57, 0x0a, 0x10, + 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x72, 0x65, + 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, + 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, 0x65, + 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x4c, 0x69, + 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, + 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x22, 0x3e, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, + 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, + 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, + 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, + 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, + 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3d, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x72, + 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, 0x72, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x53, 0x74, - 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x4c, - 0x69, 0x73, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x22, 0x3e, 0x0a, 0x11, 0x4c, 0x69, 0x73, - 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, - 0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, - 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0f, 0x47, 0x65, 0x74, + 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x40, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3d, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x07, - 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, - 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x52, 0x07, - 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x40, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, - 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x15, 0x0a, 0x13, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x36, 0x0a, 0x0e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x24, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, 0x62, 0x6c, - 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x0a, 0x10, 0x47, - 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3c, 0x0a, - 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x27, 0x0a, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, - 0x72, 0x65, 0x74, 0x52, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x42, 0x24, 0x5a, 0x22, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, - 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, - 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x15, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, + 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x36, 0x0a, 0x0e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x24, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0e, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, 0x62, 0x6c, 0x69, + 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x40, 0x0a, 0x10, 0x47, 0x65, + 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, + 0x0a, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3c, 0x0a, 0x11, + 0x47, 0x65, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x27, 0x0a, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, 0x2e, 0x53, 0x65, 0x63, 0x72, + 0x65, 0x74, 0x52, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x42, 0x24, 0x5a, 0x22, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x2d, 0x68, 0x2d, 0x61, 0x2f, 0x70, + 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x63, 0x61, 0x72, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -856,19 +855,18 @@ var file_proto_sidecar_sidecar_proto_goTypes = []interface{}{ (*anypb.Any)(nil), // 16: google.protobuf.Any } var file_proto_sidecar_sidecar_proto_depIdxs = []int32{ - 1, // 0: sidecar.Event.payload:type_name -> sidecar.KeyVal - 16, // 1: sidecar.KeyVal.value:type_name -> google.protobuf.Any - 15, // 2: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry - 1, // 3: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal - 1, // 4: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal - 1, // 5: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal - 0, // 6: sidecar.PublishRequest.event:type_name -> sidecar.Event - 2, // 7: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret - 8, // [8:8] is the sub-list for method output_type - 8, // [8:8] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 16, // 0: sidecar.KeyVal.value:type_name -> google.protobuf.Any + 15, // 1: sidecar.Secret.data:type_name -> sidecar.Secret.DataEntry + 1, // 2: sidecar.PostStateRequest.records:type_name -> sidecar.KeyVal + 1, // 3: sidecar.ListStateResponse.records:type_name -> sidecar.KeyVal + 1, // 4: sidecar.GetStateResponse.records:type_name -> sidecar.KeyVal + 0, // 5: sidecar.PublishRequest.event:type_name -> sidecar.Event + 2, // 6: sidecar.GetSecretResponse.secret:type_name -> sidecar.Secret + 7, // [7:7] is the sub-list for method output_type + 7, // [7:7] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name } func init() { file_proto_sidecar_sidecar_proto_init() } diff --git a/proto/sidecar/sidecar.proto b/proto/sidecar/sidecar.proto index 6a78470..bf5e709 100644 --- a/proto/sidecar/sidecar.proto +++ b/proto/sidecar/sidecar.proto @@ -9,7 +9,7 @@ import "google/protobuf/any.proto"; // domain message Event { string eventName = 1; - repeated KeyVal payload = 2; + bytes payload = 2; } message KeyVal { diff --git a/sidecar/utils.go b/sidecar/utils.go index 4bd4a49..4ea5a4d 100644 --- a/sidecar/utils.go +++ b/sidecar/utils.go @@ -4,20 +4,13 @@ import ( "encoding/json" pb "github.com/w-h-a/pkg/proto/sidecar" - "google.golang.org/protobuf/types/known/anypb" ) func SerializeEvent(event *Event) (*pb.Event, error) { - kvs := []*pb.KeyVal{} - - for k, v := range event.Payload { - bytes, _ := json.Marshal(v) - kv := &pb.KeyVal{Key: k, Value: &anypb.Any{Value: bytes}} - kvs = append(kvs, kv) - } + bs, _ := json.Marshal(event.Payload) return &pb.Event{ EventName: event.EventName, - Payload: kvs, + Payload: bs, }, nil } From b862147ddbd4f0c05e87fd659318ac6d3dbe251f Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 22:31:51 -0700 Subject: [PATCH 37/42] chore: debug --- sidecar/custom/sidecar.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 7942b5e..db3fd88 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -231,7 +231,12 @@ func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId strin var spanId string + log.Infof("WHAT WE HAVE %+#v", payload) + + log.Infof("WHAT WE HAVE %+#v", payload[tracev2.TraceParentKey]) + if _, ok := payload[tracev2.TraceParentKey].(string); ok { + log.Infof("WE HAVE A TRACE %s", payload[tracev2.TraceParentKey].(string)) copy(traceparent[:], payload[tracev2.TraceParentKey].(string)) ctx, _ := tracev2.ContextWithTraceParent(context.Background(), traceparent) _, spanId = s.options.Tracer.Start(ctx, fmt.Sprintf("%s.Handler", brokerId)) From 1878127d7c5fa661022411a6de56dad0d984cb16 Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 22:32:39 -0700 Subject: [PATCH 38/42] chore: debug --- sidecar/custom/sidecar.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index db3fd88..4b482f0 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -168,6 +168,10 @@ func (s *customSidecar) WriteEventToBroker(ctx context.Context, event *sidecar.E } } + log.Infof("WHAT WE HAVE %+#v", event.Payload) + + log.Infof("WHAT WE HAVE %+#v", event.Payload[tracev2.TraceParentKey]) + payload, _ := json.Marshal(event.Payload) s.options.Tracer.AddMetadata(spanId, map[string]string{ From 1036a36c192ede313d9d8cf12545bfd3fa07be0a Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 22:55:08 -0700 Subject: [PATCH 39/42] refactor: use hex --- sidecar/custom/sidecar.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 4b482f0..80c22a5 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -2,6 +2,7 @@ package custom import ( "context" + "encoding/hex" "encoding/json" "fmt" "strconv" @@ -164,14 +165,10 @@ func (s *customSidecar) WriteEventToBroker(ctx context.Context, event *sidecar.E if traceparent, found := tracev2.TraceParentFromContext(newCtx); found { if _, ok := event.Payload[tracev2.TraceParentKey].(string); !ok { - event.Payload[tracev2.TraceParentKey] = string(traceparent[:]) + event.Payload[tracev2.TraceParentKey] = hex.EncodeToString(traceparent[:]) } } - log.Infof("WHAT WE HAVE %+#v", event.Payload) - - log.Infof("WHAT WE HAVE %+#v", event.Payload[tracev2.TraceParentKey]) - payload, _ := json.Marshal(event.Payload) s.options.Tracer.AddMetadata(spanId, map[string]string{ @@ -235,12 +232,7 @@ func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId strin var spanId string - log.Infof("WHAT WE HAVE %+#v", payload) - - log.Infof("WHAT WE HAVE %+#v", payload[tracev2.TraceParentKey]) - if _, ok := payload[tracev2.TraceParentKey].(string); ok { - log.Infof("WE HAVE A TRACE %s", payload[tracev2.TraceParentKey].(string)) copy(traceparent[:], payload[tracev2.TraceParentKey].(string)) ctx, _ := tracev2.ContextWithTraceParent(context.Background(), traceparent) _, spanId = s.options.Tracer.Start(ctx, fmt.Sprintf("%s.Handler", brokerId)) From 99db623f83e474b6487583b08ed45a734d64a5ef Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 23:12:12 -0700 Subject: [PATCH 40/42] refactor: use hex --- sidecar/custom/sidecar.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sidecar/custom/sidecar.go b/sidecar/custom/sidecar.go index 80c22a5..882576d 100644 --- a/sidecar/custom/sidecar.go +++ b/sidecar/custom/sidecar.go @@ -232,8 +232,9 @@ func (s *customSidecar) ReadEventsFromBroker(ctx context.Context, brokerId strin var spanId string - if _, ok := payload[tracev2.TraceParentKey].(string); ok { - copy(traceparent[:], payload[tracev2.TraceParentKey].(string)) + if encoded, ok := payload[tracev2.TraceParentKey].(string); ok { + decoded, _ := hex.DecodeString(encoded) + copy(traceparent[:], decoded) ctx, _ := tracev2.ContextWithTraceParent(context.Background(), traceparent) _, spanId = s.options.Tracer.Start(ctx, fmt.Sprintf("%s.Handler", brokerId)) } else { From 889ff116f137ba71dfc6a5895e257124a13d4bfa Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 23:28:05 -0700 Subject: [PATCH 41/42] refactor: use hex --- telemetry/tracev2/utils.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go index a7ca6c1..2c9de15 100644 --- a/telemetry/tracev2/utils.go +++ b/telemetry/tracev2/utils.go @@ -2,7 +2,9 @@ package tracev2 import ( "context" + "encoding/hex" + "github.com/w-h-a/pkg/telemetry/log" "github.com/w-h-a/pkg/utils/metadatautils" ) @@ -23,7 +25,14 @@ func TraceParentFromContext(ctx context.Context) (traceparent [16]byte, found bo return } - copy(traceparent[:], traceId) + decoded, err := hex.DecodeString(traceId) + if err == nil { + log.Infof("IT WAS A HEX %s", traceId) + copy(traceparent[:], decoded) + } else { + log.Infof("IT WAS NOT A HEX %s", traceId) + copy(traceparent[:], traceId) + } return } @@ -40,7 +49,12 @@ func SpanParentFromContext(ctx context.Context) (spanparent [8]byte, found bool) return } - copy(spanparent[:], spanId) + decoded, err := hex.DecodeString(spanId) + if err == nil { + copy(spanparent[:], decoded) + } else { + copy(spanparent[:], spanId) + } return } From e3111f617606388ab6714f211ee8d8ba5258fd7d Mon Sep 17 00:00:00 2001 From: w-h-a Date: Mon, 14 Oct 2024 23:38:21 -0700 Subject: [PATCH 42/42] refactor: rm logs --- telemetry/tracev2/utils.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/telemetry/tracev2/utils.go b/telemetry/tracev2/utils.go index 2c9de15..356f530 100644 --- a/telemetry/tracev2/utils.go +++ b/telemetry/tracev2/utils.go @@ -4,7 +4,6 @@ import ( "context" "encoding/hex" - "github.com/w-h-a/pkg/telemetry/log" "github.com/w-h-a/pkg/utils/metadatautils" ) @@ -27,10 +26,8 @@ func TraceParentFromContext(ctx context.Context) (traceparent [16]byte, found bo decoded, err := hex.DecodeString(traceId) if err == nil { - log.Infof("IT WAS A HEX %s", traceId) copy(traceparent[:], decoded) } else { - log.Infof("IT WAS NOT A HEX %s", traceId) copy(traceparent[:], traceId) }