diff --git a/Makefile b/Makefile index 4d59e1ab6e3..3582ace1f5a 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ genproto: genproto-cleanup # Call a sub-make to ensure OPENTELEMETRY_PROTO_FILES is populated $(MAKE) genproto_sub $(MAKE) fmt - $(MAKE) genproto-cleanup + # $(MAKE) genproto-cleanup genproto_sub: @echo Generating code for the following files: @@ -234,8 +234,8 @@ genproto_sub: cp -R $(PROTO_INTERMEDIATE_DIR)/$(PROTO_PACKAGE)/* $(PROTO_TARGET_GEN_DIR)/ rm -rf $(PROTO_INTERMEDIATE_DIR)/go.opentelemetry.io - @rm -rf $(OPENTELEMETRY_PROTO_SRC_DIR)/* - @rm -rf $(OPENTELEMETRY_PROTO_SRC_DIR)/.* > /dev/null 2>&1 || true + #@rm -rf $(OPENTELEMETRY_PROTO_SRC_DIR)/* + #@rm -rf $(OPENTELEMETRY_PROTO_SRC_DIR)/.* > /dev/null 2>&1 || true # Generate structs, functions and tests for pdata package. Must be used after any changes # to proto and after running `make genproto` diff --git a/cmd/mdatagen/internal/loader.go b/cmd/mdatagen/internal/loader.go index b51fc86f141..e0e04216e4f 100644 --- a/cmd/mdatagen/internal/loader.go +++ b/cmd/mdatagen/internal/loader.go @@ -269,6 +269,15 @@ func (t telemetry) Levels() map[string]interface{} { return levels } +type Entity struct { + // Type of the entity. + Type string `mapstructure:"type"` + // Identifying attributes of the entity. + IDAttributes []AttributeName `mapstructure:"id_attributes"` + // Descriptive attributes of the entity. + DescriptiveAttributes []AttributeName `mapstructure:"descriptive_attributes"` +} + type Metadata struct { // Type of the component. Type string `mapstructure:"type"` @@ -284,6 +293,8 @@ type Metadata struct { SemConvVersion string `mapstructure:"sem_conv_version"` // ResourceAttributes that can be emitted by the component. ResourceAttributes map[AttributeName]Attribute `mapstructure:"resource_attributes"` + // Entities associated with the emitted resource attributes. + Entities []Entity `mapstructure:"entities"` // Attributes emitted by one or more metrics. Attributes map[AttributeName]Attribute `mapstructure:"attributes"` // Metrics that can be emitted by the component. diff --git a/cmd/mdatagen/internal/templates/resource.go.tmpl b/cmd/mdatagen/internal/templates/resource.go.tmpl index aa6b8e8b685..4ee3112d224 100644 --- a/cmd/mdatagen/internal/templates/resource.go.tmpl +++ b/cmd/mdatagen/internal/templates/resource.go.tmpl @@ -46,6 +46,22 @@ func (rb *ResourceBuilder) Set{{ $name.Render }}(val {{ $attr.Type.Primitive }}) // Emit returns the built resource and resets the internal builder state. func (rb *ResourceBuilder) Emit() pcommon.Resource { r := rb.res + {{- range $entity := .Entities }} + {{- range $attr := .IDAttributes }} + _, found{{ $attr.Render }} := r.Attributes().Get("{{ $attr }}") + {{- end }} + if {{ range $i, $attr := .IDAttributes }}{{ if $i }}&& {{ end }}found{{ $attr.Render }} {{ end }} { + ref := pcommon.NewResourceEntityRef() + ref.SetType("{{ $entity.Type }}") + ref.IdAttrKeys().Append({{ range $i, $attr := .IDAttributes }}{{ if $i }}, {{ end }}"{{ $attr }}"{{ end }}) + {{- range $attr := .DescriptiveAttributes }} + if _, ok := r.Attributes().Get("{{ $attr }}"); ok { + ref.DescrAttrKeys().Append("{{ $attr }}") + } + {{- end }} + ref.CopyTo(r.Entities().AppendEmpty()) + } + {{- end }} rb.res = pcommon.NewResource() return r } diff --git a/cmd/mdatagen/internal/validate.go b/cmd/mdatagen/internal/validate.go index b784a94fbba..1d439d299f1 100644 --- a/cmd/mdatagen/internal/validate.go +++ b/cmd/mdatagen/internal/validate.go @@ -25,6 +25,9 @@ func (md *Metadata) Validate() error { if err := md.validateMetrics(); err != nil { errs = errors.Join(errs, err) } + if err := md.validateEntities(); err != nil { + errs = errors.Join(errs, err) + } return errs } @@ -143,6 +146,18 @@ func (md *Metadata) validateMetrics() error { return errs } +func (md *Metadata) validateEntities() error { + var errs error + for _, entity := range md.Entities { + for _, attr := range append(entity.IDAttributes, entity.DescriptiveAttributes...) { + if _, ok := md.ResourceAttributes[attr]; !ok { + errs = errors.Join(errs, fmt.Errorf("undefined resource attribute: %v", attr)) + } + } + } + return errs +} + func (m *Metric) validate() error { var errs error if m.Description == "" { diff --git a/cmd/mdatagen/metadata-schema.yaml b/cmd/mdatagen/metadata-schema.yaml index afd1f09b62a..23662584b99 100644 --- a/cmd/mdatagen/metadata-schema.yaml +++ b/cmd/mdatagen/metadata-schema.yaml @@ -59,6 +59,13 @@ resource_attributes: # Should be used for deprecated optional resource_attributes that will be removed soon. if_configured: +# Optional: list of entities associated with the produced resource. +entities: + - type: string + # Array of attribute names that are used to identify the entity. + id_attributes: [string] + # Optional: array of attribute names that are used to describe the entity. + descriptive_attributes: [string] # Optional: map of attribute definitions with the key being the attribute name and value # being described below. diff --git a/consumer/consumertest/consumer.go b/consumer/consumertest/consumer.go index 4b699b9449a..78f3bf3d500 100644 --- a/consumer/consumertest/consumer.go +++ b/consumer/consumertest/consumer.go @@ -8,6 +8,7 @@ import ( "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumerprofiles" + "go.opentelemetry.io/collector/pdata/pentity" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/pprofile" @@ -34,6 +35,9 @@ type Consumer interface { // ConsumeProfiles to implement the consumerprofiles.Profiles. ConsumeProfiles(context.Context, pprofile.Profiles) error + // ConsumeEntities to implement the consumer.Entities. + ConsumeEntities(context.Context, pentity.Entities) error + unexported() } @@ -41,6 +45,7 @@ var _ consumer.Logs = (Consumer)(nil) var _ consumer.Metrics = (Consumer)(nil) var _ consumer.Traces = (Consumer)(nil) var _ consumerprofiles.Profiles = (Consumer)(nil) +var _ consumer.Entities = (Consumer)(nil) type nonMutatingConsumer struct{} @@ -55,6 +60,7 @@ type baseConsumer struct { consumer.ConsumeMetricsFunc consumer.ConsumeLogsFunc consumerprofiles.ConsumeProfilesFunc + consumer.ConsumeEntitiesFunc } func (bc baseConsumer) unexported() {} diff --git a/consumer/consumertest/nop.go b/consumer/consumertest/nop.go index 25b898a7751..a36e5014333 100644 --- a/consumer/consumertest/nop.go +++ b/consumer/consumertest/nop.go @@ -6,6 +6,7 @@ package consumertest // import "go.opentelemetry.io/collector/consumer/consumert import ( "context" + "go.opentelemetry.io/collector/pdata/pentity" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/pprofile" @@ -19,5 +20,6 @@ func NewNop() Consumer { ConsumeMetricsFunc: func(context.Context, pmetric.Metrics) error { return nil }, ConsumeLogsFunc: func(context.Context, plog.Logs) error { return nil }, ConsumeProfilesFunc: func(context.Context, pprofile.Profiles) error { return nil }, + ConsumeEntitiesFunc: func(context.Context, pentity.Entities) error { return nil }, } } diff --git a/consumer/entities.go b/consumer/entities.go new file mode 100644 index 00000000000..284488c8bce --- /dev/null +++ b/consumer/entities.go @@ -0,0 +1,43 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package consumer // import "go.opentelemetry.io/collector/consumer" + +import ( + "context" + + "go.opentelemetry.io/collector/consumer/internal" + "go.opentelemetry.io/collector/pdata/pentity" +) + +// Entities is an interface that receives pentity.Entities, processes it +// as needed, and sends it to the next processing node if any or to the destination. +type Entities interface { + internal.BaseConsumer + // ConsumeEntities receives pentity.Entities for consumption. + ConsumeEntities(ctx context.Context, td pentity.Entities) error +} + +// ConsumeEntitiesFunc is a helper function that is similar to ConsumeEntities. +type ConsumeEntitiesFunc func(ctx context.Context, td pentity.Entities) error + +// ConsumeEntities calls f(ctx, td). +func (f ConsumeEntitiesFunc) ConsumeEntities(ctx context.Context, td pentity.Entities) error { + return f(ctx, td) +} + +type baseEntities struct { + *internal.BaseImpl + ConsumeEntitiesFunc +} + +// NewEntities returns a Entities configured with the provided options. +func NewEntities(consume ConsumeEntitiesFunc, options ...Option) (Entities, error) { + if consume == nil { + return nil, errNilFunc + } + return &baseEntities{ + BaseImpl: internal.NewBaseImpl(options...), + ConsumeEntitiesFunc: consume, + }, nil +} diff --git a/exporter/debugexporter/internal/otlptext/databuffer.go b/exporter/debugexporter/internal/otlptext/databuffer.go index 4e73794da7a..ef46dc3df7a 100644 --- a/exporter/debugexporter/internal/otlptext/databuffer.go +++ b/exporter/debugexporter/internal/otlptext/databuffer.go @@ -440,6 +440,22 @@ func linkTableToMap(ls pprofile.LinkSlice) pcommon.Map { return m } +func (b *dataBuffer) logResourceEntities(rers pcommon.ResourceEntityRefSlice) { + if rers.Len() == 0 { + return + } + + b.logEntry("Entities:") + for i := 0; i < rers.Len(); i++ { + rer := rers.At(i) + b.logEntry("Entity Ref #%d", i) + b.logEntry(" -> Entity Type: %s", rer.Type()) + b.logEntry(" -> SchemaURL: %s", rer.SchemaUrl()) + b.logEntry(" -> Identifying Attributes: %s", strings.Join(rer.IdAttrKeys().AsRaw(), ", ")) + b.logEntry(" -> Descriptive Attributes: %s", strings.Join(rer.DescrAttrKeys().AsRaw(), ", ")) + } +} + func valueToString(v pcommon.Value) string { return fmt.Sprintf("%s(%s)", v.Type().String(), v.AsString()) } diff --git a/exporter/debugexporter/internal/otlptext/logs.go b/exporter/debugexporter/internal/otlptext/logs.go index 399e9f00d39..7d7aa875780 100644 --- a/exporter/debugexporter/internal/otlptext/logs.go +++ b/exporter/debugexporter/internal/otlptext/logs.go @@ -22,7 +22,7 @@ func (textLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) { buf.logEntry("ResourceLog #%d", i) rl := rls.At(i) buf.logEntry("Resource SchemaURL: %s", rl.SchemaUrl()) - buf.logAttributes("Resource attributes", rl.Resource().Attributes()) + marshalResource(rl.Resource(), &buf) ills := rl.ScopeLogs() for j := 0; j < ills.Len(); j++ { buf.logEntry("ScopeLogs #%d", j) diff --git a/exporter/debugexporter/internal/otlptext/metrics.go b/exporter/debugexporter/internal/otlptext/metrics.go index 489d70925b5..870ece5075a 100644 --- a/exporter/debugexporter/internal/otlptext/metrics.go +++ b/exporter/debugexporter/internal/otlptext/metrics.go @@ -20,7 +20,7 @@ func (textMetricsMarshaler) MarshalMetrics(md pmetric.Metrics) ([]byte, error) { buf.logEntry("ResourceMetrics #%d", i) rm := rms.At(i) buf.logEntry("Resource SchemaURL: %s", rm.SchemaUrl()) - buf.logAttributes("Resource attributes", rm.Resource().Attributes()) + marshalResource(rm.Resource(), &buf) ilms := rm.ScopeMetrics() for j := 0; j < ilms.Len(); j++ { buf.logEntry("ScopeMetrics #%d", j) diff --git a/exporter/debugexporter/internal/otlptext/resource.go b/exporter/debugexporter/internal/otlptext/resource.go new file mode 100644 index 00000000000..549aa1cbc8a --- /dev/null +++ b/exporter/debugexporter/internal/otlptext/resource.go @@ -0,0 +1,13 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package otlptext // import "go.opentelemetry.io/collector/exporter/debugexporter/internal/otlptext" + +import ( + "go.opentelemetry.io/collector/pdata/pcommon" +) + +func marshalResource(res pcommon.Resource, buf *dataBuffer) { + buf.logAttributes("Resource attributes", res.Attributes()) + buf.logResourceEntities(res.Entities()) +} diff --git a/exporter/debugexporter/internal/otlptext/traces.go b/exporter/debugexporter/internal/otlptext/traces.go index 90d5c400a4f..898aa7b72d5 100644 --- a/exporter/debugexporter/internal/otlptext/traces.go +++ b/exporter/debugexporter/internal/otlptext/traces.go @@ -22,7 +22,7 @@ func (textTracesMarshaler) MarshalTraces(td ptrace.Traces) ([]byte, error) { buf.logEntry("ResourceSpans #%d", i) rs := rss.At(i) buf.logEntry("Resource SchemaURL: %s", rs.SchemaUrl()) - buf.logAttributes("Resource attributes", rs.Resource().Attributes()) + marshalResource(rs.Resource(), &buf) ilss := rs.ScopeSpans() for j := 0; j < ilss.Len(); j++ { buf.logEntry("ScopeSpans #%d", j) diff --git a/exporter/exporter.go b/exporter/exporter.go index 98329fdcf05..1b8a55b1f92 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -30,6 +30,12 @@ type Logs interface { consumer.Logs } +// Entities is an exporter that can consume entities. +type Entities interface { + component.Component + consumer.Entities +} + // Settings configures exporter creators. type Settings struct { // ID returns the ID of the component that will be created. @@ -90,6 +96,14 @@ type Factory interface { // Deprecated: [v0.112.0] use LogsStability. LogsExporterStability() component.StabilityLevel + // CreateEntities creates an EntitiesExporter based on the config. + // If the exporter type does not support entities, + // this function returns the error [pipeline.ErrSignalNotSupported]. + CreateEntities(ctx context.Context, set Settings, cfg component.Config) (Entities, error) + + // EntityExporterStability gets the stability level of the EntityExporter. + EntityExporterStability() component.StabilityLevel + unexportedFactoryFunc() } @@ -156,6 +170,17 @@ func (f CreateLogsFunc) CreateLogsExporter(ctx context.Context, set Settings, cf return f.CreateLogs(ctx, set, cfg) } +// CreateEntitiesFunc is the equivalent of Factory.CreateEntities. +type CreateEntitiesFunc func(context.Context, Settings, component.Config) (Entities, error) + +// CreateEntities implements Factory.CreateEntities. +func (f CreateEntitiesFunc) CreateEntities(ctx context.Context, set Settings, cfg component.Config) (Entities, error) { + if f == nil { + return nil, pipeline.ErrSignalNotSupported + } + return f(ctx, set, cfg) +} + type factory struct { cfgType component.Type component.CreateDefaultConfigFunc @@ -165,6 +190,8 @@ type factory struct { metricsStabilityLevel component.StabilityLevel CreateLogsFunc logsStabilityLevel component.StabilityLevel + CreateEntitiesFunc + entitiesStabilityLevel component.StabilityLevel } func (f *factory) Type() component.Type { @@ -200,7 +227,11 @@ func (f *factory) LogsExporterStability() component.StabilityLevel { return f.logsStabilityLevel } -// WithTraces overrides the default "error not supported" implementation for Factory.CreateTraces and the default "undefined" stability level. +func (f *factory) EntityExporterStability() component.StabilityLevel { + return f.entitiesStabilityLevel +} + +// WithTraces overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level. func WithTraces(createTraces CreateTracesFunc, sl component.StabilityLevel) FactoryOption { return factoryOptionFunc(func(o *factory) { o.tracesStabilityLevel = sl @@ -224,6 +255,14 @@ func WithLogs(createLogs CreateLogsFunc, sl component.StabilityLevel) FactoryOpt }) } +// WithEntities overrides the default "error not supported" implementation for CreateEntities and the default "undefined" stability level. +func WithEntities(createEntities CreateEntitiesFunc, sl component.StabilityLevel) FactoryOption { + return factoryOptionFunc(func(o *factory) { + o.entitiesStabilityLevel = sl + o.CreateEntitiesFunc = createEntities + }) +} + // NewFactory returns a Factory. func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory { f := &factory{ diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index b849b3a05e6..1a26368ad8b 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -26,8 +26,10 @@ func TestNewFactory(t *testing.T) { require.Error(t, err) _, err = factory.CreateMetrics(context.Background(), Settings{}, &defaultCfg) require.Error(t, err) - _, err = factory.CreateLogs(context.Background(), Settings{}, &defaultCfg) - assert.Error(t, err) + _, err = factory.CreateLogsExporter(context.Background(), Settings{}, &defaultCfg) + require.Error(t, err) + _, err = factory.CreateEntities(context.Background(), Settings{}, &defaultCfg) + require.Error(t, err) } func TestNewFactoryWithOptions(t *testing.T) { diff --git a/exporter/internal/entities.go b/exporter/internal/entities.go new file mode 100644 index 00000000000..b7cfb5076fa --- /dev/null +++ b/exporter/internal/entities.go @@ -0,0 +1,15 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package internal // import "go.opentelemetry.io/collector/exporter/internal" + +import ( + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/consumer" +) + +// Profiles is an exporter that can consume profiles. +type Entities interface { + component.Component + consumer.Entities +} diff --git a/pdata/internal/cmd/pdatagen/internal/base_fields.go b/pdata/internal/cmd/pdatagen/internal/base_fields.go index 7808e6b9820..cdfcd0a3b13 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_fields.go +++ b/pdata/internal/cmd/pdatagen/internal/base_fields.go @@ -329,8 +329,8 @@ func (sf *sliceField) templateFields(ms *messageValueStruct) map[string]any { return "" }(), "returnType": sf.returnSlice.getName(), - "origAccessor": origAccessor(ms), - "stateAccessor": stateAccessor(ms), + "origAccessor": origAccessor(ms.packageName), + "stateAccessor": stateAccessor(ms.packageName), "isCommon": usedByOtherDataTypes(sf.returnSlice.getPackageName()), "isBaseStructCommon": usedByOtherDataTypes(ms.packageName), "originFieldName": func() string { @@ -394,8 +394,8 @@ func (mf *messageValueField) templateFields(ms *messageValueStruct) map[string]a } return "" }(), - "origAccessor": origAccessor(ms), - "stateAccessor": stateAccessor(ms), + "origAccessor": origAccessor(ms.packageName), + "stateAccessor": stateAccessor(ms.packageName), } } @@ -448,8 +448,8 @@ func (pf *primitiveField) templateFields(ms *messageValueStruct) map[string]any "lowerFieldName": strings.ToLower(pf.fieldName), "testValue": pf.testVal, "returnType": pf.returnType, - "origAccessor": origAccessor(ms), - "stateAccessor": stateAccessor(ms), + "origAccessor": origAccessor(ms.packageName), + "stateAccessor": stateAccessor(ms.packageName), "originStructName": ms.originFullName, "originFieldName": func() string { if pf.originFieldName == "" { @@ -583,8 +583,8 @@ func (psf *primitiveSliceField) templateFields(ms *messageValueStruct) map[strin "fieldName": psf.fieldName, "lowerFieldName": strings.ToLower(psf.fieldName), "testValue": psf.testVal, - "origAccessor": origAccessor(ms), - "stateAccessor": stateAccessor(ms), + "origAccessor": origAccessor(ms.packageName), + "stateAccessor": stateAccessor(ms.packageName), } } @@ -647,8 +647,8 @@ func (of *oneOfField) templateFields(ms *messageValueStruct) map[string]any { "typeName": of.typeName, "originFieldName": of.originFieldName, "lowerOriginFieldName": strings.ToLower(of.originFieldName), - "origAccessor": origAccessor(ms), - "stateAccessor": stateAccessor(ms), + "origAccessor": origAccessor(ms.packageName), + "stateAccessor": stateAccessor(ms.packageName), "values": of.values, "originTypePrefix": ms.originFullName + "_", } @@ -846,15 +846,15 @@ func (opv *optionalPrimitiveValue) templateFields(ms *messageValueStruct) map[st var _ baseField = (*optionalPrimitiveValue)(nil) -func origAccessor(bs *messageValueStruct) string { - if usedByOtherDataTypes(bs.packageName) { +func origAccessor(packageName string) string { + if usedByOtherDataTypes(packageName) { return "getOrig()" } return "orig" } -func stateAccessor(bs *messageValueStruct) string { - if usedByOtherDataTypes(bs.packageName) { +func stateAccessor(packageName string) string { + if usedByOtherDataTypes(packageName) { return "getState()" } return "state" diff --git a/pdata/internal/cmd/pdatagen/internal/base_slices.go b/pdata/internal/cmd/pdatagen/internal/base_slices.go index 24c648de9f2..30c4ca5a76c 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_slices.go +++ b/pdata/internal/cmd/pdatagen/internal/base_slices.go @@ -44,22 +44,31 @@ func (ss *sliceOfPtrs) generateTests(packageInfo *PackageInfo) []byte { } func (ss *sliceOfPtrs) templateFields(packageInfo *PackageInfo) map[string]any { + orig := origAccessor(ss.packageName) + state := stateAccessor(ss.packageName) return map[string]any{ "type": "sliceOfPtrs", + "isCommon": usedByOtherDataTypes(ss.packageName), "structName": ss.structName, "elementName": ss.element.structName, "originName": ss.element.originFullName, "originElementType": "*" + ss.element.originFullName, "emptyOriginElement": "&" + ss.element.originFullName + "{}", - "newElement": "new" + ss.element.structName + "((*es.orig)[i], es.state)", + "newElement": "new" + ss.element.structName + "((*es." + orig + ")[i], es." + state + ")", + "origAccessor": orig, + "stateAccessor": state, "packageName": packageInfo.name, "imports": packageInfo.imports, "testImports": packageInfo.testImports, } } -func (ss *sliceOfPtrs) generateInternal(*PackageInfo) []byte { - return nil +func (ss *sliceOfPtrs) generateInternal(packageInfo *PackageInfo) []byte { + var sb bytes.Buffer + if err := sliceInternalTemplate.Execute(&sb, ss.templateFields(packageInfo)); err != nil { + panic(err) + } + return sb.Bytes() } var _ baseStruct = (*sliceOfPtrs)(nil) @@ -104,14 +113,20 @@ func (ss *sliceOfValues) templateFields(packageInfo *PackageInfo) map[string]any "originElementType": ss.element.originFullName, "emptyOriginElement": ss.element.originFullName + "{}", "newElement": "new" + ss.element.structName + "(&(*es.orig)[i], es.state)", + "origAccessor": origAccessor(ss.packageName), + "stateAccessor": stateAccessor(ss.packageName), "packageName": packageInfo.name, "imports": packageInfo.imports, "testImports": packageInfo.testImports, } } -func (ss *sliceOfValues) generateInternal(*PackageInfo) []byte { - return nil +func (ss *sliceOfValues) generateInternal(packageInfo *PackageInfo) []byte { + var sb bytes.Buffer + if err := sliceInternalTemplate.Execute(&sb, ss.templateFields(packageInfo)); err != nil { + panic(err) + } + return sb.Bytes() } var _ baseStruct = (*sliceOfValues)(nil) diff --git a/pdata/internal/cmd/pdatagen/internal/base_structs.go b/pdata/internal/cmd/pdatagen/internal/base_structs.go index 4cd7832f12d..74dc95d1fca 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/base_structs.go @@ -58,18 +58,13 @@ func (ms *messageValueStruct) templateFields(packageInfo *PackageInfo) map[strin "fields": ms.fields, "structName": ms.structName, "originName": ms.originFullName, - "generateTestData": func() string { - if usedByOtherDataTypes(ms.packageName) { - return ms.structName + "(internal.GenerateTest" + ms.structName + "())" - } - return "generateTest" + ms.structName + "()" - }(), - "description": ms.description, - "isCommon": usedByOtherDataTypes(ms.packageName), - "origAccessor": origAccessor(ms), - "packageName": packageInfo.name, - "imports": packageInfo.imports, - "testImports": packageInfo.testImports, + "description": ms.description, + "isCommon": usedByOtherDataTypes(ms.packageName), + "origAccessor": origAccessor(ms.packageName), + "stateAccessor": stateAccessor(ms.packageName), + "packageName": packageInfo.name, + "imports": packageInfo.imports, + "testImports": packageInfo.testImports, } } diff --git a/pdata/internal/cmd/pdatagen/internal/packages.go b/pdata/internal/cmd/pdatagen/internal/packages.go index 47708bc975e..7bec8f0e053 100644 --- a/pdata/internal/cmd/pdatagen/internal/packages.go +++ b/pdata/internal/cmd/pdatagen/internal/packages.go @@ -18,6 +18,8 @@ const header = `// Copyright The OpenTelemetry Authors // AllPackages is a list of all packages that needs to be generated. var AllPackages = []*Package{ pcommon, + pentity, + pentityotlp, plog, plogotlp, pmetric, diff --git a/pdata/internal/cmd/pdatagen/internal/pcommon_package.go b/pdata/internal/cmd/pdatagen/internal/pcommon_package.go index d6085334f56..cb9ce82f495 100644 --- a/pdata/internal/cmd/pdatagen/internal/pcommon_package.go +++ b/pdata/internal/cmd/pdatagen/internal/pcommon_package.go @@ -23,6 +23,8 @@ var pcommon = &Package{ structs: []baseStruct{ scope, resource, + entityRefSlice, + entityRef, byteSlice, float64Slice, uInt64Slice, @@ -159,6 +161,10 @@ var resource = &messageValueStruct{ fields: []baseField{ attributes, droppedAttributesCount, + &sliceField{ + fieldName: "Entities", + returnSlice: entityRefSlice, + }, }, } @@ -167,6 +173,35 @@ var resourceField = &messageValueField{ returnMessage: resource, } +var entityRefSlice = &sliceOfPtrs{ + structName: "ResourceEntityRefSlice", + packageName: "pcommon", + element: entityRef, +} + +var entityRef = &messageValueStruct{ + structName: "ResourceEntityRef", + packageName: "pcommon", + originFullName: "otlpresource.ResourceEntityRef", + fields: []baseField{ + schemaURLField, + &primitiveField{ + fieldName: "Type", + returnType: "string", + defaultVal: `""`, + testVal: `"host"`, + }, + &sliceField{ + fieldName: "IdAttrKeys", + returnSlice: stringSlice, + }, + &sliceField{ + fieldName: "DescrAttrKeys", + returnSlice: stringSlice, + }, + }, +} + var byteSlice = &primitiveSliceStruct{ structName: "ByteSlice", packageName: "pcommon", diff --git a/pdata/internal/cmd/pdatagen/internal/pentity_package.go b/pdata/internal/cmd/pdatagen/internal/pentity_package.go new file mode 100644 index 00000000000..5fe4f5b4dd9 --- /dev/null +++ b/pdata/internal/cmd/pdatagen/internal/pentity_package.go @@ -0,0 +1,122 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package internal // import "go.opentelemetry.io/collector/pdata/internal/cmd/pdatagen/internal" + +var pentity = &Package{ + info: &PackageInfo{ + name: "pentity", + path: "pentity", + imports: []string{ + `"sort"`, + ``, + `"go.opentelemetry.io/collector/pdata/internal"`, + `"go.opentelemetry.io/collector/pdata/internal/data"`, + `otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1"`, + `"go.opentelemetry.io/collector/pdata/pcommon"`, + }, + testImports: []string{ + `"testing"`, + `"unsafe"`, + ``, + `"github.com/stretchr/testify/assert"`, + ``, + `"go.opentelemetry.io/collector/pdata/internal"`, + `"go.opentelemetry.io/collector/pdata/internal/data"`, + `otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1"`, + `"go.opentelemetry.io/collector/pdata/pcommon"`, + }, + }, + structs: []baseStruct{ + scopeEntitiesSlice, + scopeEntities, + entityEventSlice, + entityEvent, + entityState, + entityDelete, + }, +} + +var scopeEntitiesSlice = &sliceOfPtrs{ + structName: "ScopeEntitiesSlice", + element: scopeEntities, +} + +var scopeEntities = &messageValueStruct{ + structName: "ScopeEntities", + description: "// ScopeEntities is a collection of entities from a LibraryInstrumentation.", + originFullName: "otlpentities.ScopeEntities", + fields: []baseField{ + scopeField, + schemaURLField, + &sliceField{ + fieldName: "EntityEvents", + returnSlice: entityEventSlice, + }, + }, +} + +var entityEventSlice = &sliceOfPtrs{ + structName: "EntityEventSlice", + element: entityEvent, +} + +var entityEvent = &messageValueStruct{ + structName: "EntityEvent", + description: "// EntityEvent are experimental implementation of OpenTelemetry Entity Data Model.\n", + originFullName: "otlpentities.EntityEvent", + fields: []baseField{ + &primitiveTypedField{ + fieldName: "Timestamp", + originFieldName: "TimeUnixNano", + returnType: timestampType, + }, + &primitiveField{ + fieldName: "EntityType", + returnType: "string", + defaultVal: `""`, + testVal: `"service"`, + }, + entityID, + &oneOfField{ + typeName: "EventType", + originFieldName: "Data", + testValueIdx: 1, // Delete + omitOriginFieldNameInNames: true, + values: []oneOfValue{ + &oneOfMessageValue{ + fieldName: "EntityState", + originFieldPackageName: "otlpentities", + returnMessage: entityState, + }, + &oneOfMessageValue{ + fieldName: "EntityDelete", + originFieldPackageName: "otlpentities", + returnMessage: entityDelete, + }, + }, + }, + }, +} + +var entityID = &sliceField{ + fieldName: "Id", + returnSlice: mapStruct, +} + +var entityState = &messageValueStruct{ + structName: "EntityState", + description: "// EntityState are experimental implementation of OpenTelemetry Entity Data Model.\n", + originFullName: "otlpentities.EntityState", + fields: []baseField{ + attributes, + droppedAttributesCount, + }, +} + +var entityDelete = &messageValueStruct{ + structName: "EntityDelete", + description: "// EntityDelete are experimental implementation of OpenTelemetry Entity Data Model.\n", + originFullName: "otlpentities.EntityDelete", + fields: []baseField{}, +} diff --git a/pdata/internal/cmd/pdatagen/internal/pentityotlp_package.go b/pdata/internal/cmd/pdatagen/internal/pentityotlp_package.go new file mode 100644 index 00000000000..ff41202d3b9 --- /dev/null +++ b/pdata/internal/cmd/pdatagen/internal/pentityotlp_package.go @@ -0,0 +1,45 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package internal // import "go.opentelemetry.io/collector/pdata/internal/cmd/pdatagen/internal" +import ( + "path/filepath" +) + +var pentityotlp = &Package{ + info: &PackageInfo{ + name: "pentityotlp", + path: filepath.Join("pentity", "pentityotlp"), + imports: []string{ + `otlpcollectorentity "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/entities/v1"`, + }, + testImports: []string{ + `"testing"`, + ``, + `"github.com/stretchr/testify/assert"`, + }, + }, + structs: []baseStruct{ + exportEntitiesPartialSuccess, + }, +} + +var exportEntitiesPartialSuccess = &messageValueStruct{ + structName: "ExportPartialSuccess", + description: "// ExportPartialSuccess represents the details of a partially successful export request.", + originFullName: "otlpcollectorentity.ExportEntitiesPartialSuccess", + fields: []baseField{ + &primitiveField{ + fieldName: "RejectedEntities", + returnType: "int64", + defaultVal: `int64(0)`, + testVal: `int64(13)`, + }, + &primitiveField{ + fieldName: "ErrorMessage", + returnType: "string", + defaultVal: `""`, + testVal: `"error message"`, + }, + }, +} diff --git a/pdata/internal/cmd/pdatagen/internal/templates.go b/pdata/internal/cmd/pdatagen/internal/templates.go index e7218752979..5441d39bbe8 100644 --- a/pdata/internal/cmd/pdatagen/internal/templates.go +++ b/pdata/internal/cmd/pdatagen/internal/templates.go @@ -37,6 +37,10 @@ var ( sliceTemplateBytes []byte sliceTemplate = parseTemplate("slice.go", sliceTemplateBytes) + //go:embed templates/slice_internal.go.tmpl + sliceInternalTemplateBytes []byte + sliceInternalTemplate = parseTemplate("slice_internal.go", sliceInternalTemplateBytes) + //go:embed templates/slice_test.go.tmpl sliceTestTemplateBytes []byte sliceTestTemplate = parseTemplate("slice_test.go", sliceTestTemplateBytes) diff --git a/pdata/internal/cmd/pdatagen/internal/templates/message.go.tmpl b/pdata/internal/cmd/pdatagen/internal/templates/message.go.tmpl index d7e93b9f31d..b6486fbe48a 100644 --- a/pdata/internal/cmd/pdatagen/internal/templates/message.go.tmpl +++ b/pdata/internal/cmd/pdatagen/internal/templates/message.go.tmpl @@ -48,8 +48,8 @@ func New{{ .structName }}() {{ .structName }} { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms {{ .structName }}) MoveTo(dest {{ .structName }}) { - ms.{{- if .isCommon }}getState(){{ else }}state{{ end }}.AssertMutable() - dest.{{- if .isCommon }}getState(){{ else }}state{{ end }}.AssertMutable() + ms.{{ .stateAccessor }}.AssertMutable() + dest.{{ .stateAccessor }}.AssertMutable() *dest.{{ .origAccessor }} = *ms.{{ .origAccessor }} *ms.{{ .origAccessor }} = {{ .originName }}{} } @@ -70,7 +70,7 @@ func (ms {{ .structName }}) getState() *internal.State { // CopyTo copies all properties from the current struct overriding the destination. func (ms {{ .structName }}) CopyTo(dest {{ .structName }}) { - dest.{{- if .isCommon }}getState(){{ else }}state{{ end }}.AssertMutable() + dest.{{ .stateAccessor }}.AssertMutable() {{- range .fields }} {{ .GenerateCopyToValue $.messageStruct }} {{- end }} diff --git a/pdata/internal/cmd/pdatagen/internal/templates/message_test.go.tmpl b/pdata/internal/cmd/pdatagen/internal/templates/message_test.go.tmpl index ff96aa71718..2c78569b158 100644 --- a/pdata/internal/cmd/pdatagen/internal/templates/message_test.go.tmpl +++ b/pdata/internal/cmd/pdatagen/internal/templates/message_test.go.tmpl @@ -13,11 +13,11 @@ import ( ) func Test{{ .structName }}_MoveTo(t *testing.T) { - ms := {{ .generateTestData }} + ms := generateTest{{ .structName }}() dest := New{{ .structName }}() ms.MoveTo(dest) assert.Equal(t, New{{ .structName }}(), ms) - assert.Equal(t, {{ .generateTestData }}, dest) + assert.Equal(t, generateTest{{ .structName }}(), dest) sharedState := internal.StateReadOnly assert.Panics(t, func() { ms.MoveTo(new{{ .structName }}(&{{ .originName }}{}, &sharedState)) }) assert.Panics(t, func() { new{{ .structName }}(&{{ .originName }}{}, &sharedState).MoveTo(dest) }) @@ -28,7 +28,7 @@ func Test{{ .structName }}_CopyTo(t *testing.T) { orig := New{{ .structName }}() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = {{ .generateTestData }} + orig = generateTest{{ .structName }}() orig.CopyTo(ms) assert.Equal(t, orig, ms) sharedState := internal.StateReadOnly @@ -39,13 +39,17 @@ func Test{{ .structName }}_CopyTo(t *testing.T) { {{ .GenerateAccessorsTest $.messageStruct }} {{ end }} -{{- if not .isCommon }} func generateTest{{ .structName }}() {{ .structName }} { + {{- if .isCommon }} + return {{ .structName }}(internal.GenerateTest{{ .structName }}()) + {{- else }} tv := New{{ .structName }}() fillTest{{ .structName }}(tv) return tv + {{- end }} } +{{ if not .isCommon -}} func fillTest{{ .structName }}(tv {{ .structName }}) { {{- range .fields }} {{ .GenerateSetWithTestValue $.messageStruct }} diff --git a/pdata/internal/cmd/pdatagen/internal/templates/slice.go.tmpl b/pdata/internal/cmd/pdatagen/internal/templates/slice.go.tmpl index 082c6c18cce..5028ba8300e 100644 --- a/pdata/internal/cmd/pdatagen/internal/templates/slice.go.tmpl +++ b/pdata/internal/cmd/pdatagen/internal/templates/slice.go.tmpl @@ -19,13 +19,21 @@ import ( // // Must use New{{ .structName }} function to create new instances. // Important: zero-initialized instance is not valid for use. +{{- if .isCommon }} +type {{ .structName }} internal.{{ .structName }} +{{- else }} type {{ .structName }} struct { orig *[]{{ .originElementType }} state *internal.State } +{{- end }} func new{{ .structName }}(orig *[]{{ .originElementType }}, state *internal.State) {{ .structName }} { + {{- if .isCommon }} + return {{ .structName }}(internal.New{{ .structName }}(orig, state)) + {{- else }} return {{ .structName }}{orig: orig, state: state} + {{- end }} } // New{{ .structName }} creates a {{ .structName }} with 0 elements. @@ -40,7 +48,7 @@ func New{{ .structName }}() {{ .structName }} { // // Returns "0" for a newly instance created with "New{{ .structName }}()". func (es {{ .structName }}) Len() int { - return len(*es.orig) + return len(*es.{{ .origAccessor }}) } // At returns the element at the given index. @@ -66,45 +74,45 @@ func (es {{ .structName }}) At(i int) {{ .elementName }} { // // Here should set all the values for e. // } func (es {{ .structName }}) EnsureCapacity(newCap int) { - es.state.AssertMutable() - oldCap := cap(*es.orig) + es.{{ .stateAccessor }}.AssertMutable() + oldCap := cap(*es.{{ .origAccessor }}) if newCap <= oldCap { return } - newOrig := make([]{{ .originElementType }}, len(*es.orig), newCap) - copy(newOrig, *es.orig) - *es.orig = newOrig + newOrig := make([]{{ .originElementType }}, len(*es.{{ .origAccessor }}), newCap) + copy(newOrig, *es.{{ .origAccessor }}) + *es.{{ .origAccessor }} = newOrig } // AppendEmpty will append to the end of the slice an empty {{ .elementName }}. // It returns the newly added {{ .elementName }}. func (es {{ .structName }}) AppendEmpty() {{ .elementName }} { - es.state.AssertMutable() - *es.orig = append(*es.orig, {{ .emptyOriginElement }}) + es.{{ .stateAccessor }}.AssertMutable() + *es.{{ .origAccessor }} = append(*es.{{ .origAccessor }}, {{ .emptyOriginElement }}) return es.At(es.Len() - 1) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es {{ .structName }}) MoveAndAppendTo(dest {{ .structName }}) { - es.state.AssertMutable() - dest.state.AssertMutable() - if *dest.orig == nil { + es.{{ .stateAccessor }}.AssertMutable() + dest.{{ .stateAccessor }}.AssertMutable() + if *dest.{{ .origAccessor }} == nil { // We can simply move the entire vector and avoid any allocations. - *dest.orig = *es.orig + *dest.{{ .origAccessor }} = *es.{{ .origAccessor }} } else { - *dest.orig = append(*dest.orig, *es.orig...) + *dest.{{ .origAccessor }} = append(*dest.{{ .origAccessor }}, *es.{{ .origAccessor }}...) } - *es.orig = nil + *es.{{ .origAccessor }} = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es {{ .structName }}) RemoveIf(f func({{ .elementName }}) bool) { - es.state.AssertMutable() + es.{{ .stateAccessor }}.AssertMutable() newLen := 0 - for i := 0; i < len(*es.orig); i++ { + for i := 0; i < len(*es.{{ .origAccessor }}); i++ { if f(es.At(i)) { continue } @@ -113,41 +121,41 @@ func (es {{ .structName }}) RemoveIf(f func({{ .elementName }}) bool) { newLen++ continue } - (*es.orig)[newLen] = (*es.orig)[i] + (*es.{{ .origAccessor }})[newLen] = (*es.{{ .origAccessor }})[i] newLen++ } - *es.orig = (*es.orig)[:newLen] + *es.{{ .origAccessor }} = (*es.{{ .origAccessor }})[:newLen] } // CopyTo copies all elements from the current slice overriding the destination. func (es {{ .structName }}) CopyTo(dest {{ .structName }}) { - dest.state.AssertMutable() + dest.{{ .stateAccessor }}.AssertMutable() srcLen := es.Len() - destCap := cap(*dest.orig) + destCap := cap(*dest.{{ .origAccessor }}) if srcLen <= destCap { - (*dest.orig) = (*dest.orig)[:srcLen:destCap] + (*dest.{{ .origAccessor }}) = (*dest.{{ .origAccessor }})[:srcLen:destCap] {{- if eq .type "sliceOfPtrs" }} - for i := range *es.orig { - new{{ .elementName }}((*es.orig)[i], es.state).CopyTo(new{{ .elementName }}((*dest.orig)[i], dest.state)) + for i := range *es.{{ .origAccessor }} { + new{{ .elementName }}((*es.{{ .origAccessor }})[i], es.{{ .stateAccessor }}).CopyTo(new{{ .elementName }}((*dest.{{ .origAccessor }})[i], dest.{{ .stateAccessor }})) } return } origs := make([]{{ .originName }}, srcLen) wrappers := make([]*{{ .originName }}, srcLen) - for i := range *es.orig { + for i := range *es.{{ .origAccessor }} { wrappers[i] = &origs[i] - new{{ .elementName }}((*es.orig)[i], es.state).CopyTo(new{{ .elementName }}(wrappers[i], dest.state)) + new{{ .elementName }}((*es.{{ .origAccessor }})[i], es.{{ .stateAccessor }}).CopyTo(new{{ .elementName }}(wrappers[i], dest.{{ .stateAccessor }})) } - *dest.orig = wrappers + *dest.{{ .origAccessor }} = wrappers {{- else }} } else { - (*dest.orig) = make([]{{ .originElementType }}, srcLen) + (*dest.{{ .origAccessor }}) = make([]{{ .originElementType }}, srcLen) } - for i := range *es.orig { - {{ .newElement }}.CopyTo(new{{ .elementName }}(&(*dest.orig)[i], dest.state)) + for i := range *es.{{ .origAccessor }} { + {{ .newElement }}.CopyTo(new{{ .elementName }}(&(*dest.{{ .origAccessor }})[i], dest.{{ .stateAccessor }})) } {{- end }} } @@ -157,7 +165,17 @@ func (es {{ .structName }}) CopyTo(dest {{ .structName }}) { // provided less function so that two instances of {{ .structName }} // can be compared. func (es {{ .structName }}) Sort(less func(a, b {{ .elementName }}) bool) { - es.state.AssertMutable() - sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) + es.{{ .stateAccessor }}.AssertMutable() + sort.SliceStable(*es.{{ .origAccessor }}, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } -{{ end }} +{{- end }} + +{{ if .isCommon -}} +func (ms {{ .structName }}) getOrig() *[]{{ .originElementType }} { + return internal.GetOrig{{ .structName }}(internal.{{ .structName }}(ms)) +} + +func (ms {{ .structName }}) getState() *internal.State { + return internal.Get{{ .structName }}State(internal.{{ .structName }}(ms)) +} +{{- end }} \ No newline at end of file diff --git a/pdata/internal/cmd/pdatagen/internal/templates/slice_internal.go.tmpl b/pdata/internal/cmd/pdatagen/internal/templates/slice_internal.go.tmpl new file mode 100644 index 00000000000..20a3eb7e926 --- /dev/null +++ b/pdata/internal/cmd/pdatagen/internal/templates/slice_internal.go.tmpl @@ -0,0 +1,49 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package internal + +import ( + {{ range $index, $element := .imports -}} + {{ if ne $element `"go.opentelemetry.io/collector/pdata/internal"` }} + {{ $element }} + {{ end }} + {{ end }} +) + + +type {{ .structName }} struct { + orig *[]{{ .originElementType }} + state *State +} + +func GetOrig{{ .structName }}(ms {{ .structName }}) *[]{{ .originElementType }} { + return ms.orig +} + +func Get{{ .structName }}State(ms {{ .structName }}) *State { + return ms.state +} + +func New{{ .structName }}(orig *[]{{ .originElementType }}, state *State) {{ .structName }} { + return {{ .structName }}{orig: orig, state: state} +} + +func GenerateTest{{ .structName }}() {{ .structName }} { + orig := []{{ .originElementType }}(nil) + state := StateMutable + es := New{{ .structName }}(&orig, &state) + FillTest{{ .structName }}(es) + return es +} + +func FillTest{{ .structName }}(es {{ .structName }}) { + *es.orig = make([]{{ .originElementType }}, 7) + for i := 0; i < 7; i++ { + (*es.orig)[i] = {{ .emptyOriginElement }} + FillTest{{ .elementName }}(New{{ .elementName }}((*es.orig)[i], es.state)) + } +} \ No newline at end of file diff --git a/pdata/internal/cmd/pdatagen/internal/templates/slice_test.go.tmpl b/pdata/internal/cmd/pdatagen/internal/templates/slice_test.go.tmpl index 8b947a5ac8b..fc96a9c62f7 100644 --- a/pdata/internal/cmd/pdatagen/internal/templates/slice_test.go.tmpl +++ b/pdata/internal/cmd/pdatagen/internal/templates/slice_test.go.tmpl @@ -20,11 +20,19 @@ func Test{{ .structName }}(t *testing.T) { assert.Equal(t, 0, es.Len()) emptyVal := New{{ .elementName }}() + {{- if .isCommon }} + testVal := {{ .elementName }}(internal.GenerateTest{{ .elementName }}()) + {{- else }} testVal := generateTest{{ .elementName }}() + {{- end }} for i := 0; i < 7; i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, es.At(i)) + {{- if .isCommon }} + internal.FillTest{{ .elementName }}(internal.{{ .elementName }}(el)) + {{- else }} fillTest{{ .elementName }}(el) + {{- end }} assert.Equal(t, testVal, es.At(i)) } assert.Equal(t, 7, es.Len()) @@ -65,14 +73,14 @@ func Test{{ .structName }}_EnsureCapacity(t *testing.T) { const ensureSmallLen = 4 es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) - assert.Equal(t, es.Len(), cap(*es.orig)) + assert.Equal(t, es.Len(), cap(*es.{{ .origAccessor }})) assert.Equal(t, generateTest{{ .structName }}(), es) // Test ensure larger capacity const ensureLargeLen = 9 es.EnsureCapacity(ensureLargeLen) assert.Less(t, generateTest{{ .structName }}().Len(), ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.orig)) + assert.Equal(t, ensureLargeLen, cap(*es.{{ .origAccessor }})) assert.Equal(t, generateTest{{ .structName }}(), es) } @@ -123,26 +131,31 @@ func Test{{ .structName }}_RemoveIf(t *testing.T) { func Test{{ .structName }}_Sort(t *testing.T) { es := generateTest{{ .structName }}() es.Sort(func(a, b {{ .elementName }}) bool { - return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + return uintptr(unsafe.Pointer(a.{{ .origAccessor }})) < uintptr(unsafe.Pointer(b.{{ .origAccessor }})) }) for i := 1; i < es.Len(); i++ { - assert.Less(t, uintptr(unsafe.Pointer(es.At(i-1).orig)), uintptr(unsafe.Pointer(es.At(i).orig))) + assert.Less(t, uintptr(unsafe.Pointer(es.At(i-1).{{ .origAccessor }})), uintptr(unsafe.Pointer(es.At(i).{{ .origAccessor }}))) } es.Sort(func(a, b {{ .elementName }}) bool { - return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + return uintptr(unsafe.Pointer(a.{{ .origAccessor }})) > uintptr(unsafe.Pointer(b.{{ .origAccessor }})) }) for i := 1; i < es.Len(); i++ { - assert.Greater(t, uintptr(unsafe.Pointer(es.At(i-1).orig)), uintptr(unsafe.Pointer(es.At(i).orig))) + assert.Greater(t, uintptr(unsafe.Pointer(es.At(i-1).{{ .origAccessor }})), uintptr(unsafe.Pointer(es.At(i).{{ .origAccessor }}))) } } {{- end }} func generateTest{{ .structName }}() {{ .structName }} { + {{- if .isCommon }} + return {{ .structName }}(internal.GenerateTest{{ .structName }}()) + {{- else }} es := New{{ .structName }}() fillTest{{ .structName }}(es) return es + {{- end }} } +{{ if not .isCommon -}} func fillTest{{ .structName }}(es {{ .structName }}) { *es.orig = make([]{{ .originElementType }}, 7) for i := 0; i < 7; i++ { @@ -150,3 +163,4 @@ func fillTest{{ .structName }}(es {{ .structName }}) { fillTest{{ .elementName }}({{ .newElement }}) } } +{{- end }} diff --git a/pdata/internal/data/protogen/collector/entities/v1/entities_service.pb.go b/pdata/internal/data/protogen/collector/entities/v1/entities_service.pb.go new file mode 100644 index 00000000000..7a190a740e0 --- /dev/null +++ b/pdata/internal/data/protogen/collector/entities/v1/entities_service.pb.go @@ -0,0 +1,840 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: opentelemetry/proto/collector/entities/v1/entities_service.proto + +package v1 + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + + v1 "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type ExportEntitiesServiceRequest struct { + // An array of ResourceEntities. + ScopeEntities []*v1.ScopeEntities `protobuf:"bytes,1,rep,name=scope_entities,json=scopeEntities,proto3" json:"scope_entities,omitempty"` +} + +func (m *ExportEntitiesServiceRequest) Reset() { *m = ExportEntitiesServiceRequest{} } +func (m *ExportEntitiesServiceRequest) String() string { return proto.CompactTextString(m) } +func (*ExportEntitiesServiceRequest) ProtoMessage() {} +func (*ExportEntitiesServiceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_fbd01640b6ae8848, []int{0} +} +func (m *ExportEntitiesServiceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ExportEntitiesServiceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ExportEntitiesServiceRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ExportEntitiesServiceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ExportEntitiesServiceRequest.Merge(m, src) +} +func (m *ExportEntitiesServiceRequest) XXX_Size() int { + return m.Size() +} +func (m *ExportEntitiesServiceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ExportEntitiesServiceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ExportEntitiesServiceRequest proto.InternalMessageInfo + +func (m *ExportEntitiesServiceRequest) GetScopeEntities() []*v1.ScopeEntities { + if m != nil { + return m.ScopeEntities + } + return nil +} + +type ExportEntitiesServiceResponse struct { + // The details of a partially successful export request. + // + // If the request is only partially accepted + // (i.e. when the server accepts only parts of the data and rejects the rest) + // the server MUST initialize the `partial_success` field and MUST + // set the `rejected_` with the number of items it rejected. + // + // Servers MAY also make use of the `partial_success` field to convey + // warnings/suggestions to senders even when the request was fully accepted. + // In such cases, the `rejected_` MUST have a value of `0` and + // the `error_message` MUST be non-empty. + // + // A `partial_success` message with an empty value (rejected_ = 0 and + // `error_message` = "") is equivalent to it not being set/present. Senders + // SHOULD interpret it the same way as in the full success case. + PartialSuccess ExportEntitiesPartialSuccess `protobuf:"bytes,1,opt,name=partial_success,json=partialSuccess,proto3" json:"partial_success"` +} + +func (m *ExportEntitiesServiceResponse) Reset() { *m = ExportEntitiesServiceResponse{} } +func (m *ExportEntitiesServiceResponse) String() string { return proto.CompactTextString(m) } +func (*ExportEntitiesServiceResponse) ProtoMessage() {} +func (*ExportEntitiesServiceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_fbd01640b6ae8848, []int{1} +} +func (m *ExportEntitiesServiceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ExportEntitiesServiceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ExportEntitiesServiceResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ExportEntitiesServiceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ExportEntitiesServiceResponse.Merge(m, src) +} +func (m *ExportEntitiesServiceResponse) XXX_Size() int { + return m.Size() +} +func (m *ExportEntitiesServiceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ExportEntitiesServiceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ExportEntitiesServiceResponse proto.InternalMessageInfo + +func (m *ExportEntitiesServiceResponse) GetPartialSuccess() ExportEntitiesPartialSuccess { + if m != nil { + return m.PartialSuccess + } + return ExportEntitiesPartialSuccess{} +} + +type ExportEntitiesPartialSuccess struct { + // The number of rejected log records. + // + // A `rejected_` field holding a `0` value indicates that the + // request was fully accepted. + RejectedEntities int64 `protobuf:"varint,1,opt,name=rejected_entities,json=rejectedEntities,proto3" json:"rejected_entities,omitempty"` + // A developer-facing human-readable message in English. It should be used + // either to explain why the server rejected parts of the data during a partial + // success or to convey warnings/suggestions during a full success. The message + // should offer guidance on how users can address such issues. + // + // error_message is an optional field. An error_message with an empty value + // is equivalent to it not being set. + ErrorMessage string `protobuf:"bytes,2,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"` +} + +func (m *ExportEntitiesPartialSuccess) Reset() { *m = ExportEntitiesPartialSuccess{} } +func (m *ExportEntitiesPartialSuccess) String() string { return proto.CompactTextString(m) } +func (*ExportEntitiesPartialSuccess) ProtoMessage() {} +func (*ExportEntitiesPartialSuccess) Descriptor() ([]byte, []int) { + return fileDescriptor_fbd01640b6ae8848, []int{2} +} +func (m *ExportEntitiesPartialSuccess) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ExportEntitiesPartialSuccess) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ExportEntitiesPartialSuccess.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ExportEntitiesPartialSuccess) XXX_Merge(src proto.Message) { + xxx_messageInfo_ExportEntitiesPartialSuccess.Merge(m, src) +} +func (m *ExportEntitiesPartialSuccess) XXX_Size() int { + return m.Size() +} +func (m *ExportEntitiesPartialSuccess) XXX_DiscardUnknown() { + xxx_messageInfo_ExportEntitiesPartialSuccess.DiscardUnknown(m) +} + +var xxx_messageInfo_ExportEntitiesPartialSuccess proto.InternalMessageInfo + +func (m *ExportEntitiesPartialSuccess) GetRejectedEntities() int64 { + if m != nil { + return m.RejectedEntities + } + return 0 +} + +func (m *ExportEntitiesPartialSuccess) GetErrorMessage() string { + if m != nil { + return m.ErrorMessage + } + return "" +} + +func init() { + proto.RegisterType((*ExportEntitiesServiceRequest)(nil), "opentelemetry.proto.collector.entities.v1.ExportEntitiesServiceRequest") + proto.RegisterType((*ExportEntitiesServiceResponse)(nil), "opentelemetry.proto.collector.entities.v1.ExportEntitiesServiceResponse") + proto.RegisterType((*ExportEntitiesPartialSuccess)(nil), "opentelemetry.proto.collector.entities.v1.ExportEntitiesPartialSuccess") +} + +func init() { + proto.RegisterFile("opentelemetry/proto/collector/entities/v1/entities_service.proto", fileDescriptor_fbd01640b6ae8848) +} + +var fileDescriptor_fbd01640b6ae8848 = []byte{ + // 421 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x93, 0xc1, 0xaa, 0xd3, 0x40, + 0x14, 0x86, 0x33, 0xad, 0x14, 0x9c, 0xda, 0x56, 0x43, 0x17, 0xa5, 0x68, 0x2c, 0x71, 0x93, 0xa2, + 0x4c, 0x68, 0x7d, 0x01, 0xa9, 0x14, 0xdd, 0x88, 0x21, 0x55, 0x17, 0x6e, 0x42, 0x4c, 0x0f, 0x21, + 0x92, 0x66, 0xc6, 0x99, 0x69, 0xd0, 0xb7, 0x70, 0xe7, 0xca, 0x17, 0x70, 0xe7, 0x5b, 0x74, 0xd9, + 0xa5, 0x0b, 0x11, 0x69, 0x5f, 0x44, 0x92, 0x31, 0x21, 0x09, 0xb9, 0x50, 0xee, 0xdd, 0xcd, 0x9c, + 0x9c, 0xff, 0xff, 0xfe, 0x9c, 0xe1, 0xe0, 0x67, 0x94, 0x41, 0x22, 0x21, 0x86, 0x1d, 0x48, 0xfe, + 0xc5, 0x66, 0x9c, 0x4a, 0x6a, 0x07, 0x34, 0x8e, 0x21, 0x90, 0x94, 0xdb, 0x90, 0xc8, 0x48, 0x46, + 0x20, 0xec, 0x74, 0x51, 0x9e, 0x3d, 0x01, 0x3c, 0x8d, 0x02, 0x20, 0x79, 0xb3, 0x3e, 0xaf, 0x39, + 0xa8, 0x22, 0x29, 0x1d, 0x48, 0xa1, 0x22, 0xe9, 0x62, 0x3a, 0x0e, 0x69, 0x48, 0x15, 0x22, 0x3b, + 0xa9, 0xde, 0x29, 0x69, 0x8b, 0xd0, 0x06, 0x56, 0xfd, 0xe6, 0x1e, 0xdf, 0x5f, 0x7f, 0x66, 0x94, + 0xcb, 0xf5, 0xff, 0xfa, 0x46, 0xe5, 0x71, 0xe1, 0xd3, 0x1e, 0x84, 0xd4, 0xdf, 0xe2, 0xa1, 0x08, + 0x28, 0x03, 0xaf, 0xd0, 0x4d, 0xd0, 0xac, 0x6b, 0xf5, 0x97, 0x84, 0xb4, 0x25, 0xad, 0xe4, 0x23, + 0x9b, 0x4c, 0x56, 0xb8, 0xba, 0x03, 0x51, 0xbd, 0x9a, 0xdf, 0x10, 0x7e, 0x70, 0x05, 0x57, 0x30, + 0x9a, 0x08, 0xd0, 0x53, 0x3c, 0x62, 0x3e, 0x97, 0x91, 0x1f, 0x7b, 0x62, 0x1f, 0x04, 0x20, 0x32, + 0x32, 0xb2, 0xfa, 0xcb, 0x17, 0xe4, 0xe2, 0x19, 0x91, 0x3a, 0xc2, 0x51, 0x7e, 0x1b, 0x65, 0xb7, + 0xba, 0x75, 0xf8, 0xf3, 0x50, 0x73, 0x87, 0xac, 0x56, 0x35, 0x59, 0x73, 0x20, 0x75, 0x95, 0xfe, + 0x18, 0xdf, 0xe3, 0xf0, 0x11, 0x02, 0x09, 0xdb, 0xea, 0x4c, 0x90, 0xd5, 0x75, 0xef, 0x16, 0x1f, + 0x0a, 0xa9, 0xfe, 0x08, 0x0f, 0x80, 0x73, 0xca, 0xbd, 0x1d, 0x08, 0xe1, 0x87, 0x30, 0xe9, 0xcc, + 0x90, 0x75, 0xdb, 0xbd, 0x93, 0x17, 0x5f, 0xa9, 0xda, 0xf2, 0x27, 0xc2, 0xa3, 0xc6, 0x14, 0xf4, + 0xef, 0x08, 0xf7, 0x54, 0x0c, 0xfd, 0xfa, 0xff, 0x5b, 0x7f, 0xca, 0xe9, 0xcb, 0x9b, 0x1b, 0xa9, + 0xb7, 0x31, 0xb5, 0xd5, 0x6f, 0x74, 0x38, 0x19, 0xe8, 0x78, 0x32, 0xd0, 0xdf, 0x93, 0x81, 0xbe, + 0x9e, 0x0d, 0xed, 0x78, 0x36, 0xb4, 0x5f, 0x67, 0x43, 0xc3, 0x4f, 0x22, 0x7a, 0x39, 0x68, 0x35, + 0x6e, 0x30, 0x9c, 0xac, 0xd7, 0x41, 0xef, 0x9d, 0xb0, 0xe9, 0x12, 0x55, 0x57, 0x89, 0x6d, 0x7d, + 0xe9, 0xdb, 0x51, 0x22, 0x81, 0x27, 0x7e, 0x6c, 0xe7, 0xb7, 0x1c, 0x13, 0x42, 0xd2, 0xbe, 0x71, + 0x3f, 0x3a, 0xf3, 0xd7, 0x0c, 0x92, 0x37, 0xa5, 0x5f, 0x4e, 0x22, 0xcf, 0xcb, 0x54, 0x45, 0x10, + 0xf2, 0x6e, 0xf1, 0xa1, 0x97, 0x7b, 0x3d, 0xfd, 0x17, 0x00, 0x00, 0xff, 0xff, 0x77, 0x76, 0xac, + 0xd8, 0xd1, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// EntitiesServiceClient is the client API for EntitiesService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type EntitiesServiceClient interface { + // For performance reasons, it is recommended to keep this RPC + // alive for the entire life of the application. + Export(ctx context.Context, in *ExportEntitiesServiceRequest, opts ...grpc.CallOption) (*ExportEntitiesServiceResponse, error) +} + +type entitiesServiceClient struct { + cc *grpc.ClientConn +} + +func NewEntitiesServiceClient(cc *grpc.ClientConn) EntitiesServiceClient { + return &entitiesServiceClient{cc} +} + +func (c *entitiesServiceClient) Export(ctx context.Context, in *ExportEntitiesServiceRequest, opts ...grpc.CallOption) (*ExportEntitiesServiceResponse, error) { + out := new(ExportEntitiesServiceResponse) + err := c.cc.Invoke(ctx, "/opentelemetry.proto.collector.entities.v1.EntitiesService/Export", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// EntitiesServiceServer is the server API for EntitiesService service. +type EntitiesServiceServer interface { + // For performance reasons, it is recommended to keep this RPC + // alive for the entire life of the application. + Export(context.Context, *ExportEntitiesServiceRequest) (*ExportEntitiesServiceResponse, error) +} + +// UnimplementedEntitiesServiceServer can be embedded to have forward compatible implementations. +type UnimplementedEntitiesServiceServer struct { +} + +func (*UnimplementedEntitiesServiceServer) Export(ctx context.Context, req *ExportEntitiesServiceRequest) (*ExportEntitiesServiceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Export not implemented") +} + +func RegisterEntitiesServiceServer(s *grpc.Server, srv EntitiesServiceServer) { + s.RegisterService(&_EntitiesService_serviceDesc, srv) +} + +func _EntitiesService_Export_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ExportEntitiesServiceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EntitiesServiceServer).Export(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/opentelemetry.proto.collector.entities.v1.EntitiesService/Export", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EntitiesServiceServer).Export(ctx, req.(*ExportEntitiesServiceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _EntitiesService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "opentelemetry.proto.collector.entities.v1.EntitiesService", + HandlerType: (*EntitiesServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Export", + Handler: _EntitiesService_Export_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "opentelemetry/proto/collector/entities/v1/entities_service.proto", +} + +func (m *ExportEntitiesServiceRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ExportEntitiesServiceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ExportEntitiesServiceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ScopeEntities) > 0 { + for iNdEx := len(m.ScopeEntities) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ScopeEntities[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntitiesService(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ExportEntitiesServiceResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ExportEntitiesServiceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ExportEntitiesServiceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.PartialSuccess.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntitiesService(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ExportEntitiesPartialSuccess) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ExportEntitiesPartialSuccess) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ExportEntitiesPartialSuccess) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ErrorMessage) > 0 { + i -= len(m.ErrorMessage) + copy(dAtA[i:], m.ErrorMessage) + i = encodeVarintEntitiesService(dAtA, i, uint64(len(m.ErrorMessage))) + i-- + dAtA[i] = 0x12 + } + if m.RejectedEntities != 0 { + i = encodeVarintEntitiesService(dAtA, i, uint64(m.RejectedEntities)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintEntitiesService(dAtA []byte, offset int, v uint64) int { + offset -= sovEntitiesService(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ExportEntitiesServiceRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.ScopeEntities) > 0 { + for _, e := range m.ScopeEntities { + l = e.Size() + n += 1 + l + sovEntitiesService(uint64(l)) + } + } + return n +} + +func (m *ExportEntitiesServiceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.PartialSuccess.Size() + n += 1 + l + sovEntitiesService(uint64(l)) + return n +} + +func (m *ExportEntitiesPartialSuccess) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.RejectedEntities != 0 { + n += 1 + sovEntitiesService(uint64(m.RejectedEntities)) + } + l = len(m.ErrorMessage) + if l > 0 { + n += 1 + l + sovEntitiesService(uint64(l)) + } + return n +} + +func sovEntitiesService(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEntitiesService(x uint64) (n int) { + return sovEntitiesService(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ExportEntitiesServiceRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ExportEntitiesServiceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ExportEntitiesServiceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ScopeEntities", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntitiesService + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntitiesService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ScopeEntities = append(m.ScopeEntities, &v1.ScopeEntities{}) + if err := m.ScopeEntities[len(m.ScopeEntities)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEntitiesService(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEntitiesService + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ExportEntitiesServiceResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ExportEntitiesServiceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ExportEntitiesServiceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PartialSuccess", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntitiesService + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntitiesService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PartialSuccess.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEntitiesService(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEntitiesService + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ExportEntitiesPartialSuccess) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ExportEntitiesPartialSuccess: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ExportEntitiesPartialSuccess: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RejectedEntities", wireType) + } + m.RejectedEntities = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RejectedEntities |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ErrorMessage", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEntitiesService + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEntitiesService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ErrorMessage = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEntitiesService(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEntitiesService + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEntitiesService(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEntitiesService + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthEntitiesService + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEntitiesService + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEntitiesService + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEntitiesService = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEntitiesService = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEntitiesService = fmt.Errorf("proto: unexpected end of group") +) diff --git a/pdata/internal/data/protogen/entities/v1/entities.pb.go b/pdata/internal/data/protogen/entities/v1/entities.pb.go new file mode 100644 index 00000000000..4afbb05c01f --- /dev/null +++ b/pdata/internal/data/protogen/entities/v1/entities.pb.go @@ -0,0 +1,1466 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: opentelemetry/proto/entities/v1/entities.proto + +package v1 + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + + v1 "go.opentelemetry.io/collector/pdata/internal/data/protogen/common/v1" + _ "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// EntitiesData represents the entities data that can be stored in a persistent storage, +// OR can be embedded by other protocols that transfer OTLP entities data but do not +// implement the OTLP protocol. +// +// The main difference between this message and collector protocol is that +// in this message there will not be any "control" or "metadata" specific to +// OTLP protocol. +// +// When new fields are added into this message, the OTLP request MUST be updated +// as well. +type EntitiesData struct { + ScopeEntities []*ScopeEntities `protobuf:"bytes,1,rep,name=scope_entities,json=scopeEntities,proto3" json:"scope_entities,omitempty"` +} + +func (m *EntitiesData) Reset() { *m = EntitiesData{} } +func (m *EntitiesData) String() string { return proto.CompactTextString(m) } +func (*EntitiesData) ProtoMessage() {} +func (*EntitiesData) Descriptor() ([]byte, []int) { + return fileDescriptor_23658fae9436c0cd, []int{0} +} +func (m *EntitiesData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EntitiesData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EntitiesData.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EntitiesData) XXX_Merge(src proto.Message) { + xxx_messageInfo_EntitiesData.Merge(m, src) +} +func (m *EntitiesData) XXX_Size() int { + return m.Size() +} +func (m *EntitiesData) XXX_DiscardUnknown() { + xxx_messageInfo_EntitiesData.DiscardUnknown(m) +} + +var xxx_messageInfo_EntitiesData proto.InternalMessageInfo + +func (m *EntitiesData) GetScopeEntities() []*ScopeEntities { + if m != nil { + return m.ScopeEntities + } + return nil +} + +// A collection of Entities produced by a Scope. +type ScopeEntities struct { + // The instrumentation scope information for the entities in this message. + // Semantically when InstrumentationScope isn't set, it is equivalent with + // an empty instrumentation scope name (unknown). + Scope v1.InstrumentationScope `protobuf:"bytes,1,opt,name=scope,proto3" json:"scope"` + EntityEvents []*EntityEvent `protobuf:"bytes,2,rep,name=entity_events,json=entityEvents,proto3" json:"entity_events,omitempty"` + // This schema_url applies to all entities in the "entity_events" field. + SchemaUrl string `protobuf:"bytes,3,opt,name=schema_url,json=schemaUrl,proto3" json:"schema_url,omitempty"` +} + +func (m *ScopeEntities) Reset() { *m = ScopeEntities{} } +func (m *ScopeEntities) String() string { return proto.CompactTextString(m) } +func (*ScopeEntities) ProtoMessage() {} +func (*ScopeEntities) Descriptor() ([]byte, []int) { + return fileDescriptor_23658fae9436c0cd, []int{1} +} +func (m *ScopeEntities) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ScopeEntities) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ScopeEntities.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ScopeEntities) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScopeEntities.Merge(m, src) +} +func (m *ScopeEntities) XXX_Size() int { + return m.Size() +} +func (m *ScopeEntities) XXX_DiscardUnknown() { + xxx_messageInfo_ScopeEntities.DiscardUnknown(m) +} + +var xxx_messageInfo_ScopeEntities proto.InternalMessageInfo + +func (m *ScopeEntities) GetScope() v1.InstrumentationScope { + if m != nil { + return m.Scope + } + return v1.InstrumentationScope{} +} + +func (m *ScopeEntities) GetEntityEvents() []*EntityEvent { + if m != nil { + return m.EntityEvents + } + return nil +} + +func (m *ScopeEntities) GetSchemaUrl() string { + if m != nil { + return m.SchemaUrl + } + return "" +} + +// Entity event, describes something that happened with the entity. +type EntityEvent struct { + // Time when this state was observed. + TimeUnixNano uint64 `protobuf:"varint,1,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` + // Type of the entity, e.g. "service", "host", etc. + EntityType string `protobuf:"bytes,2,opt,name=entity_type,json=entityType,proto3" json:"entity_type,omitempty"` + // Set of attributes that identify the entity. + Id []v1.KeyValue `protobuf:"bytes,3,rep,name=id,proto3" json:"id"` + // One of the following event types must be set. + // + // Types that are valid to be assigned to Data: + // *EntityEvent_EntityState + // *EntityEvent_EntityDelete + Data isEntityEvent_Data `protobuf_oneof:"data"` +} + +func (m *EntityEvent) Reset() { *m = EntityEvent{} } +func (m *EntityEvent) String() string { return proto.CompactTextString(m) } +func (*EntityEvent) ProtoMessage() {} +func (*EntityEvent) Descriptor() ([]byte, []int) { + return fileDescriptor_23658fae9436c0cd, []int{2} +} +func (m *EntityEvent) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EntityEvent) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EntityEvent.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EntityEvent) XXX_Merge(src proto.Message) { + xxx_messageInfo_EntityEvent.Merge(m, src) +} +func (m *EntityEvent) XXX_Size() int { + return m.Size() +} +func (m *EntityEvent) XXX_DiscardUnknown() { + xxx_messageInfo_EntityEvent.DiscardUnknown(m) +} + +var xxx_messageInfo_EntityEvent proto.InternalMessageInfo + +type isEntityEvent_Data interface { + isEntityEvent_Data() + MarshalTo([]byte) (int, error) + Size() int +} + +type EntityEvent_EntityState struct { + EntityState *EntityState `protobuf:"bytes,4,opt,name=entity_state,json=entityState,proto3,oneof" json:"entity_state,omitempty"` +} +type EntityEvent_EntityDelete struct { + EntityDelete *EntityDelete `protobuf:"bytes,5,opt,name=entity_delete,json=entityDelete,proto3,oneof" json:"entity_delete,omitempty"` +} + +func (*EntityEvent_EntityState) isEntityEvent_Data() {} +func (*EntityEvent_EntityDelete) isEntityEvent_Data() {} + +func (m *EntityEvent) GetData() isEntityEvent_Data { + if m != nil { + return m.Data + } + return nil +} + +func (m *EntityEvent) GetTimeUnixNano() uint64 { + if m != nil { + return m.TimeUnixNano + } + return 0 +} + +func (m *EntityEvent) GetEntityType() string { + if m != nil { + return m.EntityType + } + return "" +} + +func (m *EntityEvent) GetId() []v1.KeyValue { + if m != nil { + return m.Id + } + return nil +} + +func (m *EntityEvent) GetEntityState() *EntityState { + if x, ok := m.GetData().(*EntityEvent_EntityState); ok { + return x.EntityState + } + return nil +} + +func (m *EntityEvent) GetEntityDelete() *EntityDelete { + if x, ok := m.GetData().(*EntityEvent_EntityDelete); ok { + return x.EntityDelete + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*EntityEvent) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*EntityEvent_EntityState)(nil), + (*EntityEvent_EntityDelete)(nil), + } +} + +// The full state of the Entity. +type EntityState struct { + // Set of non-identifying attributes only. + Attributes []v1.KeyValue `protobuf:"bytes,4,rep,name=attributes,proto3" json:"attributes"` + DroppedAttributesCount uint32 `protobuf:"varint,5,opt,name=dropped_attributes_count,json=droppedAttributesCount,proto3" json:"dropped_attributes_count,omitempty"` +} + +func (m *EntityState) Reset() { *m = EntityState{} } +func (m *EntityState) String() string { return proto.CompactTextString(m) } +func (*EntityState) ProtoMessage() {} +func (*EntityState) Descriptor() ([]byte, []int) { + return fileDescriptor_23658fae9436c0cd, []int{3} +} +func (m *EntityState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EntityState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EntityState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EntityState) XXX_Merge(src proto.Message) { + xxx_messageInfo_EntityState.Merge(m, src) +} +func (m *EntityState) XXX_Size() int { + return m.Size() +} +func (m *EntityState) XXX_DiscardUnknown() { + xxx_messageInfo_EntityState.DiscardUnknown(m) +} + +var xxx_messageInfo_EntityState proto.InternalMessageInfo + +func (m *EntityState) GetAttributes() []v1.KeyValue { + if m != nil { + return m.Attributes + } + return nil +} + +func (m *EntityState) GetDroppedAttributesCount() uint32 { + if m != nil { + return m.DroppedAttributesCount + } + return 0 +} + +// Deletion event. No additional information is recorded. +type EntityDelete struct { +} + +func (m *EntityDelete) Reset() { *m = EntityDelete{} } +func (m *EntityDelete) String() string { return proto.CompactTextString(m) } +func (*EntityDelete) ProtoMessage() {} +func (*EntityDelete) Descriptor() ([]byte, []int) { + return fileDescriptor_23658fae9436c0cd, []int{4} +} +func (m *EntityDelete) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EntityDelete) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EntityDelete.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EntityDelete) XXX_Merge(src proto.Message) { + xxx_messageInfo_EntityDelete.Merge(m, src) +} +func (m *EntityDelete) XXX_Size() int { + return m.Size() +} +func (m *EntityDelete) XXX_DiscardUnknown() { + xxx_messageInfo_EntityDelete.DiscardUnknown(m) +} + +var xxx_messageInfo_EntityDelete proto.InternalMessageInfo + +func init() { + proto.RegisterType((*EntitiesData)(nil), "opentelemetry.proto.entities.v1.EntitiesData") + proto.RegisterType((*ScopeEntities)(nil), "opentelemetry.proto.entities.v1.ScopeEntities") + proto.RegisterType((*EntityEvent)(nil), "opentelemetry.proto.entities.v1.EntityEvent") + proto.RegisterType((*EntityState)(nil), "opentelemetry.proto.entities.v1.EntityState") + proto.RegisterType((*EntityDelete)(nil), "opentelemetry.proto.entities.v1.EntityDelete") +} + +func init() { + proto.RegisterFile("opentelemetry/proto/entities/v1/entities.proto", fileDescriptor_23658fae9436c0cd) +} + +var fileDescriptor_23658fae9436c0cd = []byte{ + // 565 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcd, 0x6a, 0xdb, 0x4c, + 0x14, 0x95, 0x14, 0x27, 0x90, 0x71, 0xec, 0x85, 0xf8, 0xf8, 0x10, 0x81, 0xca, 0x46, 0x14, 0x6a, + 0x4a, 0x2b, 0xe1, 0x64, 0xd3, 0x4d, 0x17, 0x75, 0x93, 0x92, 0x52, 0xda, 0x24, 0x8a, 0x9d, 0x45, + 0x37, 0x62, 0x22, 0x5d, 0xdc, 0x01, 0x69, 0x46, 0x48, 0x57, 0x26, 0x7a, 0x8b, 0xae, 0xfa, 0x10, + 0x7d, 0x81, 0xbe, 0x40, 0x17, 0x59, 0x86, 0xae, 0xba, 0x2a, 0xc5, 0x7e, 0x91, 0x32, 0x23, 0xc9, + 0x71, 0x8a, 0xc1, 0xa1, 0xbb, 0xfb, 0x73, 0xee, 0xb9, 0xe7, 0x1e, 0x34, 0x22, 0xae, 0x48, 0x81, + 0x23, 0xc4, 0x90, 0x00, 0x66, 0xa5, 0x97, 0x66, 0x02, 0x85, 0x07, 0x1c, 0x19, 0x32, 0xc8, 0xbd, + 0xd9, 0x70, 0x19, 0xbb, 0xaa, 0x65, 0xf6, 0xee, 0xe1, 0xab, 0xa2, 0xbb, 0xc4, 0xcc, 0x86, 0xfb, + 0xff, 0x4d, 0xc5, 0x54, 0x54, 0x34, 0x32, 0xaa, 0x10, 0xfb, 0x4f, 0xd7, 0xad, 0x09, 0x45, 0x92, + 0x08, 0x2e, 0x97, 0x54, 0x51, 0x8d, 0x5d, 0x2b, 0x29, 0x83, 0x5c, 0x14, 0x59, 0x08, 0x12, 0xdd, + 0xc4, 0x15, 0xde, 0x01, 0xb2, 0x77, 0x5c, 0x0b, 0x38, 0xa2, 0x48, 0xcd, 0x09, 0xe9, 0xe6, 0xa1, + 0x48, 0x21, 0x68, 0x64, 0x59, 0x7a, 0x7f, 0x6b, 0xd0, 0x3e, 0x70, 0xdd, 0x0d, 0xda, 0xdd, 0x0b, + 0x39, 0xd6, 0x70, 0xf9, 0x9d, 0x7c, 0x35, 0x75, 0x7e, 0xe8, 0xa4, 0x73, 0x0f, 0x60, 0x9e, 0x92, + 0x6d, 0x05, 0xb1, 0xf4, 0xbe, 0x3e, 0x68, 0x1f, 0x1c, 0xae, 0xe5, 0xaf, 0x4f, 0x9b, 0x0d, 0xdd, + 0xb7, 0x3c, 0xc7, 0xac, 0x48, 0x80, 0x23, 0x45, 0x26, 0xb8, 0xe2, 0x1a, 0xb5, 0x6e, 0x7e, 0xf5, + 0x34, 0xbf, 0xe2, 0x31, 0xcf, 0x49, 0x47, 0xc9, 0x29, 0x03, 0x98, 0x01, 0xc7, 0xdc, 0x32, 0x94, + 0xf0, 0x67, 0x1b, 0x85, 0x2b, 0x49, 0xe5, 0xb1, 0x1c, 0xf2, 0xf7, 0xe0, 0x2e, 0xc9, 0xcd, 0x47, + 0x84, 0xe4, 0xe1, 0x27, 0x48, 0x68, 0x50, 0x64, 0xb1, 0xb5, 0xd5, 0xd7, 0x07, 0xbb, 0xfe, 0x6e, + 0x55, 0x99, 0x64, 0xb1, 0xf3, 0xdd, 0x20, 0xed, 0x95, 0x61, 0xf3, 0x31, 0xe9, 0x22, 0x4b, 0x20, + 0x28, 0x38, 0xbb, 0x0e, 0x38, 0xe5, 0x42, 0xdd, 0xd6, 0xf2, 0xf7, 0x64, 0x75, 0xc2, 0xd9, 0xf5, + 0x07, 0xca, 0x85, 0xd9, 0x23, 0xed, 0x5a, 0x27, 0x96, 0x29, 0x58, 0x86, 0x62, 0x25, 0x55, 0x69, + 0x5c, 0xa6, 0x60, 0xbe, 0x24, 0x06, 0x8b, 0xac, 0x2d, 0xa5, 0xfe, 0xc9, 0x06, 0x5b, 0xde, 0x41, + 0x79, 0x49, 0xe3, 0xa2, 0xb1, 0xc2, 0x60, 0x91, 0x79, 0x4e, 0xea, 0x23, 0x82, 0x1c, 0x29, 0x82, + 0xd5, 0x52, 0xfe, 0x3e, 0xd4, 0x86, 0x0b, 0x39, 0x73, 0xa2, 0xf9, 0xb5, 0x46, 0x95, 0x9a, 0xe3, + 0xa5, 0xb5, 0x11, 0xc4, 0x80, 0x60, 0x6d, 0x2b, 0xce, 0xe7, 0x0f, 0xe4, 0x3c, 0x52, 0x43, 0x27, + 0x5a, 0xe3, 0x6e, 0x95, 0x8f, 0x76, 0x48, 0x2b, 0xa2, 0x48, 0x9d, 0x2f, 0x7a, 0x63, 0x63, 0xb5, + 0xed, 0x3d, 0x21, 0x14, 0x31, 0x63, 0x57, 0x05, 0x42, 0x6e, 0xb5, 0xfe, 0xc5, 0x87, 0x15, 0x02, + 0xf3, 0x05, 0xb1, 0xa2, 0x4c, 0xa4, 0x29, 0x44, 0xc1, 0x5d, 0x35, 0x08, 0x45, 0xc1, 0x51, 0xdd, + 0xd1, 0xf1, 0xff, 0xaf, 0xfb, 0xaf, 0x96, 0xed, 0xd7, 0xb2, 0xeb, 0x74, 0xeb, 0xb7, 0xd1, 0x08, + 0xfe, 0xa6, 0xdf, 0xcc, 0x6d, 0xfd, 0x76, 0x6e, 0xeb, 0xbf, 0xe7, 0xb6, 0xfe, 0x79, 0x61, 0x6b, + 0xb7, 0x0b, 0x5b, 0xfb, 0xb9, 0xb0, 0x35, 0xe2, 0x30, 0xb1, 0xc9, 0x8c, 0x51, 0xa7, 0xf9, 0xf6, + 0xcf, 0x64, 0xeb, 0x4c, 0xff, 0xf8, 0x66, 0xfa, 0xf7, 0x10, 0x93, 0xef, 0x3a, 0x8e, 0x21, 0x44, + 0x91, 0x79, 0xa9, 0x74, 0xc7, 0x63, 0x1c, 0x21, 0xe3, 0x34, 0xf6, 0x54, 0xa6, 0x58, 0xa7, 0xc0, + 0x57, 0xff, 0x32, 0x5f, 0x8d, 0xde, 0x69, 0x0a, 0x7c, 0xbc, 0x64, 0x51, 0xfc, 0x6e, 0xb3, 0xcd, + 0xbd, 0x1c, 0x5e, 0xed, 0xa8, 0xb9, 0xc3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf2, 0xcf, 0xcd, + 0xb6, 0xb1, 0x04, 0x00, 0x00, +} + +func (m *EntitiesData) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EntitiesData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EntitiesData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ScopeEntities) > 0 { + for iNdEx := len(m.ScopeEntities) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ScopeEntities[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntities(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ScopeEntities) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ScopeEntities) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ScopeEntities) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SchemaUrl) > 0 { + i -= len(m.SchemaUrl) + copy(dAtA[i:], m.SchemaUrl) + i = encodeVarintEntities(dAtA, i, uint64(len(m.SchemaUrl))) + i-- + dAtA[i] = 0x1a + } + if len(m.EntityEvents) > 0 { + for iNdEx := len(m.EntityEvents) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.EntityEvents[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntities(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Scope.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntities(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *EntityEvent) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EntityEvent) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EntityEvent) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Data != nil { + { + size := m.Data.Size() + i -= size + if _, err := m.Data.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + if len(m.Id) > 0 { + for iNdEx := len(m.Id) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Id[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntities(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.EntityType) > 0 { + i -= len(m.EntityType) + copy(dAtA[i:], m.EntityType) + i = encodeVarintEntities(dAtA, i, uint64(len(m.EntityType))) + i-- + dAtA[i] = 0x12 + } + if m.TimeUnixNano != 0 { + i = encodeVarintEntities(dAtA, i, uint64(m.TimeUnixNano)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *EntityEvent_EntityState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EntityEvent_EntityState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.EntityState != nil { + { + size, err := m.EntityState.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntities(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + return len(dAtA) - i, nil +} +func (m *EntityEvent_EntityDelete) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EntityEvent_EntityDelete) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.EntityDelete != nil { + { + size, err := m.EntityDelete.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntities(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + return len(dAtA) - i, nil +} +func (m *EntityState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EntityState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EntityState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DroppedAttributesCount != 0 { + i = encodeVarintEntities(dAtA, i, uint64(m.DroppedAttributesCount)) + i-- + dAtA[i] = 0x28 + } + if len(m.Attributes) > 0 { + for iNdEx := len(m.Attributes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Attributes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEntities(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + return len(dAtA) - i, nil +} + +func (m *EntityDelete) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EntityDelete) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EntityDelete) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintEntities(dAtA []byte, offset int, v uint64) int { + offset -= sovEntities(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *EntitiesData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.ScopeEntities) > 0 { + for _, e := range m.ScopeEntities { + l = e.Size() + n += 1 + l + sovEntities(uint64(l)) + } + } + return n +} + +func (m *ScopeEntities) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Scope.Size() + n += 1 + l + sovEntities(uint64(l)) + if len(m.EntityEvents) > 0 { + for _, e := range m.EntityEvents { + l = e.Size() + n += 1 + l + sovEntities(uint64(l)) + } + } + l = len(m.SchemaUrl) + if l > 0 { + n += 1 + l + sovEntities(uint64(l)) + } + return n +} + +func (m *EntityEvent) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.TimeUnixNano != 0 { + n += 1 + sovEntities(uint64(m.TimeUnixNano)) + } + l = len(m.EntityType) + if l > 0 { + n += 1 + l + sovEntities(uint64(l)) + } + if len(m.Id) > 0 { + for _, e := range m.Id { + l = e.Size() + n += 1 + l + sovEntities(uint64(l)) + } + } + if m.Data != nil { + n += m.Data.Size() + } + return n +} + +func (m *EntityEvent_EntityState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.EntityState != nil { + l = m.EntityState.Size() + n += 1 + l + sovEntities(uint64(l)) + } + return n +} +func (m *EntityEvent_EntityDelete) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.EntityDelete != nil { + l = m.EntityDelete.Size() + n += 1 + l + sovEntities(uint64(l)) + } + return n +} +func (m *EntityState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Attributes) > 0 { + for _, e := range m.Attributes { + l = e.Size() + n += 1 + l + sovEntities(uint64(l)) + } + } + if m.DroppedAttributesCount != 0 { + n += 1 + sovEntities(uint64(m.DroppedAttributesCount)) + } + return n +} + +func (m *EntityDelete) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovEntities(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEntities(x uint64) (n int) { + return sovEntities(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *EntitiesData) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EntitiesData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EntitiesData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ScopeEntities", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ScopeEntities = append(m.ScopeEntities, &ScopeEntities{}) + if err := m.ScopeEntities[len(m.ScopeEntities)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEntities(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEntities + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ScopeEntities) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ScopeEntities: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ScopeEntities: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Scope", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Scope.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EntityEvents", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EntityEvents = append(m.EntityEvents, &EntityEvent{}) + if err := m.EntityEvents[len(m.EntityEvents)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SchemaUrl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SchemaUrl = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEntities(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEntities + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EntityEvent) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EntityEvent: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EntityEvent: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeUnixNano", wireType) + } + m.TimeUnixNano = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeUnixNano |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EntityType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EntityType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = append(m.Id, v1.KeyValue{}) + if err := m.Id[len(m.Id)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EntityState", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &EntityState{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Data = &EntityEvent_EntityState{v} + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EntityDelete", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &EntityDelete{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Data = &EntityEvent_EntityDelete{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEntities(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEntities + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EntityState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EntityState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EntityState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEntities + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEntities + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Attributes = append(m.Attributes, v1.KeyValue{}) + if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DroppedAttributesCount", wireType) + } + m.DroppedAttributesCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DroppedAttributesCount |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipEntities(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEntities + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EntityDelete) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEntities + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EntityDelete: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EntityDelete: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipEntities(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEntities + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEntities(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEntities + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEntities + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEntities + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthEntities + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEntities + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEntities + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEntities = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEntities = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEntities = fmt.Errorf("proto: unexpected end of group") +) diff --git a/pdata/internal/data/protogen/logs/v1/logs.pb.go b/pdata/internal/data/protogen/logs/v1/logs.pb.go index 65b11fbe286..0902eb75c6c 100644 --- a/pdata/internal/data/protogen/logs/v1/logs.pb.go +++ b/pdata/internal/data/protogen/logs/v1/logs.pb.go @@ -232,6 +232,8 @@ type ResourceLogs struct { // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url // This schema_url applies to the data in the "resource" field. It does not apply // to the data in the "scope_logs" field which have their own schema_url field. + // + // This field is deprecated in favour of Resource.entities.schema_url. SchemaUrl string `protobuf:"bytes,3,opt,name=schema_url,json=schemaUrl,proto3" json:"schema_url,omitempty"` } diff --git a/pdata/internal/data/protogen/metrics/v1/metrics.pb.go b/pdata/internal/data/protogen/metrics/v1/metrics.pb.go index 3649bd83f81..d723c63537e 100644 --- a/pdata/internal/data/protogen/metrics/v1/metrics.pb.go +++ b/pdata/internal/data/protogen/metrics/v1/metrics.pb.go @@ -160,6 +160,25 @@ func (DataPointFlags) EnumDescriptor() ([]byte, []int) { // storage, OR can be embedded by other protocols that transfer OTLP metrics // data but do not implement the OTLP protocol. // +// MetricsData +// └─── ResourceMetrics +// +// ├── Resource +// ├── SchemaURL +// └── ScopeMetrics +// ├── Scope +// ├── SchemaURL +// └── Metric +// ├── Name +// ├── Description +// ├── Unit +// └── data +// ├── Gauge +// ├── Sum +// ├── Histogram +// ├── ExponentialHistogram +// └── Summary +// // The main difference between this message and collector protocol is that // in this message there will not be any "control" or "metadata" specific to // OTLP protocol. @@ -228,6 +247,8 @@ type ResourceMetrics struct { // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url // This schema_url applies to the data in the "resource" field. It does not apply // to the data in the "scope_metrics" field which have their own schema_url field. + // + // This field is deprecated in favour of Resource.entities.schema_url. SchemaUrl string `protobuf:"bytes,3,opt,name=schema_url,json=schemaUrl,proto3" json:"schema_url,omitempty"` } diff --git a/pdata/internal/data/protogen/resource/v1/resource.pb.go b/pdata/internal/data/protogen/resource/v1/resource.pb.go index d4d1565c764..a71639d183f 100644 --- a/pdata/internal/data/protogen/resource/v1/resource.pb.go +++ b/pdata/internal/data/protogen/resource/v1/resource.pb.go @@ -35,6 +35,8 @@ type Resource struct { // dropped_attributes_count is the number of dropped attributes. If the value is 0, then // no attributes were dropped. DroppedAttributesCount uint32 `protobuf:"varint,2,opt,name=dropped_attributes_count,json=droppedAttributesCount,proto3" json:"dropped_attributes_count,omitempty"` + // Set of entities that participate in this Resource. + Entities []*ResourceEntityRef `protobuf:"bytes,3,rep,name=entities,proto3" json:"entities,omitempty"` } func (m *Resource) Reset() { *m = Resource{} } @@ -84,8 +86,104 @@ func (m *Resource) GetDroppedAttributesCount() uint32 { return 0 } +func (m *Resource) GetEntities() []*ResourceEntityRef { + if m != nil { + return m.Entities + } + return nil +} + +type ResourceEntityRef struct { + // The Schema URL, if known. This is the identifier of the Schema that the entity data + // is recorded in. To learn more about Schema URL see + // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url + // + // This schema_url applies to the data in this message and to the Resource attributes + // referenced by id_attr_keys and descr_attr_keys. + // TODO: discuss if we are happy with this somewhat complicated definition of what + // the schema_url applies to. + // + // This field obsoletes the schema_url field in ResourceMetrics/ResourceSpans/ResourceLogs. + SchemaUrl string `protobuf:"bytes,1,opt,name=schema_url,json=schemaUrl,proto3" json:"schema_url,omitempty"` + // Defines the type of the entity. MUST not change during the lifetime of the entity. + // For example: "service" or "host". This field is required and MUST not be empty + // for valid entities. + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + // Attribute Keys that identify the entity. + // MUST not change during the lifetime of the entity. The Id must contain at least one attribute. + // These keys MUST exist in the containing Resource.attributes. + IdAttrKeys []string `protobuf:"bytes,3,rep,name=id_attr_keys,json=idAttrKeys,proto3" json:"id_attr_keys,omitempty"` + // Descriptive (non-identifying) attribute keys of the entity. + // MAY change over the lifetime of the entity. MAY be empty. + // These attribute keys are not part of entity's identity. + // These keys MUST exist in the containing Resource.attributes. + DescrAttrKeys []string `protobuf:"bytes,4,rep,name=descr_attr_keys,json=descrAttrKeys,proto3" json:"descr_attr_keys,omitempty"` +} + +func (m *ResourceEntityRef) Reset() { *m = ResourceEntityRef{} } +func (m *ResourceEntityRef) String() string { return proto.CompactTextString(m) } +func (*ResourceEntityRef) ProtoMessage() {} +func (*ResourceEntityRef) Descriptor() ([]byte, []int) { + return fileDescriptor_446f73eacf88f3f5, []int{1} +} +func (m *ResourceEntityRef) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ResourceEntityRef) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ResourceEntityRef.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ResourceEntityRef) XXX_Merge(src proto.Message) { + xxx_messageInfo_ResourceEntityRef.Merge(m, src) +} +func (m *ResourceEntityRef) XXX_Size() int { + return m.Size() +} +func (m *ResourceEntityRef) XXX_DiscardUnknown() { + xxx_messageInfo_ResourceEntityRef.DiscardUnknown(m) +} + +var xxx_messageInfo_ResourceEntityRef proto.InternalMessageInfo + +func (m *ResourceEntityRef) GetSchemaUrl() string { + if m != nil { + return m.SchemaUrl + } + return "" +} + +func (m *ResourceEntityRef) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *ResourceEntityRef) GetIdAttrKeys() []string { + if m != nil { + return m.IdAttrKeys + } + return nil +} + +func (m *ResourceEntityRef) GetDescrAttrKeys() []string { + if m != nil { + return m.DescrAttrKeys + } + return nil +} + func init() { proto.RegisterType((*Resource)(nil), "opentelemetry.proto.resource.v1.Resource") + proto.RegisterType((*ResourceEntityRef)(nil), "opentelemetry.proto.resource.v1.ResourceEntityRef") } func init() { @@ -93,26 +191,33 @@ func init() { } var fileDescriptor_446f73eacf88f3f5 = []byte{ - // 302 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xcb, 0x2f, 0x48, 0xcd, - 0x2b, 0x49, 0xcd, 0x49, 0xcd, 0x4d, 0x2d, 0x29, 0xaa, 0xd4, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, - 0x2f, 0x4a, 0x2d, 0xce, 0x2f, 0x2d, 0x4a, 0x4e, 0xd5, 0x2f, 0x33, 0x84, 0xb3, 0xf5, 0xc0, 0x52, - 0x42, 0xf2, 0x28, 0xea, 0x21, 0x82, 0x7a, 0x70, 0x35, 0x65, 0x86, 0x52, 0x22, 0xe9, 0xf9, 0xe9, - 0xf9, 0x10, 0x63, 0x40, 0x2c, 0x88, 0x0a, 0x29, 0x2d, 0x6c, 0xd6, 0x24, 0xe7, 0xe7, 0xe6, 0xe6, - 0xe7, 0x81, 0x2c, 0x81, 0xb0, 0x20, 0x6a, 0x95, 0x26, 0x33, 0x72, 0x71, 0x04, 0x41, 0x4d, 0x14, - 0xf2, 0xe5, 0xe2, 0x4a, 0x2c, 0x29, 0x29, 0xca, 0x4c, 0x2a, 0x2d, 0x49, 0x2d, 0x96, 0x60, 0x54, - 0x60, 0xd6, 0xe0, 0x36, 0x52, 0xd7, 0xc3, 0xe6, 0x08, 0xa8, 0x19, 0x65, 0x86, 0x7a, 0xde, 0xa9, - 0x95, 0x61, 0x89, 0x39, 0xa5, 0xa9, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x21, 0x19, 0x20, - 0x64, 0xc1, 0x25, 0x91, 0x52, 0x94, 0x5f, 0x50, 0x90, 0x9a, 0x12, 0x8f, 0x10, 0x8d, 0x4f, 0xce, - 0x2f, 0xcd, 0x2b, 0x91, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0d, 0x12, 0x83, 0xca, 0x3b, 0xc2, 0xa5, - 0x9d, 0x41, 0xb2, 0x4e, 0xdb, 0x19, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, - 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x81, - 0x4b, 0x29, 0x33, 0x5f, 0x8f, 0x40, 0xb0, 0x38, 0xf1, 0xc2, 0x7c, 0x14, 0x00, 0x92, 0x0a, 0x60, - 0x8c, 0x72, 0x4b, 0x47, 0xd7, 0x94, 0x09, 0x0a, 0x91, 0x9c, 0x9c, 0xd4, 0xe4, 0x92, 0xfc, 0x22, - 0xfd, 0x82, 0x94, 0xc4, 0x92, 0x44, 0xfd, 0xcc, 0xbc, 0x92, 0xd4, 0xa2, 0xbc, 0xc4, 0x1c, 0x7d, - 0x30, 0x0f, 0x6c, 0x6a, 0x7a, 0x6a, 0x1e, 0x72, 0xfc, 0xac, 0x62, 0x92, 0xf7, 0x2f, 0x48, 0xcd, - 0x0b, 0x81, 0x9b, 0x02, 0x36, 0x5f, 0x0f, 0x66, 0x9b, 0x5e, 0x98, 0x61, 0x12, 0x1b, 0x58, 0x9f, - 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xbd, 0x8b, 0xcf, 0x38, 0xeb, 0x01, 0x00, 0x00, + // 410 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x41, 0x8e, 0xd3, 0x30, + 0x14, 0x86, 0xe3, 0x99, 0x0a, 0x4d, 0x0c, 0x15, 0xc2, 0x42, 0x28, 0x1a, 0x89, 0x34, 0xea, 0x02, + 0x2a, 0x16, 0x8e, 0x32, 0x6c, 0xd8, 0x52, 0x04, 0x9b, 0x11, 0x30, 0xb2, 0x60, 0x16, 0x6c, 0xa2, + 0x34, 0x79, 0x04, 0x8b, 0xc4, 0x8e, 0x1c, 0xa7, 0x52, 0x6e, 0xd1, 0x73, 0x70, 0x01, 0xae, 0xd0, + 0x65, 0x97, 0xac, 0x10, 0x6a, 0x2e, 0x82, 0x62, 0xb7, 0xa1, 0x40, 0xa5, 0xee, 0x5e, 0xde, 0xff, + 0xbf, 0xcf, 0xef, 0x77, 0x8c, 0xa9, 0xac, 0x40, 0x68, 0x28, 0xa0, 0x04, 0xad, 0xda, 0xb0, 0x52, + 0x52, 0xcb, 0x50, 0x41, 0x2d, 0x1b, 0x95, 0x42, 0xb8, 0x8c, 0x86, 0x9a, 0x1a, 0x89, 0x4c, 0xfe, + 0xf2, 0xdb, 0x26, 0x1d, 0x3c, 0xcb, 0xe8, 0xf2, 0x61, 0x2e, 0x73, 0x69, 0x31, 0x7d, 0x65, 0x1d, + 0x97, 0xcf, 0x8e, 0x1d, 0x93, 0xca, 0xb2, 0x94, 0xa2, 0x3f, 0xc4, 0x56, 0xd6, 0x3b, 0xed, 0x10, + 0xbe, 0x60, 0x3b, 0x22, 0x79, 0x8b, 0x71, 0xa2, 0xb5, 0xe2, 0x8b, 0x46, 0x43, 0xed, 0xa1, 0xe0, + 0x7c, 0x76, 0xf7, 0xea, 0x29, 0x3d, 0xb6, 0xc4, 0x8e, 0xb1, 0x8c, 0xe8, 0x35, 0xb4, 0xb7, 0x49, + 0xd1, 0xc0, 0x7c, 0xb4, 0xfe, 0x39, 0x71, 0xd8, 0x01, 0x80, 0xbc, 0xc0, 0x5e, 0xa6, 0x64, 0x55, + 0x41, 0x16, 0xff, 0xe9, 0xc6, 0xa9, 0x6c, 0x84, 0xf6, 0xce, 0x02, 0x34, 0x1b, 0xb3, 0x47, 0x3b, + 0xfd, 0xe5, 0x20, 0xbf, 0xea, 0x55, 0xf2, 0x0e, 0x5f, 0x80, 0xd0, 0x5c, 0x73, 0xa8, 0xbd, 0x73, + 0xb3, 0xc6, 0x15, 0x3d, 0x71, 0x17, 0x74, 0x9f, 0xe2, 0x75, 0x3f, 0xd8, 0x32, 0xf8, 0xcc, 0x06, + 0xc6, 0x74, 0x85, 0xf0, 0x83, 0xff, 0x74, 0xf2, 0x18, 0xe3, 0x3a, 0xfd, 0x02, 0x65, 0x12, 0x37, + 0xaa, 0xf0, 0x50, 0x80, 0x66, 0x2e, 0x73, 0x6d, 0xe7, 0xa3, 0x2a, 0x08, 0xc1, 0x23, 0xdd, 0x56, + 0x60, 0x56, 0x75, 0x99, 0xa9, 0x49, 0x80, 0xef, 0x71, 0x9b, 0x26, 0xfe, 0x0a, 0xad, 0x5d, 0xce, + 0x65, 0x98, 0x9b, 0x04, 0xd7, 0xd0, 0xd6, 0xe4, 0x09, 0xbe, 0x9f, 0x41, 0x9d, 0xaa, 0x03, 0xd3, + 0xc8, 0x98, 0xc6, 0xa6, 0xbd, 0xf7, 0xcd, 0xbf, 0xa3, 0xf5, 0xd6, 0x47, 0x9b, 0xad, 0x8f, 0x7e, + 0x6d, 0x7d, 0xb4, 0xea, 0x7c, 0x67, 0xd3, 0xf9, 0xce, 0x8f, 0xce, 0x77, 0xf0, 0x94, 0xcb, 0x53, + 0x69, 0xe7, 0xe3, 0x7d, 0x9c, 0x9b, 0x5e, 0xba, 0x41, 0x9f, 0xde, 0xe4, 0xff, 0x0e, 0xf1, 0xfe, + 0xa7, 0x17, 0x05, 0xa4, 0x5a, 0xaa, 0xb0, 0xca, 0x12, 0x9d, 0x84, 0x5c, 0x68, 0x50, 0x22, 0x29, + 0x42, 0xf3, 0x65, 0xa8, 0x39, 0x88, 0xc3, 0x27, 0xf8, 0xed, 0x6c, 0xf2, 0xbe, 0x02, 0xf1, 0x61, + 0xa0, 0x18, 0xfe, 0x70, 0xb9, 0xf4, 0x36, 0x5a, 0xdc, 0x31, 0x73, 0xcf, 0x7f, 0x07, 0x00, 0x00, + 0xff, 0xff, 0xbe, 0xbb, 0xb4, 0xae, 0xce, 0x02, 0x00, 0x00, } func (m *Resource) Marshal() (dAtA []byte, err error) { @@ -135,6 +240,20 @@ func (m *Resource) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Entities) > 0 { + for iNdEx := len(m.Entities) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Entities[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintResource(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } if m.DroppedAttributesCount != 0 { i = encodeVarintResource(dAtA, i, uint64(m.DroppedAttributesCount)) i-- @@ -157,6 +276,61 @@ func (m *Resource) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ResourceEntityRef) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ResourceEntityRef) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ResourceEntityRef) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DescrAttrKeys) > 0 { + for iNdEx := len(m.DescrAttrKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.DescrAttrKeys[iNdEx]) + copy(dAtA[i:], m.DescrAttrKeys[iNdEx]) + i = encodeVarintResource(dAtA, i, uint64(len(m.DescrAttrKeys[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if len(m.IdAttrKeys) > 0 { + for iNdEx := len(m.IdAttrKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.IdAttrKeys[iNdEx]) + copy(dAtA[i:], m.IdAttrKeys[iNdEx]) + i = encodeVarintResource(dAtA, i, uint64(len(m.IdAttrKeys[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintResource(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0x12 + } + if len(m.SchemaUrl) > 0 { + i -= len(m.SchemaUrl) + copy(dAtA[i:], m.SchemaUrl) + i = encodeVarintResource(dAtA, i, uint64(len(m.SchemaUrl))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintResource(dAtA []byte, offset int, v uint64) int { offset -= sovResource(v) base := offset @@ -183,6 +357,41 @@ func (m *Resource) Size() (n int) { if m.DroppedAttributesCount != 0 { n += 1 + sovResource(uint64(m.DroppedAttributesCount)) } + if len(m.Entities) > 0 { + for _, e := range m.Entities { + l = e.Size() + n += 1 + l + sovResource(uint64(l)) + } + } + return n +} + +func (m *ResourceEntityRef) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SchemaUrl) + if l > 0 { + n += 1 + l + sovResource(uint64(l)) + } + l = len(m.Type) + if l > 0 { + n += 1 + l + sovResource(uint64(l)) + } + if len(m.IdAttrKeys) > 0 { + for _, s := range m.IdAttrKeys { + l = len(s) + n += 1 + l + sovResource(uint64(l)) + } + } + if len(m.DescrAttrKeys) > 0 { + for _, s := range m.DescrAttrKeys { + l = len(s) + n += 1 + l + sovResource(uint64(l)) + } + } return n } @@ -274,6 +483,218 @@ func (m *Resource) Unmarshal(dAtA []byte) error { break } } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Entities", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowResource + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthResource + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthResource + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Entities = append(m.Entities, &ResourceEntityRef{}) + if err := m.Entities[len(m.Entities)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipResource(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthResource + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ResourceEntityRef) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowResource + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ResourceEntityRef: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ResourceEntityRef: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SchemaUrl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowResource + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthResource + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthResource + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SchemaUrl = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowResource + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthResource + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthResource + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IdAttrKeys", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowResource + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthResource + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthResource + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IdAttrKeys = append(m.IdAttrKeys, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DescrAttrKeys", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowResource + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthResource + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthResource + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DescrAttrKeys = append(m.DescrAttrKeys, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipResource(dAtA[iNdEx:]) diff --git a/pdata/internal/data/protogen/trace/v1/trace.pb.go b/pdata/internal/data/protogen/trace/v1/trace.pb.go index c1fcf0764e0..8238bdacb3f 100644 --- a/pdata/internal/data/protogen/trace/v1/trace.pb.go +++ b/pdata/internal/data/protogen/trace/v1/trace.pb.go @@ -239,6 +239,8 @@ type ResourceSpans struct { // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url // This schema_url applies to the data in the "resource" field. It does not apply // to the data in the "scope_spans" field which have their own schema_url field. + // + // This field is deprecated in favour of Resource.entities.schema_url. SchemaUrl string `protobuf:"bytes,3,opt,name=schema_url,json=schemaUrl,proto3" json:"schema_url,omitempty"` } diff --git a/pdata/internal/generated_wrapper_resource.go b/pdata/internal/generated_wrapper_resource.go index 354b2457ba7..3ab3dd9a6d5 100644 --- a/pdata/internal/generated_wrapper_resource.go +++ b/pdata/internal/generated_wrapper_resource.go @@ -38,4 +38,5 @@ func GenerateTestResource() Resource { func FillTestResource(tv Resource) { FillTestMap(NewMap(&tv.orig.Attributes, tv.state)) tv.orig.DroppedAttributesCount = uint32(17) + FillTestResourceEntityRefSlice(NewResourceEntityRefSlice(&tv.orig.Entities, tv.state)) } diff --git a/pdata/internal/generated_wrapper_resourceentityref.go b/pdata/internal/generated_wrapper_resourceentityref.go new file mode 100644 index 00000000000..35025fc1c3d --- /dev/null +++ b/pdata/internal/generated_wrapper_resourceentityref.go @@ -0,0 +1,43 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package internal + +import ( + otlpresource "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1" +) + +type ResourceEntityRef struct { + orig *otlpresource.ResourceEntityRef + state *State +} + +func GetOrigResourceEntityRef(ms ResourceEntityRef) *otlpresource.ResourceEntityRef { + return ms.orig +} + +func GetResourceEntityRefState(ms ResourceEntityRef) *State { + return ms.state +} + +func NewResourceEntityRef(orig *otlpresource.ResourceEntityRef, state *State) ResourceEntityRef { + return ResourceEntityRef{orig: orig, state: state} +} + +func GenerateTestResourceEntityRef() ResourceEntityRef { + orig := otlpresource.ResourceEntityRef{} + state := StateMutable + tv := NewResourceEntityRef(&orig, &state) + FillTestResourceEntityRef(tv) + return tv +} + +func FillTestResourceEntityRef(tv ResourceEntityRef) { + tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" + tv.orig.Type = "host" + FillTestStringSlice(NewStringSlice(&tv.orig.IdAttrKeys, tv.state)) + FillTestStringSlice(NewStringSlice(&tv.orig.DescrAttrKeys, tv.state)) +} diff --git a/pdata/internal/generated_wrapper_resourceentityrefslice.go b/pdata/internal/generated_wrapper_resourceentityrefslice.go new file mode 100644 index 00000000000..aee0cb000ca --- /dev/null +++ b/pdata/internal/generated_wrapper_resourceentityrefslice.go @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package internal + +import ( + otlpresource "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1" +) + +type ResourceEntityRefSlice struct { + orig *[]*otlpresource.ResourceEntityRef + state *State +} + +func GetOrigResourceEntityRefSlice(ms ResourceEntityRefSlice) *[]*otlpresource.ResourceEntityRef { + return ms.orig +} + +func GetResourceEntityRefSliceState(ms ResourceEntityRefSlice) *State { + return ms.state +} + +func NewResourceEntityRefSlice(orig *[]*otlpresource.ResourceEntityRef, state *State) ResourceEntityRefSlice { + return ResourceEntityRefSlice{orig: orig, state: state} +} + +func GenerateTestResourceEntityRefSlice() ResourceEntityRefSlice { + orig := []*otlpresource.ResourceEntityRef(nil) + state := StateMutable + es := NewResourceEntityRefSlice(&orig, &state) + FillTestResourceEntityRefSlice(es) + return es +} + +func FillTestResourceEntityRefSlice(es ResourceEntityRefSlice) { + *es.orig = make([]*otlpresource.ResourceEntityRef, 7) + for i := 0; i < 7; i++ { + (*es.orig)[i] = &otlpresource.ResourceEntityRef{} + FillTestResourceEntityRef(NewResourceEntityRef((*es.orig)[i], es.state)) + } +} diff --git a/pdata/internal/wrapper_entities.go b/pdata/internal/wrapper_entities.go new file mode 100644 index 00000000000..ab54f9f36f1 --- /dev/null +++ b/pdata/internal/wrapper_entities.go @@ -0,0 +1,46 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package internal // import "go.opentelemetry.io/collector/pdata/internal" + +import ( + otlpcollectorlog "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/entities/v1" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +type Entities struct { + orig *otlpcollectorlog.ExportEntitiesServiceRequest + state *State +} + +func GetOrigEntities(ms Entities) *otlpcollectorlog.ExportEntitiesServiceRequest { + return ms.orig +} + +func GetEntitiesState(ms Entities) *State { + return ms.state +} + +func SetEntitiesState(ms Entities, state State) { + *ms.state = state +} + +func NewEntities(orig *otlpcollectorlog.ExportEntitiesServiceRequest, state *State) Entities { + return Entities{orig: orig, state: state} +} + +// EntitiesToProto internal helper to convert Entities to protobuf representation. +func EntitiesToProto(l Entities) otlpentities.EntitiesData { + return otlpentities.EntitiesData{ + ScopeEntities: l.orig.ScopeEntities, + } +} + +// EntitiesFromProto internal helper to convert protobuf representation to Entities. +// This function set exclusive state assuming that it's called only once per Entities. +func EntitiesFromProto(orig otlpentities.EntitiesData) Entities { + state := StateMutable + return NewEntities(&otlpcollectorlog.ExportEntitiesServiceRequest{ + ScopeEntities: orig.ScopeEntities, + }, &state) +} diff --git a/pdata/pcommon/generated_instrumentationscope_test.go b/pdata/pcommon/generated_instrumentationscope_test.go index 8dc46fe69c4..23fb4cbb080 100644 --- a/pdata/pcommon/generated_instrumentationscope_test.go +++ b/pdata/pcommon/generated_instrumentationscope_test.go @@ -16,11 +16,11 @@ import ( ) func TestInstrumentationScope_MoveTo(t *testing.T) { - ms := InstrumentationScope(internal.GenerateTestInstrumentationScope()) + ms := generateTestInstrumentationScope() dest := NewInstrumentationScope() ms.MoveTo(dest) assert.Equal(t, NewInstrumentationScope(), ms) - assert.Equal(t, InstrumentationScope(internal.GenerateTestInstrumentationScope()), dest) + assert.Equal(t, generateTestInstrumentationScope(), dest) sharedState := internal.StateReadOnly assert.Panics(t, func() { ms.MoveTo(newInstrumentationScope(&otlpcommon.InstrumentationScope{}, &sharedState)) }) assert.Panics(t, func() { newInstrumentationScope(&otlpcommon.InstrumentationScope{}, &sharedState).MoveTo(dest) }) @@ -31,7 +31,7 @@ func TestInstrumentationScope_CopyTo(t *testing.T) { orig := NewInstrumentationScope() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = InstrumentationScope(internal.GenerateTestInstrumentationScope()) + orig = generateTestInstrumentationScope() orig.CopyTo(ms) assert.Equal(t, orig, ms) sharedState := internal.StateReadOnly @@ -75,3 +75,7 @@ func TestInstrumentationScope_DroppedAttributesCount(t *testing.T) { newInstrumentationScope(&otlpcommon.InstrumentationScope{}, &sharedState).SetDroppedAttributesCount(uint32(17)) }) } + +func generateTestInstrumentationScope() InstrumentationScope { + return InstrumentationScope(internal.GenerateTestInstrumentationScope()) +} diff --git a/pdata/pcommon/generated_resource.go b/pdata/pcommon/generated_resource.go index 12e6cfa7f3b..0455a115664 100644 --- a/pdata/pcommon/generated_resource.go +++ b/pdata/pcommon/generated_resource.go @@ -66,9 +66,15 @@ func (ms Resource) SetDroppedAttributesCount(v uint32) { ms.getOrig().DroppedAttributesCount = v } +// Entities returns the Entities associated with this Resource. +func (ms Resource) Entities() ResourceEntityRefSlice { + return ResourceEntityRefSlice(internal.NewResourceEntityRefSlice(&ms.getOrig().Entities, internal.GetResourceState(internal.Resource(ms)))) +} + // CopyTo copies all properties from the current struct overriding the destination. func (ms Resource) CopyTo(dest Resource) { dest.getState().AssertMutable() ms.Attributes().CopyTo(dest.Attributes()) dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) + ms.Entities().CopyTo(dest.Entities()) } diff --git a/pdata/pcommon/generated_resource_test.go b/pdata/pcommon/generated_resource_test.go index a7af5300fe8..5094fad3d1a 100644 --- a/pdata/pcommon/generated_resource_test.go +++ b/pdata/pcommon/generated_resource_test.go @@ -16,11 +16,11 @@ import ( ) func TestResource_MoveTo(t *testing.T) { - ms := Resource(internal.GenerateTestResource()) + ms := generateTestResource() dest := NewResource() ms.MoveTo(dest) assert.Equal(t, NewResource(), ms) - assert.Equal(t, Resource(internal.GenerateTestResource()), dest) + assert.Equal(t, generateTestResource(), dest) sharedState := internal.StateReadOnly assert.Panics(t, func() { ms.MoveTo(newResource(&otlpresource.Resource{}, &sharedState)) }) assert.Panics(t, func() { newResource(&otlpresource.Resource{}, &sharedState).MoveTo(dest) }) @@ -31,7 +31,7 @@ func TestResource_CopyTo(t *testing.T) { orig := NewResource() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Resource(internal.GenerateTestResource()) + orig = generateTestResource() orig.CopyTo(ms) assert.Equal(t, orig, ms) sharedState := internal.StateReadOnly @@ -53,3 +53,14 @@ func TestResource_DroppedAttributesCount(t *testing.T) { sharedState := internal.StateReadOnly assert.Panics(t, func() { newResource(&otlpresource.Resource{}, &sharedState).SetDroppedAttributesCount(uint32(17)) }) } + +func TestResource_Entities(t *testing.T) { + ms := NewResource() + assert.Equal(t, NewResourceEntityRefSlice(), ms.Entities()) + internal.FillTestResourceEntityRefSlice(internal.ResourceEntityRefSlice(ms.Entities())) + assert.Equal(t, ResourceEntityRefSlice(internal.GenerateTestResourceEntityRefSlice()), ms.Entities()) +} + +func generateTestResource() Resource { + return Resource(internal.GenerateTestResource()) +} diff --git a/pdata/pcommon/generated_resourceentityref.go b/pdata/pcommon/generated_resourceentityref.go new file mode 100644 index 00000000000..0cffa0f4f8b --- /dev/null +++ b/pdata/pcommon/generated_resourceentityref.go @@ -0,0 +1,90 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pcommon + +import ( + "go.opentelemetry.io/collector/pdata/internal" + otlpresource "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1" +) + +// This is a reference type, if passed by value and callee modifies it the +// caller will see the modification. +// +// Must use NewResourceEntityRef function to create new instances. +// Important: zero-initialized instance is not valid for use. +type ResourceEntityRef internal.ResourceEntityRef + +func newResourceEntityRef(orig *otlpresource.ResourceEntityRef, state *internal.State) ResourceEntityRef { + return ResourceEntityRef(internal.NewResourceEntityRef(orig, state)) +} + +// NewResourceEntityRef creates a new empty ResourceEntityRef. +// +// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, +// OR directly access the member if this is embedded in another struct. +func NewResourceEntityRef() ResourceEntityRef { + state := internal.StateMutable + return newResourceEntityRef(&otlpresource.ResourceEntityRef{}, &state) +} + +// MoveTo moves all properties from the current struct overriding the destination and +// resetting the current instance to its zero value +func (ms ResourceEntityRef) MoveTo(dest ResourceEntityRef) { + ms.getState().AssertMutable() + dest.getState().AssertMutable() + *dest.getOrig() = *ms.getOrig() + *ms.getOrig() = otlpresource.ResourceEntityRef{} +} + +func (ms ResourceEntityRef) getOrig() *otlpresource.ResourceEntityRef { + return internal.GetOrigResourceEntityRef(internal.ResourceEntityRef(ms)) +} + +func (ms ResourceEntityRef) getState() *internal.State { + return internal.GetResourceEntityRefState(internal.ResourceEntityRef(ms)) +} + +// SchemaUrl returns the schemaurl associated with this ResourceEntityRef. +func (ms ResourceEntityRef) SchemaUrl() string { + return ms.getOrig().SchemaUrl +} + +// SetSchemaUrl replaces the schemaurl associated with this ResourceEntityRef. +func (ms ResourceEntityRef) SetSchemaUrl(v string) { + ms.getState().AssertMutable() + ms.getOrig().SchemaUrl = v +} + +// Type returns the type associated with this ResourceEntityRef. +func (ms ResourceEntityRef) Type() string { + return ms.getOrig().Type +} + +// SetType replaces the type associated with this ResourceEntityRef. +func (ms ResourceEntityRef) SetType(v string) { + ms.getState().AssertMutable() + ms.getOrig().Type = v +} + +// IdAttrKeys returns the IdAttrKeys associated with this ResourceEntityRef. +func (ms ResourceEntityRef) IdAttrKeys() StringSlice { + return StringSlice(internal.NewStringSlice(&ms.getOrig().IdAttrKeys, internal.GetResourceEntityRefState(internal.ResourceEntityRef(ms)))) +} + +// DescrAttrKeys returns the DescrAttrKeys associated with this ResourceEntityRef. +func (ms ResourceEntityRef) DescrAttrKeys() StringSlice { + return StringSlice(internal.NewStringSlice(&ms.getOrig().DescrAttrKeys, internal.GetResourceEntityRefState(internal.ResourceEntityRef(ms)))) +} + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms ResourceEntityRef) CopyTo(dest ResourceEntityRef) { + dest.getState().AssertMutable() + dest.SetSchemaUrl(ms.SchemaUrl()) + dest.SetType(ms.Type()) + ms.IdAttrKeys().CopyTo(dest.IdAttrKeys()) + ms.DescrAttrKeys().CopyTo(dest.DescrAttrKeys()) +} diff --git a/pdata/pcommon/generated_resourceentityref_test.go b/pdata/pcommon/generated_resourceentityref_test.go new file mode 100644 index 00000000000..b51717eacfc --- /dev/null +++ b/pdata/pcommon/generated_resourceentityref_test.go @@ -0,0 +1,77 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pcommon + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpresource "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1" +) + +func TestResourceEntityRef_MoveTo(t *testing.T) { + ms := generateTestResourceEntityRef() + dest := NewResourceEntityRef() + ms.MoveTo(dest) + assert.Equal(t, NewResourceEntityRef(), ms) + assert.Equal(t, generateTestResourceEntityRef(), dest) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.MoveTo(newResourceEntityRef(&otlpresource.ResourceEntityRef{}, &sharedState)) }) + assert.Panics(t, func() { newResourceEntityRef(&otlpresource.ResourceEntityRef{}, &sharedState).MoveTo(dest) }) +} + +func TestResourceEntityRef_CopyTo(t *testing.T) { + ms := NewResourceEntityRef() + orig := NewResourceEntityRef() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + orig = generateTestResourceEntityRef() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.CopyTo(newResourceEntityRef(&otlpresource.ResourceEntityRef{}, &sharedState)) }) +} + +func TestResourceEntityRef_SchemaUrl(t *testing.T) { + ms := NewResourceEntityRef() + assert.Equal(t, "", ms.SchemaUrl()) + ms.SetSchemaUrl("https://opentelemetry.io/schemas/1.5.0") + assert.Equal(t, "https://opentelemetry.io/schemas/1.5.0", ms.SchemaUrl()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { + newResourceEntityRef(&otlpresource.ResourceEntityRef{}, &sharedState).SetSchemaUrl("https://opentelemetry.io/schemas/1.5.0") + }) +} + +func TestResourceEntityRef_Type(t *testing.T) { + ms := NewResourceEntityRef() + assert.Equal(t, "", ms.Type()) + ms.SetType("host") + assert.Equal(t, "host", ms.Type()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { newResourceEntityRef(&otlpresource.ResourceEntityRef{}, &sharedState).SetType("host") }) +} + +func TestResourceEntityRef_IdAttrKeys(t *testing.T) { + ms := NewResourceEntityRef() + assert.Equal(t, NewStringSlice(), ms.IdAttrKeys()) + internal.FillTestStringSlice(internal.StringSlice(ms.IdAttrKeys())) + assert.Equal(t, StringSlice(internal.GenerateTestStringSlice()), ms.IdAttrKeys()) +} + +func TestResourceEntityRef_DescrAttrKeys(t *testing.T) { + ms := NewResourceEntityRef() + assert.Equal(t, NewStringSlice(), ms.DescrAttrKeys()) + internal.FillTestStringSlice(internal.StringSlice(ms.DescrAttrKeys())) + assert.Equal(t, StringSlice(internal.GenerateTestStringSlice()), ms.DescrAttrKeys()) +} + +func generateTestResourceEntityRef() ResourceEntityRef { + return ResourceEntityRef(internal.GenerateTestResourceEntityRef()) +} diff --git a/pdata/pcommon/generated_resourceentityrefslice.go b/pdata/pcommon/generated_resourceentityrefslice.go new file mode 100644 index 00000000000..8d6117ed108 --- /dev/null +++ b/pdata/pcommon/generated_resourceentityrefslice.go @@ -0,0 +1,157 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pcommon + +import ( + "sort" + + "go.opentelemetry.io/collector/pdata/internal" + otlpresource "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1" +) + +// ResourceEntityRefSlice logically represents a slice of ResourceEntityRef. +// +// This is a reference type. If passed by value and callee modifies it, the +// caller will see the modification. +// +// Must use NewResourceEntityRefSlice function to create new instances. +// Important: zero-initialized instance is not valid for use. +type ResourceEntityRefSlice internal.ResourceEntityRefSlice + +func newResourceEntityRefSlice(orig *[]*otlpresource.ResourceEntityRef, state *internal.State) ResourceEntityRefSlice { + return ResourceEntityRefSlice(internal.NewResourceEntityRefSlice(orig, state)) +} + +// NewResourceEntityRefSlice creates a ResourceEntityRefSlice with 0 elements. +// Can use "EnsureCapacity" to initialize with a given capacity. +func NewResourceEntityRefSlice() ResourceEntityRefSlice { + orig := []*otlpresource.ResourceEntityRef(nil) + state := internal.StateMutable + return newResourceEntityRefSlice(&orig, &state) +} + +// Len returns the number of elements in the slice. +// +// Returns "0" for a newly instance created with "NewResourceEntityRefSlice()". +func (es ResourceEntityRefSlice) Len() int { + return len(*es.getOrig()) +} + +// At returns the element at the given index. +// +// This function is used mostly for iterating over all the values in the slice: +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } +func (es ResourceEntityRefSlice) At(i int) ResourceEntityRef { + return newResourceEntityRef((*es.getOrig())[i], es.getState()) +} + +// EnsureCapacity is an operation that ensures the slice has at least the specified capacity. +// 1. If the newCap <= cap then no change in capacity. +// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. +// +// Here is how a new ResourceEntityRefSlice can be initialized: +// +// es := NewResourceEntityRefSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } +func (es ResourceEntityRefSlice) EnsureCapacity(newCap int) { + es.getState().AssertMutable() + oldCap := cap(*es.getOrig()) + if newCap <= oldCap { + return + } + + newOrig := make([]*otlpresource.ResourceEntityRef, len(*es.getOrig()), newCap) + copy(newOrig, *es.getOrig()) + *es.getOrig() = newOrig +} + +// AppendEmpty will append to the end of the slice an empty ResourceEntityRef. +// It returns the newly added ResourceEntityRef. +func (es ResourceEntityRefSlice) AppendEmpty() ResourceEntityRef { + es.getState().AssertMutable() + *es.getOrig() = append(*es.getOrig(), &otlpresource.ResourceEntityRef{}) + return es.At(es.Len() - 1) +} + +// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. +// The current slice will be cleared. +func (es ResourceEntityRefSlice) MoveAndAppendTo(dest ResourceEntityRefSlice) { + es.getState().AssertMutable() + dest.getState().AssertMutable() + if *dest.getOrig() == nil { + // We can simply move the entire vector and avoid any allocations. + *dest.getOrig() = *es.getOrig() + } else { + *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + } + *es.getOrig() = nil +} + +// RemoveIf calls f sequentially for each element present in the slice. +// If f returns true, the element is removed from the slice. +func (es ResourceEntityRefSlice) RemoveIf(f func(ResourceEntityRef) bool) { + es.getState().AssertMutable() + newLen := 0 + for i := 0; i < len(*es.getOrig()); i++ { + if f(es.At(i)) { + continue + } + if newLen == i { + // Nothing to move, element is at the right place. + newLen++ + continue + } + (*es.getOrig())[newLen] = (*es.getOrig())[i] + newLen++ + } + *es.getOrig() = (*es.getOrig())[:newLen] +} + +// CopyTo copies all elements from the current slice overriding the destination. +func (es ResourceEntityRefSlice) CopyTo(dest ResourceEntityRefSlice) { + dest.getState().AssertMutable() + srcLen := es.Len() + destCap := cap(*dest.getOrig()) + if srcLen <= destCap { + (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] + for i := range *es.getOrig() { + newResourceEntityRef((*es.getOrig())[i], es.getState()).CopyTo(newResourceEntityRef((*dest.getOrig())[i], dest.getState())) + } + return + } + origs := make([]otlpresource.ResourceEntityRef, srcLen) + wrappers := make([]*otlpresource.ResourceEntityRef, srcLen) + for i := range *es.getOrig() { + wrappers[i] = &origs[i] + newResourceEntityRef((*es.getOrig())[i], es.getState()).CopyTo(newResourceEntityRef(wrappers[i], dest.getState())) + } + *dest.getOrig() = wrappers +} + +// Sort sorts the ResourceEntityRef elements within ResourceEntityRefSlice given the +// provided less function so that two instances of ResourceEntityRefSlice +// can be compared. +func (es ResourceEntityRefSlice) Sort(less func(a, b ResourceEntityRef) bool) { + es.getState().AssertMutable() + sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) +} + +func (ms ResourceEntityRefSlice) getOrig() *[]*otlpresource.ResourceEntityRef { + return internal.GetOrigResourceEntityRefSlice(internal.ResourceEntityRefSlice(ms)) +} + +func (ms ResourceEntityRefSlice) getState() *internal.State { + return internal.GetResourceEntityRefSliceState(internal.ResourceEntityRefSlice(ms)) +} diff --git a/pdata/pcommon/generated_resourceentityrefslice_test.go b/pdata/pcommon/generated_resourceentityrefslice_test.go new file mode 100644 index 00000000000..1e4cbed44f7 --- /dev/null +++ b/pdata/pcommon/generated_resourceentityrefslice_test.go @@ -0,0 +1,144 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pcommon + +import ( + "testing" + "unsafe" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpresource "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1" +) + +func TestResourceEntityRefSlice(t *testing.T) { + es := NewResourceEntityRefSlice() + assert.Equal(t, 0, es.Len()) + state := internal.StateMutable + es = newResourceEntityRefSlice(&[]*otlpresource.ResourceEntityRef{}, &state) + assert.Equal(t, 0, es.Len()) + + emptyVal := NewResourceEntityRef() + testVal := ResourceEntityRef(internal.GenerateTestResourceEntityRef()) + for i := 0; i < 7; i++ { + el := es.AppendEmpty() + assert.Equal(t, emptyVal, es.At(i)) + internal.FillTestResourceEntityRef(internal.ResourceEntityRef(el)) + assert.Equal(t, testVal, es.At(i)) + } + assert.Equal(t, 7, es.Len()) +} + +func TestResourceEntityRefSliceReadOnly(t *testing.T) { + sharedState := internal.StateReadOnly + es := newResourceEntityRefSlice(&[]*otlpresource.ResourceEntityRef{}, &sharedState) + assert.Equal(t, 0, es.Len()) + assert.Panics(t, func() { es.AppendEmpty() }) + assert.Panics(t, func() { es.EnsureCapacity(2) }) + es2 := NewResourceEntityRefSlice() + es.CopyTo(es2) + assert.Panics(t, func() { es2.CopyTo(es) }) + assert.Panics(t, func() { es.MoveAndAppendTo(es2) }) + assert.Panics(t, func() { es2.MoveAndAppendTo(es) }) +} + +func TestResourceEntityRefSlice_CopyTo(t *testing.T) { + dest := NewResourceEntityRefSlice() + // Test CopyTo to empty + NewResourceEntityRefSlice().CopyTo(dest) + assert.Equal(t, NewResourceEntityRefSlice(), dest) + + // Test CopyTo larger slice + generateTestResourceEntityRefSlice().CopyTo(dest) + assert.Equal(t, generateTestResourceEntityRefSlice(), dest) + + // Test CopyTo same size slice + generateTestResourceEntityRefSlice().CopyTo(dest) + assert.Equal(t, generateTestResourceEntityRefSlice(), dest) +} + +func TestResourceEntityRefSlice_EnsureCapacity(t *testing.T) { + es := generateTestResourceEntityRefSlice() + + // Test ensure smaller capacity. + const ensureSmallLen = 4 + es.EnsureCapacity(ensureSmallLen) + assert.Less(t, ensureSmallLen, es.Len()) + assert.Equal(t, es.Len(), cap(*es.getOrig())) + assert.Equal(t, generateTestResourceEntityRefSlice(), es) + + // Test ensure larger capacity + const ensureLargeLen = 9 + es.EnsureCapacity(ensureLargeLen) + assert.Less(t, generateTestResourceEntityRefSlice().Len(), ensureLargeLen) + assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, generateTestResourceEntityRefSlice(), es) +} + +func TestResourceEntityRefSlice_MoveAndAppendTo(t *testing.T) { + // Test MoveAndAppendTo to empty + expectedSlice := generateTestResourceEntityRefSlice() + dest := NewResourceEntityRefSlice() + src := generateTestResourceEntityRefSlice() + src.MoveAndAppendTo(dest) + assert.Equal(t, generateTestResourceEntityRefSlice(), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo empty slice + src.MoveAndAppendTo(dest) + assert.Equal(t, generateTestResourceEntityRefSlice(), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo not empty slice + generateTestResourceEntityRefSlice().MoveAndAppendTo(dest) + assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) + for i := 0; i < expectedSlice.Len(); i++ { + assert.Equal(t, expectedSlice.At(i), dest.At(i)) + assert.Equal(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) + } +} + +func TestResourceEntityRefSlice_RemoveIf(t *testing.T) { + // Test RemoveIf on empty slice + emptySlice := NewResourceEntityRefSlice() + emptySlice.RemoveIf(func(el ResourceEntityRef) bool { + t.Fail() + return false + }) + + // Test RemoveIf + filtered := generateTestResourceEntityRefSlice() + pos := 0 + filtered.RemoveIf(func(el ResourceEntityRef) bool { + pos++ + return pos%3 == 0 + }) + assert.Equal(t, 5, filtered.Len()) +} + +func TestResourceEntityRefSlice_Sort(t *testing.T) { + es := generateTestResourceEntityRefSlice() + es.Sort(func(a, b ResourceEntityRef) bool { + return uintptr(unsafe.Pointer(a.getOrig())) < uintptr(unsafe.Pointer(b.getOrig())) + }) + for i := 1; i < es.Len(); i++ { + assert.Less(t, uintptr(unsafe.Pointer(es.At(i-1).getOrig())), uintptr(unsafe.Pointer(es.At(i).getOrig()))) + } + es.Sort(func(a, b ResourceEntityRef) bool { + return uintptr(unsafe.Pointer(a.getOrig())) > uintptr(unsafe.Pointer(b.getOrig())) + }) + for i := 1; i < es.Len(); i++ { + assert.Greater(t, uintptr(unsafe.Pointer(es.At(i-1).getOrig())), uintptr(unsafe.Pointer(es.At(i).getOrig()))) + } +} + +func generateTestResourceEntityRefSlice() ResourceEntityRefSlice { + return ResourceEntityRefSlice(internal.GenerateTestResourceEntityRefSlice()) +} diff --git a/pdata/pentity/entities.go b/pdata/pentity/entities.go new file mode 100644 index 00000000000..fbb41bd36f0 --- /dev/null +++ b/pdata/pentity/entities.go @@ -0,0 +1,62 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package pentity // import "go.opentelemetry.io/collector/pdata/pentity" + +import ( + "go.opentelemetry.io/collector/pdata/internal" + otlpcollectorlog "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/entities/v1" +) + +// Entities is the top-level struct that is propagated through the entities pipeline. +// Use NewEntities to create new instance, zero-initialized instance is not valid for use. +type Entities internal.Entities + +func newEntities(orig *otlpcollectorlog.ExportEntitiesServiceRequest) Entities { + state := internal.StateMutable + return Entities(internal.NewEntities(orig, &state)) +} + +func (ms Entities) getOrig() *otlpcollectorlog.ExportEntitiesServiceRequest { + return internal.GetOrigEntities(internal.Entities(ms)) +} + +func (ms Entities) getState() *internal.State { + return internal.GetEntitiesState(internal.Entities(ms)) +} + +// NewEntities creates a new Entities struct. +func NewEntities() Entities { + return newEntities(&otlpcollectorlog.ExportEntitiesServiceRequest{}) +} + +// IsReadOnly returns true if this Entities instance is read-only. +func (ms Entities) IsReadOnly() bool { + return *ms.getState() == internal.StateReadOnly +} + +// CopyTo copies the Entities instance overriding the destination. +func (ms Entities) CopyTo(dest Entities) { + ms.ScopeEntities().CopyTo(dest.ScopeEntities()) +} + +// LogRecordCount calculates the total number of log records. +func (ms Entities) LogRecordCount() int { + logCount := 0 + ill := ms.ScopeEntities() + for i := 0; i < ill.Len(); i++ { + entities := ill.At(i) + logCount += entities.EntityEvents().Len() + } + return logCount +} + +// ScopeEntities returns the ScopeEntitiesSlice associated with this Entities. +func (ms Entities) ScopeEntities() ScopeEntitiesSlice { + return newScopeEntitiesSlice(&ms.getOrig().ScopeEntities, internal.GetEntitiesState(internal.Entities(ms))) +} + +// MarkReadOnly marks the Entities as shared so that no further modifications can be done on it. +func (ms Entities) MarkReadOnly() { + internal.SetEntitiesState(internal.Entities(ms), internal.StateReadOnly) +} diff --git a/pdata/pentity/event_type.go b/pdata/pentity/event_type.go new file mode 100644 index 00000000000..8e5d3268ea9 --- /dev/null +++ b/pdata/pentity/event_type.go @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package pentity // import "go.opentelemetry.io/collector/pdata/pentity" + +// EventType specifies the type of entity event. +type EventType int32 + +const ( + // EventTypeEmpty means that metric type is unset. + EventTypeEmpty EventType = iota + EventTypeEntityState + EventTypeEntityDelete +) + +// String returns the string representation of the EventType. +func (mdt EventType) String() string { + switch mdt { + case EventTypeEmpty: + return "Empty" + case EventTypeEntityState: + return "State" + case EventTypeEntityDelete: + return "Delete" + } + return "" +} diff --git a/pdata/pentity/generated_entitydelete.go b/pdata/pentity/generated_entitydelete.go new file mode 100644 index 00000000000..67a80a15bbe --- /dev/null +++ b/pdata/pentity/generated_entitydelete.go @@ -0,0 +1,51 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +// EntityDelete are experimental implementation of OpenTelemetry Entity Data Model. + +// This is a reference type, if passed by value and callee modifies it the +// caller will see the modification. +// +// Must use NewEntityDelete function to create new instances. +// Important: zero-initialized instance is not valid for use. +type EntityDelete struct { + orig *otlpentities.EntityDelete + state *internal.State +} + +func newEntityDelete(orig *otlpentities.EntityDelete, state *internal.State) EntityDelete { + return EntityDelete{orig: orig, state: state} +} + +// NewEntityDelete creates a new empty EntityDelete. +// +// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, +// OR directly access the member if this is embedded in another struct. +func NewEntityDelete() EntityDelete { + state := internal.StateMutable + return newEntityDelete(&otlpentities.EntityDelete{}, &state) +} + +// MoveTo moves all properties from the current struct overriding the destination and +// resetting the current instance to its zero value +func (ms EntityDelete) MoveTo(dest EntityDelete) { + ms.state.AssertMutable() + dest.state.AssertMutable() + *dest.orig = *ms.orig + *ms.orig = otlpentities.EntityDelete{} +} + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms EntityDelete) CopyTo(dest EntityDelete) { + dest.state.AssertMutable() +} diff --git a/pdata/pentity/generated_entitydelete_test.go b/pdata/pentity/generated_entitydelete_test.go new file mode 100644 index 00000000000..7fe04c748a4 --- /dev/null +++ b/pdata/pentity/generated_entitydelete_test.go @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +func TestEntityDelete_MoveTo(t *testing.T) { + ms := generateTestEntityDelete() + dest := NewEntityDelete() + ms.MoveTo(dest) + assert.Equal(t, NewEntityDelete(), ms) + assert.Equal(t, generateTestEntityDelete(), dest) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.MoveTo(newEntityDelete(&otlpentities.EntityDelete{}, &sharedState)) }) + assert.Panics(t, func() { newEntityDelete(&otlpentities.EntityDelete{}, &sharedState).MoveTo(dest) }) +} + +func TestEntityDelete_CopyTo(t *testing.T) { + ms := NewEntityDelete() + orig := NewEntityDelete() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + orig = generateTestEntityDelete() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.CopyTo(newEntityDelete(&otlpentities.EntityDelete{}, &sharedState)) }) +} + +func generateTestEntityDelete() EntityDelete { + tv := NewEntityDelete() + fillTestEntityDelete(tv) + return tv +} + +func fillTestEntityDelete(tv EntityDelete) { +} diff --git a/pdata/pentity/generated_entityevent.go b/pdata/pentity/generated_entityevent.go new file mode 100644 index 00000000000..686239b7163 --- /dev/null +++ b/pdata/pentity/generated_entityevent.go @@ -0,0 +1,153 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" + "go.opentelemetry.io/collector/pdata/pcommon" +) + +// EntityEvent are experimental implementation of OpenTelemetry Entity Data Model. + +// This is a reference type, if passed by value and callee modifies it the +// caller will see the modification. +// +// Must use NewEntityEvent function to create new instances. +// Important: zero-initialized instance is not valid for use. +type EntityEvent struct { + orig *otlpentities.EntityEvent + state *internal.State +} + +func newEntityEvent(orig *otlpentities.EntityEvent, state *internal.State) EntityEvent { + return EntityEvent{orig: orig, state: state} +} + +// NewEntityEvent creates a new empty EntityEvent. +// +// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, +// OR directly access the member if this is embedded in another struct. +func NewEntityEvent() EntityEvent { + state := internal.StateMutable + return newEntityEvent(&otlpentities.EntityEvent{}, &state) +} + +// MoveTo moves all properties from the current struct overriding the destination and +// resetting the current instance to its zero value +func (ms EntityEvent) MoveTo(dest EntityEvent) { + ms.state.AssertMutable() + dest.state.AssertMutable() + *dest.orig = *ms.orig + *ms.orig = otlpentities.EntityEvent{} +} + +// Timestamp returns the timestamp associated with this EntityEvent. +func (ms EntityEvent) Timestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.orig.TimeUnixNano) +} + +// SetTimestamp replaces the timestamp associated with this EntityEvent. +func (ms EntityEvent) SetTimestamp(v pcommon.Timestamp) { + ms.state.AssertMutable() + ms.orig.TimeUnixNano = uint64(v) +} + +// EntityType returns the entitytype associated with this EntityEvent. +func (ms EntityEvent) EntityType() string { + return ms.orig.EntityType +} + +// SetEntityType replaces the entitytype associated with this EntityEvent. +func (ms EntityEvent) SetEntityType(v string) { + ms.state.AssertMutable() + ms.orig.EntityType = v +} + +// Id returns the Id associated with this EntityEvent. +func (ms EntityEvent) Id() pcommon.Map { + return pcommon.Map(internal.NewMap(&ms.orig.Id, ms.state)) +} + +// Type returns the type of the data for this EntityEvent. +// Calling this function on zero-initialized EntityEvent will cause a panic. +func (ms EntityEvent) Type() EventType { + switch ms.orig.Data.(type) { + case *otlpentities.EntityEvent_EntityState: + return EventTypeEntityState + case *otlpentities.EntityEvent_EntityDelete: + return EventTypeEntityDelete + } + return EventTypeEmpty +} + +// EntityState returns the entitystate associated with this EntityEvent. +// +// Calling this function when Type() != EventTypeEntityState returns an invalid +// zero-initialized instance of EntityState. Note that using such EntityState instance can cause panic. +// +// Calling this function on zero-initialized EntityEvent will cause a panic. +func (ms EntityEvent) EntityState() EntityState { + v, ok := ms.orig.GetData().(*otlpentities.EntityEvent_EntityState) + if !ok { + return EntityState{} + } + return newEntityState(v.EntityState, ms.state) +} + +// SetEmptyEntityState sets an empty entitystate to this EntityEvent. +// +// After this, Type() function will return EventTypeEntityState". +// +// Calling this function on zero-initialized EntityEvent will cause a panic. +func (ms EntityEvent) SetEmptyEntityState() EntityState { + ms.state.AssertMutable() + val := &otlpentities.EntityState{} + ms.orig.Data = &otlpentities.EntityEvent_EntityState{EntityState: val} + return newEntityState(val, ms.state) +} + +// EntityDelete returns the entitydelete associated with this EntityEvent. +// +// Calling this function when Type() != EventTypeEntityDelete returns an invalid +// zero-initialized instance of EntityDelete. Note that using such EntityDelete instance can cause panic. +// +// Calling this function on zero-initialized EntityEvent will cause a panic. +func (ms EntityEvent) EntityDelete() EntityDelete { + v, ok := ms.orig.GetData().(*otlpentities.EntityEvent_EntityDelete) + if !ok { + return EntityDelete{} + } + return newEntityDelete(v.EntityDelete, ms.state) +} + +// SetEmptyEntityDelete sets an empty entitydelete to this EntityEvent. +// +// After this, Type() function will return EventTypeEntityDelete". +// +// Calling this function on zero-initialized EntityEvent will cause a panic. +func (ms EntityEvent) SetEmptyEntityDelete() EntityDelete { + ms.state.AssertMutable() + val := &otlpentities.EntityDelete{} + ms.orig.Data = &otlpentities.EntityEvent_EntityDelete{EntityDelete: val} + return newEntityDelete(val, ms.state) +} + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms EntityEvent) CopyTo(dest EntityEvent) { + dest.state.AssertMutable() + dest.SetTimestamp(ms.Timestamp()) + dest.SetEntityType(ms.EntityType()) + ms.Id().CopyTo(dest.Id()) + switch ms.Type() { + case EventTypeEntityState: + ms.EntityState().CopyTo(dest.SetEmptyEntityState()) + case EventTypeEntityDelete: + ms.EntityDelete().CopyTo(dest.SetEmptyEntityDelete()) + } + +} diff --git a/pdata/pentity/generated_entityevent_test.go b/pdata/pentity/generated_entityevent_test.go new file mode 100644 index 00000000000..8f32217d0db --- /dev/null +++ b/pdata/pentity/generated_entityevent_test.go @@ -0,0 +1,121 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" + "go.opentelemetry.io/collector/pdata/pcommon" +) + +func TestEntityEvent_MoveTo(t *testing.T) { + ms := generateTestEntityEvent() + dest := NewEntityEvent() + ms.MoveTo(dest) + assert.Equal(t, NewEntityEvent(), ms) + assert.Equal(t, generateTestEntityEvent(), dest) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.MoveTo(newEntityEvent(&otlpentities.EntityEvent{}, &sharedState)) }) + assert.Panics(t, func() { newEntityEvent(&otlpentities.EntityEvent{}, &sharedState).MoveTo(dest) }) +} + +func TestEntityEvent_CopyTo(t *testing.T) { + ms := NewEntityEvent() + orig := NewEntityEvent() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + orig = generateTestEntityEvent() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.CopyTo(newEntityEvent(&otlpentities.EntityEvent{}, &sharedState)) }) +} + +func TestEntityEvent_Timestamp(t *testing.T) { + ms := NewEntityEvent() + assert.Equal(t, pcommon.Timestamp(0), ms.Timestamp()) + testValTimestamp := pcommon.Timestamp(1234567890) + ms.SetTimestamp(testValTimestamp) + assert.Equal(t, testValTimestamp, ms.Timestamp()) +} + +func TestEntityEvent_EntityType(t *testing.T) { + ms := NewEntityEvent() + assert.Equal(t, "", ms.EntityType()) + ms.SetEntityType("service") + assert.Equal(t, "service", ms.EntityType()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { newEntityEvent(&otlpentities.EntityEvent{}, &sharedState).SetEntityType("service") }) +} + +func TestEntityEvent_Id(t *testing.T) { + ms := NewEntityEvent() + assert.Equal(t, pcommon.NewMap(), ms.Id()) + internal.FillTestMap(internal.Map(ms.Id())) + assert.Equal(t, pcommon.Map(internal.GenerateTestMap()), ms.Id()) +} + +func TestEntityEvent_Type(t *testing.T) { + tv := NewEntityEvent() + assert.Equal(t, EventTypeEmpty, tv.Type()) +} + +func TestEntityEvent_EntityState(t *testing.T) { + ms := NewEntityEvent() + fillTestEntityState(ms.SetEmptyEntityState()) + assert.Equal(t, EventTypeEntityState, ms.Type()) + assert.Equal(t, generateTestEntityState(), ms.EntityState()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { newEntityEvent(&otlpentities.EntityEvent{}, &sharedState).SetEmptyEntityState() }) +} + +func TestEntityEvent_CopyTo_EntityState(t *testing.T) { + ms := NewEntityEvent() + fillTestEntityState(ms.SetEmptyEntityState()) + dest := NewEntityEvent() + ms.CopyTo(dest) + assert.Equal(t, ms, dest) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.CopyTo(newEntityEvent(&otlpentities.EntityEvent{}, &sharedState)) }) +} + +func TestEntityEvent_EntityDelete(t *testing.T) { + ms := NewEntityEvent() + fillTestEntityDelete(ms.SetEmptyEntityDelete()) + assert.Equal(t, EventTypeEntityDelete, ms.Type()) + assert.Equal(t, generateTestEntityDelete(), ms.EntityDelete()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { newEntityEvent(&otlpentities.EntityEvent{}, &sharedState).SetEmptyEntityDelete() }) +} + +func TestEntityEvent_CopyTo_EntityDelete(t *testing.T) { + ms := NewEntityEvent() + fillTestEntityDelete(ms.SetEmptyEntityDelete()) + dest := NewEntityEvent() + ms.CopyTo(dest) + assert.Equal(t, ms, dest) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.CopyTo(newEntityEvent(&otlpentities.EntityEvent{}, &sharedState)) }) +} + +func generateTestEntityEvent() EntityEvent { + tv := NewEntityEvent() + fillTestEntityEvent(tv) + return tv +} + +func fillTestEntityEvent(tv EntityEvent) { + tv.orig.TimeUnixNano = 1234567890 + tv.orig.EntityType = "service" + internal.FillTestMap(internal.NewMap(&tv.orig.Id, tv.state)) + tv.orig.Data = &otlpentities.EntityEvent_EntityDelete{EntityDelete: &otlpentities.EntityDelete{}} + fillTestEntityDelete(newEntityDelete(tv.orig.GetEntityDelete(), tv.state)) +} diff --git a/pdata/pentity/generated_entityeventslice.go b/pdata/pentity/generated_entityeventslice.go new file mode 100644 index 00000000000..c2cf40960f9 --- /dev/null +++ b/pdata/pentity/generated_entityeventslice.go @@ -0,0 +1,152 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "sort" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +// EntityEventSlice logically represents a slice of EntityEvent. +// +// This is a reference type. If passed by value and callee modifies it, the +// caller will see the modification. +// +// Must use NewEntityEventSlice function to create new instances. +// Important: zero-initialized instance is not valid for use. +type EntityEventSlice struct { + orig *[]*otlpentities.EntityEvent + state *internal.State +} + +func newEntityEventSlice(orig *[]*otlpentities.EntityEvent, state *internal.State) EntityEventSlice { + return EntityEventSlice{orig: orig, state: state} +} + +// NewEntityEventSlice creates a EntityEventSlice with 0 elements. +// Can use "EnsureCapacity" to initialize with a given capacity. +func NewEntityEventSlice() EntityEventSlice { + orig := []*otlpentities.EntityEvent(nil) + state := internal.StateMutable + return newEntityEventSlice(&orig, &state) +} + +// Len returns the number of elements in the slice. +// +// Returns "0" for a newly instance created with "NewEntityEventSlice()". +func (es EntityEventSlice) Len() int { + return len(*es.orig) +} + +// At returns the element at the given index. +// +// This function is used mostly for iterating over all the values in the slice: +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } +func (es EntityEventSlice) At(i int) EntityEvent { + return newEntityEvent((*es.orig)[i], es.state) +} + +// EnsureCapacity is an operation that ensures the slice has at least the specified capacity. +// 1. If the newCap <= cap then no change in capacity. +// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. +// +// Here is how a new EntityEventSlice can be initialized: +// +// es := NewEntityEventSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } +func (es EntityEventSlice) EnsureCapacity(newCap int) { + es.state.AssertMutable() + oldCap := cap(*es.orig) + if newCap <= oldCap { + return + } + + newOrig := make([]*otlpentities.EntityEvent, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig +} + +// AppendEmpty will append to the end of the slice an empty EntityEvent. +// It returns the newly added EntityEvent. +func (es EntityEventSlice) AppendEmpty() EntityEvent { + es.state.AssertMutable() + *es.orig = append(*es.orig, &otlpentities.EntityEvent{}) + return es.At(es.Len() - 1) +} + +// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. +// The current slice will be cleared. +func (es EntityEventSlice) MoveAndAppendTo(dest EntityEventSlice) { + es.state.AssertMutable() + dest.state.AssertMutable() + if *dest.orig == nil { + // We can simply move the entire vector and avoid any allocations. + *dest.orig = *es.orig + } else { + *dest.orig = append(*dest.orig, *es.orig...) + } + *es.orig = nil +} + +// RemoveIf calls f sequentially for each element present in the slice. +// If f returns true, the element is removed from the slice. +func (es EntityEventSlice) RemoveIf(f func(EntityEvent) bool) { + es.state.AssertMutable() + newLen := 0 + for i := 0; i < len(*es.orig); i++ { + if f(es.At(i)) { + continue + } + if newLen == i { + // Nothing to move, element is at the right place. + newLen++ + continue + } + (*es.orig)[newLen] = (*es.orig)[i] + newLen++ + } + *es.orig = (*es.orig)[:newLen] +} + +// CopyTo copies all elements from the current slice overriding the destination. +func (es EntityEventSlice) CopyTo(dest EntityEventSlice) { + dest.state.AssertMutable() + srcLen := es.Len() + destCap := cap(*dest.orig) + if srcLen <= destCap { + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newEntityEvent((*es.orig)[i], es.state).CopyTo(newEntityEvent((*dest.orig)[i], dest.state)) + } + return + } + origs := make([]otlpentities.EntityEvent, srcLen) + wrappers := make([]*otlpentities.EntityEvent, srcLen) + for i := range *es.orig { + wrappers[i] = &origs[i] + newEntityEvent((*es.orig)[i], es.state).CopyTo(newEntityEvent(wrappers[i], dest.state)) + } + *dest.orig = wrappers +} + +// Sort sorts the EntityEvent elements within EntityEventSlice given the +// provided less function so that two instances of EntityEventSlice +// can be compared. +func (es EntityEventSlice) Sort(less func(a, b EntityEvent) bool) { + es.state.AssertMutable() + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) +} diff --git a/pdata/pentity/generated_entityeventslice_test.go b/pdata/pentity/generated_entityeventslice_test.go new file mode 100644 index 00000000000..f0b088fc7bd --- /dev/null +++ b/pdata/pentity/generated_entityeventslice_test.go @@ -0,0 +1,154 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "testing" + "unsafe" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +func TestEntityEventSlice(t *testing.T) { + es := NewEntityEventSlice() + assert.Equal(t, 0, es.Len()) + state := internal.StateMutable + es = newEntityEventSlice(&[]*otlpentities.EntityEvent{}, &state) + assert.Equal(t, 0, es.Len()) + + emptyVal := NewEntityEvent() + testVal := generateTestEntityEvent() + for i := 0; i < 7; i++ { + el := es.AppendEmpty() + assert.Equal(t, emptyVal, es.At(i)) + fillTestEntityEvent(el) + assert.Equal(t, testVal, es.At(i)) + } + assert.Equal(t, 7, es.Len()) +} + +func TestEntityEventSliceReadOnly(t *testing.T) { + sharedState := internal.StateReadOnly + es := newEntityEventSlice(&[]*otlpentities.EntityEvent{}, &sharedState) + assert.Equal(t, 0, es.Len()) + assert.Panics(t, func() { es.AppendEmpty() }) + assert.Panics(t, func() { es.EnsureCapacity(2) }) + es2 := NewEntityEventSlice() + es.CopyTo(es2) + assert.Panics(t, func() { es2.CopyTo(es) }) + assert.Panics(t, func() { es.MoveAndAppendTo(es2) }) + assert.Panics(t, func() { es2.MoveAndAppendTo(es) }) +} + +func TestEntityEventSlice_CopyTo(t *testing.T) { + dest := NewEntityEventSlice() + // Test CopyTo to empty + NewEntityEventSlice().CopyTo(dest) + assert.Equal(t, NewEntityEventSlice(), dest) + + // Test CopyTo larger slice + generateTestEntityEventSlice().CopyTo(dest) + assert.Equal(t, generateTestEntityEventSlice(), dest) + + // Test CopyTo same size slice + generateTestEntityEventSlice().CopyTo(dest) + assert.Equal(t, generateTestEntityEventSlice(), dest) +} + +func TestEntityEventSlice_EnsureCapacity(t *testing.T) { + es := generateTestEntityEventSlice() + + // Test ensure smaller capacity. + const ensureSmallLen = 4 + es.EnsureCapacity(ensureSmallLen) + assert.Less(t, ensureSmallLen, es.Len()) + assert.Equal(t, es.Len(), cap(*es.orig)) + assert.Equal(t, generateTestEntityEventSlice(), es) + + // Test ensure larger capacity + const ensureLargeLen = 9 + es.EnsureCapacity(ensureLargeLen) + assert.Less(t, generateTestEntityEventSlice().Len(), ensureLargeLen) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) + assert.Equal(t, generateTestEntityEventSlice(), es) +} + +func TestEntityEventSlice_MoveAndAppendTo(t *testing.T) { + // Test MoveAndAppendTo to empty + expectedSlice := generateTestEntityEventSlice() + dest := NewEntityEventSlice() + src := generateTestEntityEventSlice() + src.MoveAndAppendTo(dest) + assert.Equal(t, generateTestEntityEventSlice(), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo empty slice + src.MoveAndAppendTo(dest) + assert.Equal(t, generateTestEntityEventSlice(), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo not empty slice + generateTestEntityEventSlice().MoveAndAppendTo(dest) + assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) + for i := 0; i < expectedSlice.Len(); i++ { + assert.Equal(t, expectedSlice.At(i), dest.At(i)) + assert.Equal(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) + } +} + +func TestEntityEventSlice_RemoveIf(t *testing.T) { + // Test RemoveIf on empty slice + emptySlice := NewEntityEventSlice() + emptySlice.RemoveIf(func(el EntityEvent) bool { + t.Fail() + return false + }) + + // Test RemoveIf + filtered := generateTestEntityEventSlice() + pos := 0 + filtered.RemoveIf(func(el EntityEvent) bool { + pos++ + return pos%3 == 0 + }) + assert.Equal(t, 5, filtered.Len()) +} + +func TestEntityEventSlice_Sort(t *testing.T) { + es := generateTestEntityEventSlice() + es.Sort(func(a, b EntityEvent) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.Less(t, uintptr(unsafe.Pointer(es.At(i-1).orig)), uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b EntityEvent) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.Greater(t, uintptr(unsafe.Pointer(es.At(i-1).orig)), uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + +func generateTestEntityEventSlice() EntityEventSlice { + es := NewEntityEventSlice() + fillTestEntityEventSlice(es) + return es +} + +func fillTestEntityEventSlice(es EntityEventSlice) { + *es.orig = make([]*otlpentities.EntityEvent, 7) + for i := 0; i < 7; i++ { + (*es.orig)[i] = &otlpentities.EntityEvent{} + fillTestEntityEvent(newEntityEvent((*es.orig)[i], es.state)) + } +} diff --git a/pdata/pentity/generated_entitystate.go b/pdata/pentity/generated_entitystate.go new file mode 100644 index 00000000000..a4687343927 --- /dev/null +++ b/pdata/pentity/generated_entitystate.go @@ -0,0 +1,70 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" + "go.opentelemetry.io/collector/pdata/pcommon" +) + +// EntityState are experimental implementation of OpenTelemetry Entity Data Model. + +// This is a reference type, if passed by value and callee modifies it the +// caller will see the modification. +// +// Must use NewEntityState function to create new instances. +// Important: zero-initialized instance is not valid for use. +type EntityState struct { + orig *otlpentities.EntityState + state *internal.State +} + +func newEntityState(orig *otlpentities.EntityState, state *internal.State) EntityState { + return EntityState{orig: orig, state: state} +} + +// NewEntityState creates a new empty EntityState. +// +// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, +// OR directly access the member if this is embedded in another struct. +func NewEntityState() EntityState { + state := internal.StateMutable + return newEntityState(&otlpentities.EntityState{}, &state) +} + +// MoveTo moves all properties from the current struct overriding the destination and +// resetting the current instance to its zero value +func (ms EntityState) MoveTo(dest EntityState) { + ms.state.AssertMutable() + dest.state.AssertMutable() + *dest.orig = *ms.orig + *ms.orig = otlpentities.EntityState{} +} + +// Attributes returns the Attributes associated with this EntityState. +func (ms EntityState) Attributes() pcommon.Map { + return pcommon.Map(internal.NewMap(&ms.orig.Attributes, ms.state)) +} + +// DroppedAttributesCount returns the droppedattributescount associated with this EntityState. +func (ms EntityState) DroppedAttributesCount() uint32 { + return ms.orig.DroppedAttributesCount +} + +// SetDroppedAttributesCount replaces the droppedattributescount associated with this EntityState. +func (ms EntityState) SetDroppedAttributesCount(v uint32) { + ms.state.AssertMutable() + ms.orig.DroppedAttributesCount = v +} + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms EntityState) CopyTo(dest EntityState) { + dest.state.AssertMutable() + ms.Attributes().CopyTo(dest.Attributes()) + dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) +} diff --git a/pdata/pentity/generated_entitystate_test.go b/pdata/pentity/generated_entitystate_test.go new file mode 100644 index 00000000000..6f455dd8adb --- /dev/null +++ b/pdata/pentity/generated_entitystate_test.go @@ -0,0 +1,69 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" + "go.opentelemetry.io/collector/pdata/pcommon" +) + +func TestEntityState_MoveTo(t *testing.T) { + ms := generateTestEntityState() + dest := NewEntityState() + ms.MoveTo(dest) + assert.Equal(t, NewEntityState(), ms) + assert.Equal(t, generateTestEntityState(), dest) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.MoveTo(newEntityState(&otlpentities.EntityState{}, &sharedState)) }) + assert.Panics(t, func() { newEntityState(&otlpentities.EntityState{}, &sharedState).MoveTo(dest) }) +} + +func TestEntityState_CopyTo(t *testing.T) { + ms := NewEntityState() + orig := NewEntityState() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + orig = generateTestEntityState() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.CopyTo(newEntityState(&otlpentities.EntityState{}, &sharedState)) }) +} + +func TestEntityState_Attributes(t *testing.T) { + ms := NewEntityState() + assert.Equal(t, pcommon.NewMap(), ms.Attributes()) + internal.FillTestMap(internal.Map(ms.Attributes())) + assert.Equal(t, pcommon.Map(internal.GenerateTestMap()), ms.Attributes()) +} + +func TestEntityState_DroppedAttributesCount(t *testing.T) { + ms := NewEntityState() + assert.Equal(t, uint32(0), ms.DroppedAttributesCount()) + ms.SetDroppedAttributesCount(uint32(17)) + assert.Equal(t, uint32(17), ms.DroppedAttributesCount()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { + newEntityState(&otlpentities.EntityState{}, &sharedState).SetDroppedAttributesCount(uint32(17)) + }) +} + +func generateTestEntityState() EntityState { + tv := NewEntityState() + fillTestEntityState(tv) + return tv +} + +func fillTestEntityState(tv EntityState) { + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes, tv.state)) + tv.orig.DroppedAttributesCount = uint32(17) +} diff --git a/pdata/pentity/generated_entitystateslice.go b/pdata/pentity/generated_entitystateslice.go new file mode 100644 index 00000000000..a4df068ae84 --- /dev/null +++ b/pdata/pentity/generated_entitystateslice.go @@ -0,0 +1,152 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "sort" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +// EntityStateSlice logically represents a slice of EntityState. +// +// This is a reference type. If passed by value and callee modifies it, the +// caller will see the modification. +// +// Must use NewEntityStateSlice function to create new instances. +// Important: zero-initialized instance is not valid for use. +type EntityStateSlice struct { + orig *[]*otlpentities.EntityState + state *internal.State +} + +func newEntityStateSlice(orig *[]*otlpentities.EntityState, state *internal.State) EntityStateSlice { + return EntityStateSlice{orig: orig, state: state} +} + +// NewEntityStateSlice creates a EntityStateSlice with 0 elements. +// Can use "EnsureCapacity" to initialize with a given capacity. +func NewEntityStateSlice() EntityStateSlice { + orig := []*otlpentities.EntityState(nil) + state := internal.StateMutable + return newEntityStateSlice(&orig, &state) +} + +// Len returns the number of elements in the slice. +// +// Returns "0" for a newly instance created with "NewEntityStateSlice()". +func (es EntityStateSlice) Len() int { + return len(*es.orig) +} + +// At returns the element at the given index. +// +// This function is used mostly for iterating over all the values in the slice: +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } +func (es EntityStateSlice) At(i int) EntityState { + return newEntityState((*es.orig)[i], es.state) +} + +// EnsureCapacity is an operation that ensures the slice has at least the specified capacity. +// 1. If the newCap <= cap then no change in capacity. +// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. +// +// Here is how a new EntityStateSlice can be initialized: +// +// es := NewEntityStateSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } +func (es EntityStateSlice) EnsureCapacity(newCap int) { + es.state.AssertMutable() + oldCap := cap(*es.orig) + if newCap <= oldCap { + return + } + + newOrig := make([]*otlpentities.EntityState, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig +} + +// AppendEmpty will append to the end of the slice an empty EntityState. +// It returns the newly added EntityState. +func (es EntityStateSlice) AppendEmpty() EntityState { + es.state.AssertMutable() + *es.orig = append(*es.orig, &otlpentities.EntityState{}) + return es.At(es.Len() - 1) +} + +// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. +// The current slice will be cleared. +func (es EntityStateSlice) MoveAndAppendTo(dest EntityStateSlice) { + es.state.AssertMutable() + dest.state.AssertMutable() + if *dest.orig == nil { + // We can simply move the entire vector and avoid any allocations. + *dest.orig = *es.orig + } else { + *dest.orig = append(*dest.orig, *es.orig...) + } + *es.orig = nil +} + +// RemoveIf calls f sequentially for each element present in the slice. +// If f returns true, the element is removed from the slice. +func (es EntityStateSlice) RemoveIf(f func(EntityState) bool) { + es.state.AssertMutable() + newLen := 0 + for i := 0; i < len(*es.orig); i++ { + if f(es.At(i)) { + continue + } + if newLen == i { + // Nothing to move, element is at the right place. + newLen++ + continue + } + (*es.orig)[newLen] = (*es.orig)[i] + newLen++ + } + *es.orig = (*es.orig)[:newLen] +} + +// CopyTo copies all elements from the current slice overriding the destination. +func (es EntityStateSlice) CopyTo(dest EntityStateSlice) { + dest.state.AssertMutable() + srcLen := es.Len() + destCap := cap(*dest.orig) + if srcLen <= destCap { + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newEntityState((*es.orig)[i], es.state).CopyTo(newEntityState((*dest.orig)[i], dest.state)) + } + return + } + origs := make([]otlpentities.EntityState, srcLen) + wrappers := make([]*otlpentities.EntityState, srcLen) + for i := range *es.orig { + wrappers[i] = &origs[i] + newEntityState((*es.orig)[i], es.state).CopyTo(newEntityState(wrappers[i], dest.state)) + } + *dest.orig = wrappers +} + +// Sort sorts the EntityState elements within EntityStateSlice given the +// provided less function so that two instances of EntityStateSlice +// can be compared. +func (es EntityStateSlice) Sort(less func(a, b EntityState) bool) { + es.state.AssertMutable() + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) +} diff --git a/pdata/pentity/generated_entitystateslice_test.go b/pdata/pentity/generated_entitystateslice_test.go new file mode 100644 index 00000000000..cfa145b5b98 --- /dev/null +++ b/pdata/pentity/generated_entitystateslice_test.go @@ -0,0 +1,154 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "testing" + "unsafe" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +func TestEntityStateSlice(t *testing.T) { + es := NewEntityStateSlice() + assert.Equal(t, 0, es.Len()) + state := internal.StateMutable + es = newEntityStateSlice(&[]*otlpentities.EntityState{}, &state) + assert.Equal(t, 0, es.Len()) + + emptyVal := NewEntityState() + testVal := generateTestEntityState() + for i := 0; i < 7; i++ { + el := es.AppendEmpty() + assert.Equal(t, emptyVal, es.At(i)) + fillTestEntityState(el) + assert.Equal(t, testVal, es.At(i)) + } + assert.Equal(t, 7, es.Len()) +} + +func TestEntityStateSliceReadOnly(t *testing.T) { + sharedState := internal.StateReadOnly + es := newEntityStateSlice(&[]*otlpentities.EntityState{}, &sharedState) + assert.Equal(t, 0, es.Len()) + assert.Panics(t, func() { es.AppendEmpty() }) + assert.Panics(t, func() { es.EnsureCapacity(2) }) + es2 := NewEntityStateSlice() + es.CopyTo(es2) + assert.Panics(t, func() { es2.CopyTo(es) }) + assert.Panics(t, func() { es.MoveAndAppendTo(es2) }) + assert.Panics(t, func() { es2.MoveAndAppendTo(es) }) +} + +func TestEntityStateSlice_CopyTo(t *testing.T) { + dest := NewEntityStateSlice() + // Test CopyTo to empty + NewEntityStateSlice().CopyTo(dest) + assert.Equal(t, NewEntityStateSlice(), dest) + + // Test CopyTo larger slice + generateTestEntityStateSlice().CopyTo(dest) + assert.Equal(t, generateTestEntityStateSlice(), dest) + + // Test CopyTo same size slice + generateTestEntityStateSlice().CopyTo(dest) + assert.Equal(t, generateTestEntityStateSlice(), dest) +} + +func TestEntityStateSlice_EnsureCapacity(t *testing.T) { + es := generateTestEntityStateSlice() + + // Test ensure smaller capacity. + const ensureSmallLen = 4 + es.EnsureCapacity(ensureSmallLen) + assert.Less(t, ensureSmallLen, es.Len()) + assert.Equal(t, es.Len(), cap(*es.orig)) + assert.Equal(t, generateTestEntityStateSlice(), es) + + // Test ensure larger capacity + const ensureLargeLen = 9 + es.EnsureCapacity(ensureLargeLen) + assert.Less(t, generateTestEntityStateSlice().Len(), ensureLargeLen) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) + assert.Equal(t, generateTestEntityStateSlice(), es) +} + +func TestEntityStateSlice_MoveAndAppendTo(t *testing.T) { + // Test MoveAndAppendTo to empty + expectedSlice := generateTestEntityStateSlice() + dest := NewEntityStateSlice() + src := generateTestEntityStateSlice() + src.MoveAndAppendTo(dest) + assert.Equal(t, generateTestEntityStateSlice(), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo empty slice + src.MoveAndAppendTo(dest) + assert.Equal(t, generateTestEntityStateSlice(), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo not empty slice + generateTestEntityStateSlice().MoveAndAppendTo(dest) + assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) + for i := 0; i < expectedSlice.Len(); i++ { + assert.Equal(t, expectedSlice.At(i), dest.At(i)) + assert.Equal(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) + } +} + +func TestEntityStateSlice_RemoveIf(t *testing.T) { + // Test RemoveIf on empty slice + emptySlice := NewEntityStateSlice() + emptySlice.RemoveIf(func(el EntityState) bool { + t.Fail() + return false + }) + + // Test RemoveIf + filtered := generateTestEntityStateSlice() + pos := 0 + filtered.RemoveIf(func(el EntityState) bool { + pos++ + return pos%3 == 0 + }) + assert.Equal(t, 5, filtered.Len()) +} + +func TestEntityStateSlice_Sort(t *testing.T) { + es := generateTestEntityStateSlice() + es.Sort(func(a, b EntityState) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) < uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b EntityState) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.True(t, uintptr(unsafe.Pointer(es.At(i-1).orig)) > uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + +func generateTestEntityStateSlice() EntityStateSlice { + es := NewEntityStateSlice() + fillTestEntityStateSlice(es) + return es +} + +func fillTestEntityStateSlice(es EntityStateSlice) { + *es.orig = make([]*otlpentities.EntityState, 7) + for i := 0; i < 7; i++ { + (*es.orig)[i] = &otlpentities.EntityState{} + fillTestEntityState(newEntityState((*es.orig)[i], es.state)) + } +} diff --git a/pdata/pentity/generated_scopeentities.go b/pdata/pentity/generated_scopeentities.go new file mode 100644 index 00000000000..9f6f9376ea7 --- /dev/null +++ b/pdata/pentity/generated_scopeentities.go @@ -0,0 +1,76 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" + "go.opentelemetry.io/collector/pdata/pcommon" +) + +// ScopeEntities is a collection of entities from a LibraryInstrumentation. +// +// This is a reference type, if passed by value and callee modifies it the +// caller will see the modification. +// +// Must use NewScopeEntities function to create new instances. +// Important: zero-initialized instance is not valid for use. +type ScopeEntities struct { + orig *otlpentities.ScopeEntities + state *internal.State +} + +func newScopeEntities(orig *otlpentities.ScopeEntities, state *internal.State) ScopeEntities { + return ScopeEntities{orig: orig, state: state} +} + +// NewScopeEntities creates a new empty ScopeEntities. +// +// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, +// OR directly access the member if this is embedded in another struct. +func NewScopeEntities() ScopeEntities { + state := internal.StateMutable + return newScopeEntities(&otlpentities.ScopeEntities{}, &state) +} + +// MoveTo moves all properties from the current struct overriding the destination and +// resetting the current instance to its zero value +func (ms ScopeEntities) MoveTo(dest ScopeEntities) { + ms.state.AssertMutable() + dest.state.AssertMutable() + *dest.orig = *ms.orig + *ms.orig = otlpentities.ScopeEntities{} +} + +// Scope returns the scope associated with this ScopeEntities. +func (ms ScopeEntities) Scope() pcommon.InstrumentationScope { + return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.orig.Scope, ms.state)) +} + +// SchemaUrl returns the schemaurl associated with this ScopeEntities. +func (ms ScopeEntities) SchemaUrl() string { + return ms.orig.SchemaUrl +} + +// SetSchemaUrl replaces the schemaurl associated with this ScopeEntities. +func (ms ScopeEntities) SetSchemaUrl(v string) { + ms.state.AssertMutable() + ms.orig.SchemaUrl = v +} + +// EntityEvents returns the EntityEvents associated with this ScopeEntities. +func (ms ScopeEntities) EntityEvents() EntityEventSlice { + return newEntityEventSlice(&ms.orig.EntityEvents, ms.state) +} + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms ScopeEntities) CopyTo(dest ScopeEntities) { + dest.state.AssertMutable() + ms.Scope().CopyTo(dest.Scope()) + dest.SetSchemaUrl(ms.SchemaUrl()) + ms.EntityEvents().CopyTo(dest.EntityEvents()) +} diff --git a/pdata/pentity/generated_scopeentities_test.go b/pdata/pentity/generated_scopeentities_test.go new file mode 100644 index 00000000000..2e03b67f8a4 --- /dev/null +++ b/pdata/pentity/generated_scopeentities_test.go @@ -0,0 +1,76 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" + "go.opentelemetry.io/collector/pdata/pcommon" +) + +func TestScopeEntities_MoveTo(t *testing.T) { + ms := generateTestScopeEntities() + dest := NewScopeEntities() + ms.MoveTo(dest) + assert.Equal(t, NewScopeEntities(), ms) + assert.Equal(t, generateTestScopeEntities(), dest) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.MoveTo(newScopeEntities(&otlpentities.ScopeEntities{}, &sharedState)) }) + assert.Panics(t, func() { newScopeEntities(&otlpentities.ScopeEntities{}, &sharedState).MoveTo(dest) }) +} + +func TestScopeEntities_CopyTo(t *testing.T) { + ms := NewScopeEntities() + orig := NewScopeEntities() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + orig = generateTestScopeEntities() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { ms.CopyTo(newScopeEntities(&otlpentities.ScopeEntities{}, &sharedState)) }) +} + +func TestScopeEntities_Scope(t *testing.T) { + ms := NewScopeEntities() + internal.FillTestInstrumentationScope(internal.InstrumentationScope(ms.Scope())) + assert.Equal(t, pcommon.InstrumentationScope(internal.GenerateTestInstrumentationScope()), ms.Scope()) +} + +func TestScopeEntities_SchemaUrl(t *testing.T) { + ms := NewScopeEntities() + assert.Equal(t, "", ms.SchemaUrl()) + ms.SetSchemaUrl("https://opentelemetry.io/schemas/1.5.0") + assert.Equal(t, "https://opentelemetry.io/schemas/1.5.0", ms.SchemaUrl()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { + newScopeEntities(&otlpentities.ScopeEntities{}, &sharedState).SetSchemaUrl("https://opentelemetry.io/schemas/1.5.0") + }) +} + +func TestScopeEntities_EntityEvents(t *testing.T) { + ms := NewScopeEntities() + assert.Equal(t, NewEntityEventSlice(), ms.EntityEvents()) + fillTestEntityEventSlice(ms.EntityEvents()) + assert.Equal(t, generateTestEntityEventSlice(), ms.EntityEvents()) +} + +func generateTestScopeEntities() ScopeEntities { + tv := NewScopeEntities() + fillTestScopeEntities(tv) + return tv +} + +func fillTestScopeEntities(tv ScopeEntities) { + internal.FillTestInstrumentationScope(internal.NewInstrumentationScope(&tv.orig.Scope, tv.state)) + tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" + fillTestEntityEventSlice(newEntityEventSlice(&tv.orig.EntityEvents, tv.state)) +} diff --git a/pdata/pentity/generated_scopeentitiesslice.go b/pdata/pentity/generated_scopeentitiesslice.go new file mode 100644 index 00000000000..685120203e0 --- /dev/null +++ b/pdata/pentity/generated_scopeentitiesslice.go @@ -0,0 +1,152 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "sort" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +// ScopeEntitiesSlice logically represents a slice of ScopeEntities. +// +// This is a reference type. If passed by value and callee modifies it, the +// caller will see the modification. +// +// Must use NewScopeEntitiesSlice function to create new instances. +// Important: zero-initialized instance is not valid for use. +type ScopeEntitiesSlice struct { + orig *[]*otlpentities.ScopeEntities + state *internal.State +} + +func newScopeEntitiesSlice(orig *[]*otlpentities.ScopeEntities, state *internal.State) ScopeEntitiesSlice { + return ScopeEntitiesSlice{orig: orig, state: state} +} + +// NewScopeEntitiesSlice creates a ScopeEntitiesSlice with 0 elements. +// Can use "EnsureCapacity" to initialize with a given capacity. +func NewScopeEntitiesSlice() ScopeEntitiesSlice { + orig := []*otlpentities.ScopeEntities(nil) + state := internal.StateMutable + return newScopeEntitiesSlice(&orig, &state) +} + +// Len returns the number of elements in the slice. +// +// Returns "0" for a newly instance created with "NewScopeEntitiesSlice()". +func (es ScopeEntitiesSlice) Len() int { + return len(*es.orig) +} + +// At returns the element at the given index. +// +// This function is used mostly for iterating over all the values in the slice: +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } +func (es ScopeEntitiesSlice) At(i int) ScopeEntities { + return newScopeEntities((*es.orig)[i], es.state) +} + +// EnsureCapacity is an operation that ensures the slice has at least the specified capacity. +// 1. If the newCap <= cap then no change in capacity. +// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. +// +// Here is how a new ScopeEntitiesSlice can be initialized: +// +// es := NewScopeEntitiesSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } +func (es ScopeEntitiesSlice) EnsureCapacity(newCap int) { + es.state.AssertMutable() + oldCap := cap(*es.orig) + if newCap <= oldCap { + return + } + + newOrig := make([]*otlpentities.ScopeEntities, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig +} + +// AppendEmpty will append to the end of the slice an empty ScopeEntities. +// It returns the newly added ScopeEntities. +func (es ScopeEntitiesSlice) AppendEmpty() ScopeEntities { + es.state.AssertMutable() + *es.orig = append(*es.orig, &otlpentities.ScopeEntities{}) + return es.At(es.Len() - 1) +} + +// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. +// The current slice will be cleared. +func (es ScopeEntitiesSlice) MoveAndAppendTo(dest ScopeEntitiesSlice) { + es.state.AssertMutable() + dest.state.AssertMutable() + if *dest.orig == nil { + // We can simply move the entire vector and avoid any allocations. + *dest.orig = *es.orig + } else { + *dest.orig = append(*dest.orig, *es.orig...) + } + *es.orig = nil +} + +// RemoveIf calls f sequentially for each element present in the slice. +// If f returns true, the element is removed from the slice. +func (es ScopeEntitiesSlice) RemoveIf(f func(ScopeEntities) bool) { + es.state.AssertMutable() + newLen := 0 + for i := 0; i < len(*es.orig); i++ { + if f(es.At(i)) { + continue + } + if newLen == i { + // Nothing to move, element is at the right place. + newLen++ + continue + } + (*es.orig)[newLen] = (*es.orig)[i] + newLen++ + } + *es.orig = (*es.orig)[:newLen] +} + +// CopyTo copies all elements from the current slice overriding the destination. +func (es ScopeEntitiesSlice) CopyTo(dest ScopeEntitiesSlice) { + dest.state.AssertMutable() + srcLen := es.Len() + destCap := cap(*dest.orig) + if srcLen <= destCap { + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newScopeEntities((*es.orig)[i], es.state).CopyTo(newScopeEntities((*dest.orig)[i], dest.state)) + } + return + } + origs := make([]otlpentities.ScopeEntities, srcLen) + wrappers := make([]*otlpentities.ScopeEntities, srcLen) + for i := range *es.orig { + wrappers[i] = &origs[i] + newScopeEntities((*es.orig)[i], es.state).CopyTo(newScopeEntities(wrappers[i], dest.state)) + } + *dest.orig = wrappers +} + +// Sort sorts the ScopeEntities elements within ScopeEntitiesSlice given the +// provided less function so that two instances of ScopeEntitiesSlice +// can be compared. +func (es ScopeEntitiesSlice) Sort(less func(a, b ScopeEntities) bool) { + es.state.AssertMutable() + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) +} diff --git a/pdata/pentity/generated_scopeentitiesslice_test.go b/pdata/pentity/generated_scopeentitiesslice_test.go new file mode 100644 index 00000000000..34284bea52a --- /dev/null +++ b/pdata/pentity/generated_scopeentitiesslice_test.go @@ -0,0 +1,154 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentity + +import ( + "testing" + "unsafe" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpentities "go.opentelemetry.io/collector/pdata/internal/data/protogen/entities/v1" +) + +func TestScopeEntitiesSlice(t *testing.T) { + es := NewScopeEntitiesSlice() + assert.Equal(t, 0, es.Len()) + state := internal.StateMutable + es = newScopeEntitiesSlice(&[]*otlpentities.ScopeEntities{}, &state) + assert.Equal(t, 0, es.Len()) + + emptyVal := NewScopeEntities() + testVal := generateTestScopeEntities() + for i := 0; i < 7; i++ { + el := es.AppendEmpty() + assert.Equal(t, emptyVal, es.At(i)) + fillTestScopeEntities(el) + assert.Equal(t, testVal, es.At(i)) + } + assert.Equal(t, 7, es.Len()) +} + +func TestScopeEntitiesSliceReadOnly(t *testing.T) { + sharedState := internal.StateReadOnly + es := newScopeEntitiesSlice(&[]*otlpentities.ScopeEntities{}, &sharedState) + assert.Equal(t, 0, es.Len()) + assert.Panics(t, func() { es.AppendEmpty() }) + assert.Panics(t, func() { es.EnsureCapacity(2) }) + es2 := NewScopeEntitiesSlice() + es.CopyTo(es2) + assert.Panics(t, func() { es2.CopyTo(es) }) + assert.Panics(t, func() { es.MoveAndAppendTo(es2) }) + assert.Panics(t, func() { es2.MoveAndAppendTo(es) }) +} + +func TestScopeEntitiesSlice_CopyTo(t *testing.T) { + dest := NewScopeEntitiesSlice() + // Test CopyTo to empty + NewScopeEntitiesSlice().CopyTo(dest) + assert.Equal(t, NewScopeEntitiesSlice(), dest) + + // Test CopyTo larger slice + generateTestScopeEntitiesSlice().CopyTo(dest) + assert.Equal(t, generateTestScopeEntitiesSlice(), dest) + + // Test CopyTo same size slice + generateTestScopeEntitiesSlice().CopyTo(dest) + assert.Equal(t, generateTestScopeEntitiesSlice(), dest) +} + +func TestScopeEntitiesSlice_EnsureCapacity(t *testing.T) { + es := generateTestScopeEntitiesSlice() + + // Test ensure smaller capacity. + const ensureSmallLen = 4 + es.EnsureCapacity(ensureSmallLen) + assert.Less(t, ensureSmallLen, es.Len()) + assert.Equal(t, es.Len(), cap(*es.orig)) + assert.Equal(t, generateTestScopeEntitiesSlice(), es) + + // Test ensure larger capacity + const ensureLargeLen = 9 + es.EnsureCapacity(ensureLargeLen) + assert.Less(t, generateTestScopeEntitiesSlice().Len(), ensureLargeLen) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) + assert.Equal(t, generateTestScopeEntitiesSlice(), es) +} + +func TestScopeEntitiesSlice_MoveAndAppendTo(t *testing.T) { + // Test MoveAndAppendTo to empty + expectedSlice := generateTestScopeEntitiesSlice() + dest := NewScopeEntitiesSlice() + src := generateTestScopeEntitiesSlice() + src.MoveAndAppendTo(dest) + assert.Equal(t, generateTestScopeEntitiesSlice(), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo empty slice + src.MoveAndAppendTo(dest) + assert.Equal(t, generateTestScopeEntitiesSlice(), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo not empty slice + generateTestScopeEntitiesSlice().MoveAndAppendTo(dest) + assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) + for i := 0; i < expectedSlice.Len(); i++ { + assert.Equal(t, expectedSlice.At(i), dest.At(i)) + assert.Equal(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) + } +} + +func TestScopeEntitiesSlice_RemoveIf(t *testing.T) { + // Test RemoveIf on empty slice + emptySlice := NewScopeEntitiesSlice() + emptySlice.RemoveIf(func(el ScopeEntities) bool { + t.Fail() + return false + }) + + // Test RemoveIf + filtered := generateTestScopeEntitiesSlice() + pos := 0 + filtered.RemoveIf(func(el ScopeEntities) bool { + pos++ + return pos%3 == 0 + }) + assert.Equal(t, 5, filtered.Len()) +} + +func TestScopeEntitiesSlice_Sort(t *testing.T) { + es := generateTestScopeEntitiesSlice() + es.Sort(func(a, b ScopeEntities) bool { + return uintptr(unsafe.Pointer(a.orig)) < uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.Less(t, uintptr(unsafe.Pointer(es.At(i-1).orig)), uintptr(unsafe.Pointer(es.At(i).orig))) + } + es.Sort(func(a, b ScopeEntities) bool { + return uintptr(unsafe.Pointer(a.orig)) > uintptr(unsafe.Pointer(b.orig)) + }) + for i := 1; i < es.Len(); i++ { + assert.Greater(t, uintptr(unsafe.Pointer(es.At(i-1).orig)), uintptr(unsafe.Pointer(es.At(i).orig))) + } +} + +func generateTestScopeEntitiesSlice() ScopeEntitiesSlice { + es := NewScopeEntitiesSlice() + fillTestScopeEntitiesSlice(es) + return es +} + +func fillTestScopeEntitiesSlice(es ScopeEntitiesSlice) { + *es.orig = make([]*otlpentities.ScopeEntities, 7) + for i := 0; i < 7; i++ { + (*es.orig)[i] = &otlpentities.ScopeEntities{} + fillTestScopeEntities(newScopeEntities((*es.orig)[i], es.state)) + } +} diff --git a/pdata/pentity/pentityotlp/generated_exportpartialsuccess.go b/pdata/pentity/pentityotlp/generated_exportpartialsuccess.go new file mode 100644 index 00000000000..c367b1fab78 --- /dev/null +++ b/pdata/pentity/pentityotlp/generated_exportpartialsuccess.go @@ -0,0 +1,75 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentityotlp + +import ( + "go.opentelemetry.io/collector/pdata/internal" + otlpcollectorentity "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/entities/v1" +) + +// ExportPartialSuccess represents the details of a partially successful export request. +// +// This is a reference type, if passed by value and callee modifies it the +// caller will see the modification. +// +// Must use NewExportPartialSuccess function to create new instances. +// Important: zero-initialized instance is not valid for use. +type ExportPartialSuccess struct { + orig *otlpcollectorentity.ExportEntitiesPartialSuccess + state *internal.State +} + +func newExportPartialSuccess(orig *otlpcollectorentity.ExportEntitiesPartialSuccess, state *internal.State) ExportPartialSuccess { + return ExportPartialSuccess{orig: orig, state: state} +} + +// NewExportPartialSuccess creates a new empty ExportPartialSuccess. +// +// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, +// OR directly access the member if this is embedded in another struct. +func NewExportPartialSuccess() ExportPartialSuccess { + state := internal.StateMutable + return newExportPartialSuccess(&otlpcollectorentity.ExportEntitiesPartialSuccess{}, &state) +} + +// MoveTo moves all properties from the current struct overriding the destination and +// resetting the current instance to its zero value +func (ms ExportPartialSuccess) MoveTo(dest ExportPartialSuccess) { + ms.state.AssertMutable() + dest.state.AssertMutable() + *dest.orig = *ms.orig + *ms.orig = otlpcollectorentity.ExportEntitiesPartialSuccess{} +} + +// RejectedEntities returns the rejectedentities associated with this ExportPartialSuccess. +func (ms ExportPartialSuccess) RejectedEntities() int64 { + return ms.orig.RejectedEntities +} + +// SetRejectedEntities replaces the rejectedentities associated with this ExportPartialSuccess. +func (ms ExportPartialSuccess) SetRejectedEntities(v int64) { + ms.state.AssertMutable() + ms.orig.RejectedEntities = v +} + +// ErrorMessage returns the errormessage associated with this ExportPartialSuccess. +func (ms ExportPartialSuccess) ErrorMessage() string { + return ms.orig.ErrorMessage +} + +// SetErrorMessage replaces the errormessage associated with this ExportPartialSuccess. +func (ms ExportPartialSuccess) SetErrorMessage(v string) { + ms.state.AssertMutable() + ms.orig.ErrorMessage = v +} + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms ExportPartialSuccess) CopyTo(dest ExportPartialSuccess) { + dest.state.AssertMutable() + dest.SetRejectedEntities(ms.RejectedEntities()) + dest.SetErrorMessage(ms.ErrorMessage()) +} diff --git a/pdata/pentity/pentityotlp/generated_exportpartialsuccess_test.go b/pdata/pentity/pentityotlp/generated_exportpartialsuccess_test.go new file mode 100644 index 00000000000..cbd0d5df52b --- /dev/null +++ b/pdata/pentity/pentityotlp/generated_exportpartialsuccess_test.go @@ -0,0 +1,78 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by "pdata/internal/cmd/pdatagen/main.go". DO NOT EDIT. +// To regenerate this file run "make genpdata". + +package pentityotlp + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/pdata/internal" + otlpcollectorentity "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/entities/v1" +) + +func TestExportPartialSuccess_MoveTo(t *testing.T) { + ms := generateTestExportPartialSuccess() + dest := NewExportPartialSuccess() + ms.MoveTo(dest) + assert.Equal(t, NewExportPartialSuccess(), ms) + assert.Equal(t, generateTestExportPartialSuccess(), dest) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { + ms.MoveTo(newExportPartialSuccess(&otlpcollectorentity.ExportEntitiesPartialSuccess{}, &sharedState)) + }) + assert.Panics(t, func() { + newExportPartialSuccess(&otlpcollectorentity.ExportEntitiesPartialSuccess{}, &sharedState).MoveTo(dest) + }) +} + +func TestExportPartialSuccess_CopyTo(t *testing.T) { + ms := NewExportPartialSuccess() + orig := NewExportPartialSuccess() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + orig = generateTestExportPartialSuccess() + orig.CopyTo(ms) + assert.Equal(t, orig, ms) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { + ms.CopyTo(newExportPartialSuccess(&otlpcollectorentity.ExportEntitiesPartialSuccess{}, &sharedState)) + }) +} + +func TestExportPartialSuccess_RejectedEntities(t *testing.T) { + ms := NewExportPartialSuccess() + assert.Equal(t, int64(0), ms.RejectedEntities()) + ms.SetRejectedEntities(int64(13)) + assert.Equal(t, int64(13), ms.RejectedEntities()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { + newExportPartialSuccess(&otlpcollectorentity.ExportEntitiesPartialSuccess{}, &sharedState).SetRejectedEntities(int64(13)) + }) +} + +func TestExportPartialSuccess_ErrorMessage(t *testing.T) { + ms := NewExportPartialSuccess() + assert.Equal(t, "", ms.ErrorMessage()) + ms.SetErrorMessage("error message") + assert.Equal(t, "error message", ms.ErrorMessage()) + sharedState := internal.StateReadOnly + assert.Panics(t, func() { + newExportPartialSuccess(&otlpcollectorentity.ExportEntitiesPartialSuccess{}, &sharedState).SetErrorMessage("error message") + }) +} + +func generateTestExportPartialSuccess() ExportPartialSuccess { + tv := NewExportPartialSuccess() + fillTestExportPartialSuccess(tv) + return tv +} + +func fillTestExportPartialSuccess(tv ExportPartialSuccess) { + tv.orig.RejectedEntities = int64(13) + tv.orig.ErrorMessage = "error message" +} diff --git a/processor/internal/entities.go b/processor/internal/entities.go new file mode 100644 index 00000000000..8932a68fb8e --- /dev/null +++ b/processor/internal/entities.go @@ -0,0 +1,15 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package internal // import "go.opentelemetry.io/collector/processor/internal" + +import ( + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/consumer" +) + +// Entities is a processor that can consume profiles. +type Entities interface { + component.Component + consumer.Entities +} diff --git a/processor/processor.go b/processor/processor.go index 8ecd4d497c6..374467e9986 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -30,6 +30,12 @@ type Logs interface { consumer.Logs } +// Entities is a processor that can consume entities. +type Entities interface { + component.Component + consumer.Entities +} + // Settings is passed to Create* functions in Factory. type Settings struct { // ID returns the ID of the component that will be created. @@ -75,6 +81,15 @@ type Factory interface { // LogsStability gets the stability level of the Logs processor. LogsStability() component.StabilityLevel + // CreateEntities creates an Entities processor based on this config. + // If the processor type does not support entities, + // this function returns the error [pipeline.ErrSignalNotSupported]. + // Implementers can assume `next` is never nil. + CreateEntities(ctx context.Context, set Settings, cfg component.Config, next consumer.Entities) (Entities, error) + + // EntitiesStability gets the stability level of the Entities processor. + EntitiesStability() component.StabilityLevel + unexportedFactoryFunc() } @@ -102,6 +117,8 @@ type factory struct { metricsStabilityLevel component.StabilityLevel CreateLogsFunc logsStabilityLevel component.StabilityLevel + CreateEntitiesFunc + entitiesStabilityLevel component.StabilityLevel } func (f *factory) Type() component.Type { @@ -122,6 +139,10 @@ func (f *factory) LogsStability() component.StabilityLevel { return f.logsStabilityLevel } +func (f factory) EntitiesStability() component.StabilityLevel { + return f.entitiesStabilityLevel +} + // CreateTracesFunc is the equivalent of Factory.CreateTraces(). type CreateTracesFunc func(context.Context, Settings, component.Config, consumer.Traces) (Traces, error) @@ -155,6 +176,17 @@ func (f CreateLogsFunc) CreateLogs(ctx context.Context, set Settings, cfg compon return f(ctx, set, cfg, next) } +// CreateEntitiesFunc is the equivalent of Factory.CreateEntities(). +type CreateEntitiesFunc func(context.Context, Settings, component.Config, consumer.Entities) (Entities, error) + +// CreateEntities implements Factory.CreateEntities. +func (f CreateEntitiesFunc) CreateEntities(ctx context.Context, set Settings, cfg component.Config, next consumer.Entities) (Entities, error) { + if f == nil { + return nil, pipeline.ErrSignalNotSupported + } + return f(ctx, set, cfg, next) +} + // WithTraces overrides the default "error not supported" implementation for CreateTraces and the default "undefined" stability level. func WithTraces(createTraces CreateTracesFunc, sl component.StabilityLevel) FactoryOption { return factoryOptionFunc(func(o *factory) { @@ -179,6 +211,14 @@ func WithLogs(createLogs CreateLogsFunc, sl component.StabilityLevel) FactoryOpt }) } +// WithEntities overrides the default "error not supported" implementation for CreateEntities and the default "undefined" stability level. +func WithEntities(createEntities CreateEntitiesFunc, sl component.StabilityLevel) FactoryOption { + return factoryOptionFunc(func(o *factory) { + o.entitiesStabilityLevel = sl + o.CreateEntitiesFunc = createEntities + }) +} + // NewFactory returns a Factory. func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory { f := &factory{ diff --git a/processor/processor_test.go b/processor/processor_test.go index 79fd2cb6aa6..49ba7b472aa 100644 --- a/processor/processor_test.go +++ b/processor/processor_test.go @@ -28,6 +28,8 @@ func TestNewFactory(t *testing.T) { _, err = factory.CreateMetrics(context.Background(), Settings{}, &defaultCfg, consumertest.NewNop()) require.Error(t, err) _, err = factory.CreateLogs(context.Background(), Settings{}, &defaultCfg, consumertest.NewNop()) + require.Error(t, err) + _, err = factory.CreateEntities(context.Background(), Settings{}, &defaultCfg, consumertest.NewNop()) assert.Error(t, err) } diff --git a/receiver/receiver.go b/receiver/receiver.go index dd7242d5f77..0606e2767cd 100644 --- a/receiver/receiver.go +++ b/receiver/receiver.go @@ -39,7 +39,16 @@ type Logs interface { component.Component } -// Settings configures receiver creators. +// Entities receiver receives entities. +// Its purpose is to translate data from any format to the collector's internal entities data format. +// EntitiesReceiver feeds a consumer.Entities with data. +// +// For example, it could be a receiver that reads sysentities and convert them into plog.Entities. +type Entities interface { + component.Component +} + +// Settings configures Receiver creators. type Settings struct { // ID returns the ID of the component that will be created. ID component.ID @@ -84,6 +93,14 @@ type Factory interface { // LogsStability gets the stability level of the Logs receiver. LogsStability() component.StabilityLevel + // CreateEntitiesReceiver creates a EntitiesReceiver based on this config. + // If the receiver type does not support the data type or if the config is not valid + // an error will be returned instead. + CreateEntities(ctx context.Context, set Settings, cfg component.Config, nextConsumer consumer.Entities) (Entities, error) + + // EntitiesReceiverStability gets the stability level of the EntitiesReceiver. + EntitiesStability() component.StabilityLevel + unexportedFactoryFunc() } @@ -133,6 +150,22 @@ func (f CreateLogsFunc) CreateLogs(ctx context.Context, set Settings, cfg compon return f(ctx, set, cfg, next) } +// CreateEntitiesFunc is the equivalent of ReceiverFactory.CreateEntitiesReceiver(). +type CreateEntitiesFunc func(context.Context, Settings, component.Config, consumer.Entities) (Entities, error) + +// CreateEntities implements Factory.CreateEntitiesReceiver(). +func (f CreateEntitiesFunc) CreateEntities( + ctx context.Context, + set Settings, + cfg component.Config, + nextConsumer consumer.Entities, +) (Entities, error) { + if f == nil { + return nil, pipeline.ErrSignalNotSupported + } + return f(ctx, set, cfg, nextConsumer) +} + type factory struct { cfgType component.Type component.CreateDefaultConfigFunc @@ -142,6 +175,8 @@ type factory struct { metricsStabilityLevel component.StabilityLevel CreateLogsFunc logsStabilityLevel component.StabilityLevel + CreateEntitiesFunc + entitiesStabilityLevel component.StabilityLevel } func (f *factory) Type() component.Type { @@ -162,7 +197,11 @@ func (f *factory) LogsStability() component.StabilityLevel { return f.logsStabilityLevel } -// WithTraces overrides the default "error not supported" implementation for Factory.CreateTraces and the default "undefined" stability level. +func (f *factory) EntitiesStability() component.StabilityLevel { + return f.entitiesStabilityLevel +} + +// WithTraces overrides the default "error not supported" implementation for CreateTracesReceiver and the default "undefined" stability level. func WithTraces(createTraces CreateTracesFunc, sl component.StabilityLevel) FactoryOption { return factoryOptionFunc(func(o *factory) { o.tracesStabilityLevel = sl @@ -186,6 +225,14 @@ func WithLogs(createLogs CreateLogsFunc, sl component.StabilityLevel) FactoryOpt }) } +// WithEntities overrides the default "error not supported" implementation for CreateEntitiesReceiver and the default "undefined" stability level. +func WithEntities(createEntities CreateEntitiesFunc, sl component.StabilityLevel) FactoryOption { + return factoryOptionFunc(func(o *factory) { + o.entitiesStabilityLevel = sl + o.CreateEntitiesFunc = createEntities + }) +} + // NewFactory returns a Factory. func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory { f := &factory{