Commit Graph

116 Commits

Author SHA1 Message Date
Matthieu MOREL 564818fd7f
[chore]: fix testifylint rules (#12791)
#### Description

Fixes testifylint rules which where disabled with golangci-lint v2
upgrade

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-02 23:10:07 +00:00
Alex Boten bf9fa311fa
[chore] update tests to use Empty (#12750)
This change was caught by the linter in the update of golangci-lint to
v2 (see
https://github.com/open-telemetry/opentelemetry-collector/pull/12731)

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
2025-03-27 20:52:18 +00:00
Mauri de Souza Meneguzzo e4c4d2fb46
pdata: add iterator All method to slice and map types (#12380)
#### 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
2025-03-14 08:55:02 +00:00
Israel Blancas 6ae1c98f63
Bytes based batching for metrics (#12550)
#### Description

This PR implements serialized bytes based batching for metrics.

#### Link to tracking issue

https://github.com/open-telemetry/opentelemetry-collector/issues/3262

Continuation of #12299 made by @sfc-gh-sili.

Signed-off-by: Israel Blancas <iblancasa@gmail.com>
2025-03-10 20:39:26 +00:00
Bogdan Drutu 4cf491babd
[chore] Fix some nolint in tests or non critical code (#11943)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2024-12-17 21:59:18 +00:00
Matthieu MOREL 824c9f7a43
[chore]: enable gofumpt linter in internal, otelcol, pdata, pipeline and processor (#11855)
#### 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>
2024-12-12 19:21:54 +00:00
Matthieu MOREL 51d57f0c62
[chore]: use ErrorContains with testify (#11680)
#### Description

use ErrorContains with testify when possible

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-11-14 12:25:06 -08:00
renovate[bot] 168a881b3c
fix(deps): update module github.com/golangci/golangci-lint to v1.62.0 (#11644)
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[github.com/golangci/golangci-lint](https://redirect.github.com/golangci/golangci-lint)
| `v1.61.0` -> `v1.62.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fgolangci%2fgolangci-lint/v1.62.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fgolangci%2fgolangci-lint/v1.62.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fgolangci%2fgolangci-lint/v1.61.0/v1.62.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fgolangci%2fgolangci-lint/v1.61.0/v1.62.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>golangci/golangci-lint
(github.com/golangci/golangci-lint)</summary>

###
[`v1.62.0`](https://redirect.github.com/golangci/golangci-lint/compare/v1.61.0...v1.62.0)

[Compare
Source](https://redirect.github.com/golangci/golangci-lint/compare/v1.61.0...v1.62.0)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/open-telemetry/opentelemetry-collector).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS45LjUiLCJ1cGRhdGVkSW5WZXIiOiIzOS45LjUiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImRlcGVuZGVuY2llcyIsInJlbm92YXRlYm90Il19-->

---------

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
Co-authored-by: Yang Song <songy23@users.noreply.github.com>
Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Yang Song <yang.song@datadoghq.com>
2024-11-13 12:15:45 -08:00
Matthieu MOREL 37f783308e
[chore]: enable require-error rule from testifylint (#11199)
#### Description

Testifylint is a linter that provides best practices with the use of
testify.

This PR enables
[require-error](https://github.com/Antonboom/testifylint?tab=readme-ov-file#require-error)
rule from [testifylint](https://github.com/Antonboom/testifylint)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-09-18 15:02:22 -07:00
Matthieu MOREL 012cf86228
[chore]: enable float-compare rule from testifylint (#11149)
#### Description

Testifylint is a linter that provides best practices with the use of
testify.

This PR enables
[float-compare](https://github.com/Antonboom/testifylint?tab=readme-ov-file#float-compare)
rule from [testifylint](https://github.com/Antonboom/testifylint)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-09-18 11:34:34 +02:00
Matthieu MOREL eb0a4b6388
[chore]: enable expected-actual rule from testifylint (#11135)
#### Description

Testifylint is a linter that provides best practices with the use of
testify.

This PR enables
[expected-actual](https://github.com/Antonboom/testifylint?tab=readme-ov-file#expected-actual)
rule from [testifylint](https://github.com/Antonboom/testifylint)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-09-11 11:28:31 -07:00
Matthieu MOREL 8f3ca8aaf5
[chore] mdatagen comply with testifylint (#11136)
#### 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>
2024-09-11 09:07:52 -07:00
Matthieu MOREL 6925a306fa
[chore]: enable len and empty rules from testifylint (#11021)
#### Description

Testifylint is a linter that provides best practices with the use of
testify.

This PR enables
[len](https://github.com/Antonboom/testifylint?tab=readme-ov-file#len)
and
[empty](https://github.com/Antonboom/testifylint?tab=readme-ov-file#empty)
rules from [testifylint](https://github.com/Antonboom/testifylint)

It also adds testifylint as tool to use with a make command

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-09-09 09:57:58 -07:00
AdamKorcz 852a696f40
Add fuzz tests for unmarshaling routines (#10697)
<!--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>
2024-07-26 10:31:09 +02:00
Alex Boten 8a2a1a58d1
[chore] replace deprecated calls (#10211)
Updating grpc.Dial -> grpc.NewClient, removing grpc.WithBlock as it's
not recommended
https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#the-wrong-way-grpcdial.
We may need to add code in the future to wait for state to be connected,
but in my local tests, there was no flakiness introduced with this
change.

Fixes
https://github.com/open-telemetry/opentelemetry-collector/issues/10194

---------

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
2024-05-23 01:53:34 -07:00
David Ashpole 31528ce81d
Support parsing metric.metadata from OTLP JSON (#10026)
Follow-up to
https://github.com/open-telemetry/opentelemetry-collector/pull/10006,
which added metric.metadata to pmetric.

I forgot to add support for parsing the field from JSON in that PR. This
PR adds the missing support.

#### Testing

Unit tests
2024-04-26 06:45:29 -07:00
David Ashpole cb0637f6c4
Support metric.metadata in pdata/pmetric (#10006)
#### Description

After
https://github.com/open-telemetry/opentelemetry-collector/pull/9985, add
support for the new metric.metadata field in the pmetric package.

I plan to use the metric.metadata field to support additional prometheus
types per
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md#metric-metadata
2024-04-19 12:52:25 -07:00
Alex Boten 062d0a7ffc
[chore] remove unnecessary underscores (#9580)
As per feedback from my previous PR

Signed-off-by: Alex Boten <aboten@lightstep.com>
2024-02-13 13:34:53 -08:00
Alex Boten 4688461318
[chore] fix unused params (#9578)
Related to #9577

Signed-off-by: Alex Boten <aboten@lightstep.com>
2024-02-13 11:04:48 -08:00
Curtis Robert 8ee1f13743
[chore] Enable goleak for all (passing) tests (#9173)
**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.
2024-01-03 08:35:58 -08:00
Pablo Baeyens 704a16c2cd
[pdata] Document that Marshalers/Unmarshalers use OTLP/JSON format explicitly (#8974)
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
2023-11-21 08:46:32 -08:00
Pablo Baeyens 10b7cdcff7
[pdata] Remove TODO, move to issue (#8977)
**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
2023-11-21 17:39:35 +01:00
William Dumont e13dd5b1af
Add ZeroThreshold field to exponentialHistogramDataPoint in pmetric package (#8769)
**Description:** Add ZeroThreshold field to
exponentialHistogramDataPoint in pmetric package. It's needed to
understand which values fall in the ZeroBucket


Fixes #8802
2023-11-16 09:00:48 -08:00
Dmitrii Anoshin 8a385c22e5
[pdata] Enable the pdata mutation safeguards in the fanout consumers (#8634)
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
2023-10-16 11:12:50 -07:00
Dmitrii Anoshin 7ee0b28302
[pdata] Introduce runtime safeguards to catch incorrect pdata mutations (#8494)
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.
2023-10-06 08:56:20 -07:00
Dmitrii Anoshin 271debcea7
[chore] [pdata] Simplify internal pdatagen structs and interfaces (#8537)
Simplify internal pdatagen structures by removing redundant interface
usages and struct fields.

No functional changes.
2023-09-27 08:57:37 -07:00
Bogdan Drutu 18a11ec09b
Change JSON unmarshalling to be a func on pdata types (#7701)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-05-22 06:19:52 -07:00
Alex Boten 80d704deb4
[chore] use license shortform (#7694)
* [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>
2023-05-18 13:11:17 -07:00
Dmitrii Anoshin 1f5865df1c
[chore] [pdata] Migrate the generator to go templates (#7241) 2023-02-27 09:05:50 -08:00
Dmitrii Anoshin 08985c48bb
[pdata] Remove deprecated `[Metrics|Traces|Logs]MoveTo` methods (#7165) 2023-02-09 11:23:59 -08:00
Dmitrii Anoshin 0f6a174fd4
[chore] [pdata] Add test coverage for slices Sort method (#7115) 2023-02-03 18:50:33 -08:00
Dmitrii Anoshin 56fc8f2e31
[chore] [pdata] Combine slice templates in the generator (#7103) 2023-02-03 16:14:02 -08:00
Dmitrii Anoshin a8cfb51cec
[chore] [pdata] Fix the generated tests for slices (#7112)
The loop was never executed before
2023-02-03 11:02:13 -08:00
Dmitrii Anoshin 33e5265e3c
[chore] [pdata] Simplify EnsureCapacity tests (#7099)
This brings slicePtr and sliceValue tests the the same view which helps to consolidate them
2023-02-02 15:58:54 -08:00
Dmitrii Anoshin c641c0502e
[pdata] Deprecate [Metrics|Logs|Traces].MoveTo methods (#7091) 2023-02-02 08:35:56 -08:00
Dmitrii Anoshin 3f73651d61
[chore] [pdata] Move constants to separate files (#7092) 2023-02-02 04:01:18 -08:00
Dmitrii Anoshin fcd68becc8
[chore] [pdata] Split generated code into more files (#7084) 2023-01-31 08:19:12 -08:00
Bogdan Drutu a2f0153679
[chore] replace the usage of interface{} with any (#7053)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-01-30 15:01:25 -08:00
Dmitrii Anoshin de4867fc8a
[pdata] Do not wrap orig fields when it's not required (#7081)
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.
2023-01-30 11:48:02 -08:00
Bogdan Drutu e5208293ec
Add private method to GrpcServer interface, disallow direct implementation (#7029)
Fixes https://github.com/open-telemetry/opentelemetry-collector/issues/6966

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-01-27 09:50:47 -08:00
Bogdan Drutu 5358eb9826
Start enforcing grpc server implementation to embed UnimplementedGRPCServer, dissallow client implementation (#6967)
* Enforce grpc server implementation to embed UnimplementedGRPCServer, dissallow client implementation

Fixes https://github.com/open-telemetry/opentelemetry-collector/issues/6966

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>

* Update disallowimpl.yaml

* Update grpc.go

* Update grpc.go

* Update grpc.go

* Update grpc.go

* Update grpc.go

* Update grpc.go

* Update grpc.go

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-01-19 10:05:55 -08:00
Dmitrii Anoshin bf2e0a8cd1
[pdata] Change [...Slice|Map].Sort methods to not return any value (#6667)
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.
2022-12-05 15:16:01 -08:00
Dmitrii Anoshin 8f061641b9
[pdata] Add ability to remove optional fields (#6475)
This change adds an ability to remove optional fields like pmetric.HistogramDataPoint.Min/Max/Sum.
2022-11-21 13:27:28 -08:00
Bogdan 087c047483
Remove deprecated code from pdata
Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-26 14:21:47 -07:00
Dmitrii Anoshin 4fbedf759c
[pdata] Rename p[trace|metric|log]otlp.ExportPartialSuccess (#6370)
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
2022-10-24 10:16:28 -07:00
Bogdan Drutu 38fcd5dc7d
Rename Request|Response to Export[Request|Response] (#6367)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-21 12:28:41 -07:00
Bogdan Drutu 2758d1a7a2
Generate Export[Logs|Metrics|Traces]PartialSuccess, plugin into the Response (#6361)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-20 10:27:43 -07:00
Bogdan Drutu 73ee7ead1a
Change to non-nullable PartialSuccess (#6364)
To avoid the need of checking if the message is present, see https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/collector/trace/v1/trace_service.proto#L58

Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-20 10:09:34 -07:00
Bogdan Drutu d957e982d3
Deprecate p[trace|metric|log]otlp.NewClient in favor of p[trace|metric|log]otlp.NewGRPCClient (#6355)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-19 11:50:22 -07:00
Bogdan Drutu 3a5e134722
[chore] Split the single file in p[trace|metric|log]otlp package into one per struct (#6349)
This allow to identify a new problem, NewClient -> NewGRPCClient

Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-19 09:05:11 -07:00