Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start Entities Prototype #1

Closed
wants to merge 10 commits into from
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.2 // indirect
github.com/knadh/koanf/v2 v2.1.0 // indirect
github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
Expand Down Expand Up @@ -662,7 +662,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.1 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.2 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.45.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
Expand Down Expand Up @@ -1150,3 +1150,5 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/stor
replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/dbstorage => ../../extension/storage/dbstorage

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage => ../../extension/storage

replace go.opentelemetry.io/collector => /Users/tnajaryan/work/repos/opentelemetry-collector
10 changes: 4 additions & 6 deletions cmd/configschema/go.sum

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

2 changes: 2 additions & 0 deletions cmd/githubgen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
)

replace go.opentelemetry.io/collector => /Users/tnajaryan/work/repos/opentelemetry-collector
2 changes: 2 additions & 0 deletions cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ retract (
v0.76.1
v0.65.0
)

replace go.opentelemetry.io/collector => /Users/tnajaryan/work/repos/opentelemetry-collector
2 changes: 0 additions & 2 deletions cmd/mdatagen/go.sum

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

9 changes: 9 additions & 0 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ type attribute struct {
FullName attributeName `mapstructure:"-"`
// Warnings that will be shown to user under specified conditions.
Warnings warnings `mapstructure:"warnings"`
// EntityIdentifying is true if the attribute is identifying for the entity.
// See also entity struct.
EntityIdentifying bool `mapstructure:"entity_identifying"`
}

// Name returns actual name of the attribute that is set on the metric after applying NameOverride.
Expand Down Expand Up @@ -205,6 +208,10 @@ type tests struct {
ExpectConsumerError bool `mapstructure:"expect_consumer_error"`
}

type entity struct {
Type string `mapstructure:"type"`
}

