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

[DRAFT] [DO NOT MERGE] Entities support prototype #11958

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ ocb:
# Definitions for ProtoBuf generation.

# The source directory for OTLP ProtoBufs.
OPENTELEMETRY_PROTO_SRC_DIR=pdata/internal/opentelemetry-proto
OPENTELEMETRY_PROTO_SRC_DIR?=pdata/internal/opentelemetry-proto

# The branch matching the current version of the proto to use
OPENTELEMETRY_PROTO_VERSION=v1.4.0
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var replaceModules = []string{
"/processor/processortest",
"/processor/batchprocessor",
"/processor/memorylimiterprocessor",
"/processor/processorhelper/xprocessorhelper",
"/processor/xprocessor",
"/receiver",
"/receiver/nopreceiver",
Expand Down
1 change: 1 addition & 0 deletions cmd/builder/test/core.builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ replaces:
- go.opentelemetry.io/collector/processor => ${WORKSPACE_DIR}/processor
- go.opentelemetry.io/collector/processor/processortest => ${WORKSPACE_DIR}/processor/processortest
- go.opentelemetry.io/collector/processor/xprocessor => ${WORKSPACE_DIR}/processor/xprocessor
- go.opentelemetry.io/collector/processor/processorhelper/xprocessorhelper => ${WORKSPACE_DIR}/processor/processorhelper/xprocessorhelper
- go.opentelemetry.io/collector/receiver => ${WORKSPACE_DIR}/receiver
- go.opentelemetry.io/collector/receiver/otlpreceiver => ${WORKSPACE_DIR}/receiver/otlpreceiver
- go.opentelemetry.io/collector/receiver/xreceiver => ${WORKSPACE_DIR}/receiver/xreceiver
Expand Down
2 changes: 2 additions & 0 deletions cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ replace go.opentelemetry.io/collector/processor => ../../processor
replace go.opentelemetry.io/collector/consumer/consumererror => ../../consumer/consumererror

replace go.opentelemetry.io/collector/scraper => ../../scraper

replace go.opentelemetry.io/collector/pipeline/xpipeline => ../../pipeline/xpipeline
26 changes: 26 additions & 0 deletions cmd/mdatagen/internal/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
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.
Expand Down Expand Up @@ -65,6 +67,9 @@
if err := md.validateMetrics(); err != nil {
errs = errors.Join(errs, err)
}
if err := md.validateEntities(); err != nil {
errs = errors.Join(errs, err)
}

Check warning on line 72 in cmd/mdatagen/internal/metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/mdatagen/internal/metadata.go#L71-L72

Added lines #L71 - L72 were not covered by tests
return errs
}

Expand Down Expand Up @@ -114,6 +119,18 @@
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))
}

Check warning on line 128 in cmd/mdatagen/internal/metadata.go

View check run for this annotation

Codecov / codecov/patch

cmd/mdatagen/internal/metadata.go#L125-L128

Added lines #L125 - L128 were not covered by tests
}
}
return errs
}

func (md *Metadata) validateAttributes(usedAttrs map[AttributeName]bool) error {
var errs error
unusedAttrs := make([]AttributeName, 0, len(md.Attributes))
Expand Down Expand Up @@ -157,6 +174,15 @@
return errs
}

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 AttributeName string

func (mn AttributeName) Render() (string, error) {
Expand Down
1 change: 1 addition & 0 deletions cmd/mdatagen/internal/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (ms StabilityMap) Validate() error {
c != "traces" &&
c != "logs" &&
c != "profiles" &&
c != "entities" &&
c != "traces_to_traces" &&
c != "traces_to_metrics" &&
c != "traces_to_logs" &&
Expand Down
16 changes: 16 additions & 0 deletions cmd/mdatagen/internal/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }} {{ else }}true {{ 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
}
7 changes: 7 additions & 0 deletions cmd/mdatagen/metadata-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cmd/otelcorecol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ replaces:
- go.opentelemetry.io/collector/processor/batchprocessor => ../../processor/batchprocessor
- go.opentelemetry.io/collector/processor/memorylimiterprocessor => ../../processor/memorylimiterprocessor
- go.opentelemetry.io/collector/processor/xprocessor => ../../processor/xprocessor
- go.opentelemetry.io/collector/processor/processorhelper/xprocessorhelper => ../../processor/processorhelper/xprocessorhelper
- go.opentelemetry.io/collector/receiver => ../../receiver
- go.opentelemetry.io/collector/receiver/nopreceiver => ../../receiver/nopreceiver
- go.opentelemetry.io/collector/receiver/otlpreceiver => ../../receiver/otlpreceiver
Expand Down
3 changes: 3 additions & 0 deletions cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ require (
go.opentelemetry.io/collector/pdata/testdata v0.116.0 // indirect
go.opentelemetry.io/collector/pipeline v0.116.0 // indirect
go.opentelemetry.io/collector/pipeline/xpipeline v0.116.0 // indirect
go.opentelemetry.io/collector/processor/processorhelper/xprocessorhelper v0.116.0 // indirect
go.opentelemetry.io/collector/processor/processortest v0.116.0 // indirect
go.opentelemetry.io/collector/processor/xprocessor v0.116.0 // indirect
go.opentelemetry.io/collector/receiver/receivertest v0.116.0 // indirect
Expand Down Expand Up @@ -278,6 +279,8 @@ replace go.opentelemetry.io/collector/processor/memorylimiterprocessor => ../../

replace go.opentelemetry.io/collector/processor/xprocessor => ../../processor/xprocessor

replace go.opentelemetry.io/collector/processor/processorhelper/xprocessorhelper => ../../processor/processorhelper/xprocessorhelper

replace go.opentelemetry.io/collector/receiver => ../../receiver

replace go.opentelemetry.io/collector/receiver/nopreceiver => ../../receiver/nopreceiver
Expand Down
Loading
Loading