#### Description
This PR adds support for iterators to Slice and Map types and their
autogenerated counterparts. Iterators were stabilized in Go 1.23.
The All method is analogous to [maps.All](https://pkg.go.dev/maps#All)
and [slices.All ](https://pkg.go.dev/slices#All) and is a more idiomatic
alternative to the more verbose `for i := 0; i < es.Len(); i++ { z :=
es.At(i) }` way of looping.
Code that is written like this today:
```go
for i := 0; i < ld.ResourceLogs().Len(); i++ {
rl := ld.ResourceLogs().At(i)
for j := 0; j < rl.ScopeLogs().Len(); j++ {
sl := rl.ScopeLogs().At(j)
for k := 0; k < sl.LogRecords().Len(); k++ {
lr := sl.LogRecords().At(k)
// use lr
}
}
}
```
Can now be written like this:
```go
for _, rl := range ld.ResourceLogs().All() {
for _, sl := range rl.ScopeLogs().All() {
for _, lr := range sl.LogRecords().All() {
// use lr
}
}
}
```
#### Link to tracking issue
Fixes
https://github.com/open-telemetry/opentelemetry-collector/issues/11982
#### Description
[gofumpt](https://golangci-lint.run/usage/linters/#gofumpt) is a
stricter format than gofmt, while being backwards compatible.
---------
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
#### Description
As Testifylint is not applied on generated files, this update mdatagen
to comply with actually applied testifylint recommandations.
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Adds fuzz tests for various unmarshaling routines.
This can be tested with `go test -fuzz=`
This is ongoing work for
https://github.com/open-telemetry/sig-security/issues/55
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes #
<!--Describe what testing was performed and which tests were added.-->
#### Testing
<!--Describe the documentation added.-->
#### Documentation
<!--Please delete paragraphs that you did not use before submitting.-->
Signed-off-by: Adam Korczynski <adam@adalogics.com>
**Description:**
It was suggested that we add the [goleak
package](https://pkg.go.dev/go.uber.org/goleak) to every test in core.
This change adds `goleak` to every package that is succeeds with goleak.
There a number that are not successful, the full list of which I've
posted in the bug.
I generated these files using a shell script to copy a template
`main_test.go` file into each package, then modified the package name.
I'm sure there was a better way to automate this, but it worked well
enough at this point. Here's the script:
```
cp ./main_test.go $1
PACKAGE_NAME=$(basename $1)
sed -i '' -e "s|package component|package $PACKAGE_NAME|g"
$1/main_test.go
pushd . && cd $1 && go mod tidy
go test -v .
```
Usage example:
```
$ ./add_leak_test reciever/scrapererror
```
**Link to tracking Issue:**
#9165
**Testing:**
All added tests are passing, but there are a number failing. Note that there's no sign of `goleak` running until it fails.
Explicitly documents that the `JSONMarshaler` and `JSONUnmarshaler` as
conforming to the format in the OTLP/JSON specification.
The intent is to be explicit that we follow this spec and that
deviations (such as supporting snake case) are bugs that can be removed
in a minor version update.
**Link to tracking Issue:** Relates to #6287
**Description:**
Removes `TODO` from code in favor of having this on the issue tracker as
we do for most issues.
**Link to tracking Issue:** This is now tracked by issue #8976
**Description:** Add ZeroThreshold field to
exponentialHistogramDataPoint in pmetric package. It's needed to
understand which values fall in the ZeroBucket
Fixes#8802
This change enables the runtime assertions to catch unintentional pdata
mutations in components claiming as non-mutating pdata. Without these
assertions, runtime errors may still occur, but thrown by unrelated
components, making it very difficult to troubleshoot.
This required introducing extra API to get the pdata mutability state:
- p[metric|trace|log].[Metrics|Traces|Logs].IsReadOnly()
Resolves:
https://github.com/open-telemetry/opentelemetry-collector/issues/6794
This change introduces an option to enable runtime assertions to catch
unintentional pdata mutations in components that are claimed as
non-mutating pdata. Without these assertions, runtime errors may still
occur, but thrown by unrelated components, making it very difficult to
troubleshoot.
For now, this doesn't change the default behavior. It just introduces a
new method on `[Metrics/Traces|Logs].Shared()` that returns pdata marked
as shared. The method will be applied to fan-out consumers in the next
PR.
Later, if we want to remove the need of `MutatesData` capability, we can
introduce another method `[Metrics/Traces|Logs].Exclusive()` which
returns a copy of the pdata if it's shared.
This change unblocks the 1.0 release by implementing the original
solution proposed by @bogdandrutu in
https://github.com/open-telemetry/opentelemetry-collector/issues/6794.
Going forward, we may introduce a copy-on-write solution that doesn't
require the runtime assertions. That will likely be part of the 2.0
release.
* [chore] use license shortform
To remain consistent w/ contrib repo, see https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/22052
Signed-off-by: Alex Boten <aboten@lightstep.com>
* make goporto
Signed-off-by: Alex Boten <aboten@lightstep.com>
---------
Signed-off-by: Alex Boten <aboten@lightstep.com>
This change simplifies the generated pdata code to not wrap orig fields in the internal package for structs that are not being used by other packages.
The code generator is adjusted to generate wrapped or unwrapped code for only for structs that need it based on the package name. The only exception is `Slice` struct that was pulled from the generator because:
- We don't have and don't expect to have any new slices that are used by other packages.
- The `Slice` struct have two additional methods `AsRaw` and `FromRaw` that are not generated and defined in a separate file which is a bit confusing.
Returning the same object from Sort methods leads to subtle bug when non-mutating components rely use the returned object assuming it's a copy. Making the methods to not return anything makes it clear that they are mutating.
Rename `p[trace|metric|log]otlp.Export[Trace|Metrics|Logs]PartialSuccess` to `p[trace|metric|log]otlp.ExportPartialSuccess` for simplicity and consistency with Export[Request|Response]
This doesn't need a deprecation because `p[trace|metric|log]otlp.Export[Trace|Metrics|Logs]PartialSuccess` is not released yet
This allow to identify a new problem, NewClient -> NewGRPCClient
Signed-off-by: Bogdan <bogdandrutu@gmail.com>
Signed-off-by: Bogdan <bogdandrutu@gmail.com>