type metadata struct {
// Type of the component.
Type string `mapstructure:"type"`
Expand All @@ -225,6 +232,8 @@ type metadata struct {
// ShortFolderName is the shortened folder name of the component, removing class if present
ShortFolderName string `mapstructure:"-"`

Entity entity `mapstructure:"entity"`

Tests *tests `mapstructure:"tests"`
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/mdatagen/metadata-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ resource_attributes:
# A warning that will be displayed if the resource_attribute is configured by user in any way.
# Should be used for deprecated optional resource_attributes that will be removed soon.
if_configured:
# Optional: true if the attribute is identifying for the entity. See "entity" section.
entity_identifying: bool

entity:
# Optional: the type of the entity to produce.
# If specified will produce an entity of this type. The Id of the entity will be
# composed of all resource attributes where "identifying=true" and all other resource
# attributes will be recorded as non-identifying attributes of the entity.
type: string

# Optional: map of attribute definitions with the key being the attribute name and value
# being described below.
Expand Down
50 changes: 50 additions & 0 deletions cmd/mdatagen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,43 @@ package {{ .Package }}

import (
"go.opentelemetry.io/collector/pdata/pcommon"
{{- if .Entity.Type }}
"go.opentelemetry.io/collector/pdata/pentity"
{{- end }}
)

// ResourceBuilder is a helper struct to build resources predefined in metadata.yaml.
// The ResourceBuilder is not thread-safe and must not to be used in multiple goroutines.
type ResourceBuilder struct {
config ResourceAttributesConfig
res pcommon.Resource
{{- if .Entity.Type }}
ent pentity.EntityEvent
{{- end }}
}

// NewResourceBuilder creates a new ResourceBuilder. This method should be called on the start of the application.
func NewResourceBuilder(rac ResourceAttributesConfig) *ResourceBuilder {
{{- if .Entity.Type }}
res := pcommon.NewResource()
ent := pentity.NewEntityEvent()

// Set the producing entity type in the Resource.
res.SetEntityType("{{ .Entity.Type }}")

// Prepare an EntityState event.
ent.SetEmptyEntityState()
ent.SetEntityType("{{ .Entity.Type }}")

{{- end }}
return &ResourceBuilder{
config: rac,
{{- if .Entity.Type }}
res: res,
ent: ent,
{{- else }}
res: pcommon.NewResource(),
{{- end }}
}
}

Expand All @@ -27,6 +50,14 @@ func NewResourceBuilder(rac ResourceAttributesConfig) *ResourceBuilder {
func (rb *ResourceBuilder) Set{{ $name.Render }}{{ . | publicVar }}() {
if rb.config.{{ $name.Render }}.Enabled {
rb.res.Attributes().PutStr("{{ $name }}", "{{ . }}")
{{- if $.Entity.Type }}
{{- if eq $attr.EntityIdentifying true }}
rb.res.EntityId().PutStr("{{ $name }}", "{{ . }}")
rb.ent.Id().PutStr("{{ $name }}", "{{ . }}")
{{- else }}
rb.ent.EntityState().Attributes().PutStr("{{ $name }}", "{{ . }}")
{{- end }}
{{- end }}
}
}
{{- else }}
Expand All @@ -38,6 +69,25 @@ func (rb *ResourceBuilder) Set{{ $name.Render }}(val {{ $attr.Type.Primitive }})
{{- else }}
rb.res.Attributes().Put{{ $attr.Type }}("{{ $name }}", val)
{{- end }}
{{- if $.Entity.Type }}
{{- if eq $attr.EntityIdentifying true }}
// This is an identifying attribute of the entity.
{{- if or (eq $attr.Type.String "Bytes") (eq $attr.Type.String "Slice") (eq $attr.Type.String "Map") }}
rb.res.EntityId().PutEmpty{{ $attr.Type }}("{{ $name }}").FromRaw(val)
rb.ent.Id().PutEmpty{{ $attr.Type }}("{{ $name }}").FromRaw(val)
{{- else }}
rb.res.EntityId().Put{{ $attr.Type }}("{{ $name }}", val)
rb.ent.Id().Put{{ $attr.Type }}("{{ $name }}", val)
{{- end }}
{{- else }}
// This is a non-identifying attribute of the entity.
{{- if or (eq $attr.Type.String "Bytes") (eq $attr.Type.String "Slice") (eq $attr.Type.String "Map") }}
rb.ent.EntityState().Attributes().PutEmpty{{ $attr.Type }}("{{ $name }}").FromRaw(val)
{{- else }}
rb.ent.EntityState().Attributes().Put{{ $attr.Type }}("{{ $name }}", val)
{{- end }}
{{- end }}
{{- end }}
}
}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions cmd/opampsupervisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ require (
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace go.opentelemetry.io/collector => /Users/tnajaryan/work/repos/opentelemetry-collector
20 changes: 18 additions & 2 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.2 // indirect
github.com/knadh/koanf/v2 v2.1.0 // indirect
github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
Expand Down Expand Up @@ -677,7 +677,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.1 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.2 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.45.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
Expand Down Expand Up @@ -1190,3 +1190,19 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/sola
replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/namedpipereceiver => ../../receiver/namedpipereceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/sqlquery => ../../internal/sqlquery

replace go.opentelemetry.io/collector => /Users/tnajaryan/work/repos/opentelemetry-collector

replace go.opentelemetry.io/collector/pdata => /Users/tnajaryan/work/repos/opentelemetry-collector/pdata

replace go.opentelemetry.io/collector/pdata/pentity => /Users/tnajaryan/work/repos/opentelemetry-collector/pdata/pentity

replace go.opentelemetry.io/collector/exporter/debugexporter => /Users/tnajaryan/work/repos/opentelemetry-collector/exporter/debugexporter

replace go.opentelemetry.io/collector/exporter => /Users/tnajaryan/work/repos/opentelemetry-collector/exporter

replace go.opentelemetry.io/collector/processor => /Users/tnajaryan/work/repos/opentelemetry-collector/processor

replace go.opentelemetry.io/collector/receiver => /Users/tnajaryan/work/repos/opentelemetry-collector/receiver

replace go.opentelemetry.io/collector/consumer => /Users/tnajaryan/work/repos/opentelemetry-collector/consumer
10 changes: 4 additions & 6 deletions cmd/otelcontribcol/go.sum

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

8 changes: 5 additions & 3 deletions cmd/oteltestbedcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ require (
github.com/klauspost/compress v1.17.6 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.2 // indirect
github.com/knadh/koanf/v2 v2.1.0 // indirect
github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leodido/ragel-machinery v0.0.0-20181214104525-299bdde78165 // indirect
Expand Down Expand Up @@ -246,12 +246,12 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.1 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.2 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.45.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/sdk v1.23.1 // indirect
go.opentelemetry.io/otel/sdk/metric v1.23.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
Expand Down Expand Up @@ -388,3 +388,5 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil
replace github.com/openshift/api v3.9.0+incompatible => github.com/openshift/api v0.0.0-20180801171038-322a19404e37

replace github.com/outcaste-io/ristretto v0.2.0 => github.com/outcaste-io/ristretto v0.2.1

replace go.opentelemetry.io/collector => /Users/tnajaryan/work/repos/opentelemetry-collector
Loading
Loading