Skip to content

Commit

Permalink
Merge branch 'main' into debug-exporter-disable-sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzej-stencel authored May 31, 2024
2 parents 8ba5b52 + 4bbb604 commit ca72298
Show file tree
Hide file tree
Showing 22 changed files with 737 additions and 329 deletions.
25 changes: 25 additions & 0 deletions .chloggen/codeboten_fix-9674-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: support setting an AttributeSet for async instruments

# One or more tracking issues or pull requests related to the change
issues: [9674]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
25 changes: 25 additions & 0 deletions .chloggen/codeboten_fix-9674.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: batchprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: ensure attributes are set on cardinality metadata metric

# One or more tracking issues or pull requests related to the change
issues: [9674]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
25 changes: 25 additions & 0 deletions .chloggen/confmap-default-provider.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: confmap

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow setting a default Provider on a Resolver to use when `${}` syntax is used without a scheme

# One or more tracking issues or pull requests related to the change
issues: [10182]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
20 changes: 20 additions & 0 deletions .chloggen/fix-batcher-sender-shutdown-deadlock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: exporterhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix potential deadlocks in BatcherSender shutdown

# One or more tracking issues or pull requests related to the change
issues: [10255]

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
2 changes: 1 addition & 1 deletion cmd/mdatagen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ When making updates to the metadata generator or introducing support for new fun

1. Ensure the [metadata-schema.yaml](./metadata-schema.yaml) and [./metadata.yaml](metadata.yaml) files reflect the changes.
2. Run `make mdatagen-test`.
3. Make sure all tests are passing including [generated tests](./internal/metadata/generated_metrics_test.go).
3. Make sure all tests are passing including [generated tests](./internal/samplereceiver/internal/metadata/generated_metrics_test.go).
4. Run `make generate`.
2 changes: 1 addition & 1 deletion cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
go.opentelemetry.io/collector/pdata v1.8.0
go.opentelemetry.io/collector/receiver v0.101.0
go.opentelemetry.io/collector/semconv v0.101.0
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
Expand Down Expand Up @@ -44,7 +45,6 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand Down

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

8 changes: 8 additions & 0 deletions cmd/mdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ func templatize(tmplFile string, md metadata) *template.Template {
}
return result
},
"hasAsync": func(t telemetry) bool {
for _, m := range t.Metrics {
if m.Data().IsAsync() {
return true
}
}
return false
},
"inc": func(i int) int { return i + 1 },
"distroURL": func(name string) string {
return distros[name]
Expand Down
14 changes: 13 additions & 1 deletion cmd/mdatagen/templates/telemetry.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
{{- end }}

{{ if hasAsync .Telemetry }}"go.opentelemetry.io/otel/attribute"{{- end }}
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -35,6 +36,7 @@ type TelemetryBuilder struct {
{{- end }}
{{- end }}
level configtelemetry.Level
{{ if hasAsync .Telemetry }}attributeSet attribute.Set{{- end }}
}

// telemetryBuilderOption applies changes to default builder.
Expand All @@ -47,6 +49,15 @@ func WithLevel(lvl configtelemetry.Level) telemetryBuilderOption {
}
}

{{- if hasAsync .Telemetry }}
// WithAttributeSet applies a set of attributes for asynchronous instruments.
func WithAttributeSet(set attribute.Set) telemetryBuilderOption {
return func(builder *TelemetryBuilder) {
builder.attributeSet = set
}
}
{{- end }}

{{- range $name, $metric := .Telemetry.Metrics }}
{{ if $metric.Data.Async -}}
// With{{ $name.Render }}Callback sets callback for observable {{ $name.Render }} metric.
Expand All @@ -58,6 +69,7 @@ func With{{ $name.Render }}Callback(cb func() {{ $metric.Data.BasicType }}) tele
{{- end }}
{{- end }}


// NewTelemetryBuilder provides a struct with methods to update all internal telemetry
// for a component
func NewTelemetryBuilder(settings component.TelemetrySettings, options ...telemetryBuilderOption) (*TelemetryBuilder, error) {
Expand Down Expand Up @@ -85,7 +97,7 @@ func NewTelemetryBuilder(settings component.TelemetrySettings, options ...teleme
{{- end }}
{{ if $metric.Data.Async -}}
metric.With{{ casesTitle $metric.Data.BasicType }}Callback(func(_ context.Context, o metric.{{ casesTitle $metric.Data.BasicType }}Observer) error {
o.Observe(builder.observe{{ $name.Render }}())
o.Observe(builder.observe{{ $name.Render }}(), metric.WithAttributeSet(builder.attributeSet))
return nil
}),
{{- end }}
Expand Down
28 changes: 20 additions & 8 deletions confmap/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,34 @@ func (mr *Resolver) expandValue(ctx context.Context, value any) (any, bool, erro
return value, false, nil
}

// findURI attempts to find the first expandable URI in input. It returns an expandable
// findURI attempts to find the first potentially expandable URI in input. It returns a potentially expandable
// URI, or an empty string if none are found.
// Note: findURI is only called when input contains a closing bracket.
func findURI(input string) string {
func (mr *Resolver) findURI(input string) string {
closeIndex := strings.Index(input, "}")
remaining := input[closeIndex+1:]
openIndex := strings.LastIndex(input[:closeIndex+1], "${")

// if there is a missing "${" or the uri does not contain ":", check the next URI.
if openIndex < 0 || !strings.Contains(input[openIndex:closeIndex+1], ":") {
// if there is any of:
// - a missing "${"
// - there is no default scheme AND no scheme is detected because no `:` is found.
// then check the next URI.
if openIndex < 0 || (mr.defaultScheme == "" && !strings.Contains(input[openIndex:closeIndex+1], ":")) {
// if remaining does not contain "}", there are no URIs left: stop recursion.
if !strings.Contains(remaining, "}") {
return ""
}
return findURI(remaining)
return mr.findURI(remaining)
}

return input[openIndex : closeIndex+1]
}

// findAndExpandURI attempts to find and expand the first occurrence of an expandable URI in input. If an expandable URI is found it
// returns the input with the URI expanded, true and nil. Otherwise, it returns the unchanged input, false and the expanding error.
// This method expects input to start with ${ and end with }
func (mr *Resolver) findAndExpandURI(ctx context.Context, input string) (any, bool, error) {
uri := findURI(input)
uri := mr.findURI(input)
if uri == "" {
// No URI found, return.
return input, false, nil
Expand Down Expand Up @@ -138,11 +142,19 @@ func toString(input any) (string, error) {
}
}

func (mr *Resolver) expandURI(ctx context.Context, uri string) (any, bool, error) {
lURI, err := newLocation(uri[2 : len(uri)-1])
func (mr *Resolver) expandURI(ctx context.Context, input string) (any, bool, error) {
// strip ${ and }
uri := input[2 : len(input)-1]

if !strings.Contains(uri, ":") {
uri = fmt.Sprintf("%s:%s", mr.defaultScheme, uri)
}

lURI, err := newLocation(uri)
if err != nil {
return nil, false, err
}

if strings.Contains(lURI.opaqueValue, "$") {
return nil, false, fmt.Errorf("the uri %q contains unsupported characters ('$')", lURI.asString())
}
Expand Down
Loading

0 comments on commit ca72298

Please sign in to comment.