Commit Graph

20 Commits

Author SHA1 Message Date
Bogdan Drutu 5934839229
[chore] Call NewOrig* func instead of manually create new objects (#13646)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-15 21:45:34 +00:00
Bogdan Drutu b302feba10
[chore] Re-write the internal.State in pdata to support multiple properties. (#13633)
Part of
https://github.com/open-telemetry/opentelemetry-collector/issues/13631

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-15 16:38:54 +00:00
Bogdan Drutu eb9588bb3b
[chore] Fix custom marshaling code to preserve arrays order (#13641)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-14 18:03:50 +00:00
Bogdan Drutu 9b90d9f910
[chore] Generate custom proto unmarshal (#13626)
Benchmark results are in
https://github.com/open-telemetry/opentelemetry-collector/pull/13602

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-14 03:50:41 +00:00
Bogdan Drutu 787ae29ad2
[chore] pdatagen: Change JSON marshal to directly use the ProtoFields (#13616)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-11 20:40:52 +00:00
Bogdan Drutu c74560c80b
[chore] Generate proto marshal (#13596)
No changelog because this code is not yet publicly exposed in any way.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-10 07:17:43 +00:00
Bogdan Drutu 64e5220195
[chore] Add support to calculate proto size in pdata (#13592)
Add support to generate the proto Size by pdatagen. Not yet used, will
update after more tests are added.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-08 17:45:07 +00:00
Bogdan Drutu 56d8c8f8ff
[chore] Move marshal/unmarshal JSON to work with origin (#13581)
Remove the complication about internal/public for all funcs that only
need origin. Also improves significant testing.

This simplified a lot the fields (no more isCommon/isBaseCommon/etc.)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-06 23:24:03 +00:00
Bogdan Drutu cb546d8654
[chore] Move FillOrigTest to use orig and always in internal (#13578)
This PR allows to add tests for CopyOrig directly in the internal
package, also enables us to move more things to internal (including
tests) for Marshal/Unmarshal.

After this PR is merged we can generate the ProtoSize and other proto
helpers in internal.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-06 18:30:28 +00:00
Bogdan Drutu 53528d4bfc
[chore] Move CopyOrig funcs all to internal (#13570)
Main idea is to have all funcs that work on "origin" in internal, so
that we simplify access to them (see field access to this). Also will
remove duplicate generated code like copying the slice of KeyValue
(followup PR).

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-05 18:58:04 +00:00
Bogdan Drutu 85b47ce850
[chore] Refactor pdatagen to use the proto types for fields (#13545)
Part of the effort in
https://github.com/open-telemetry/opentelemetry-collector/pull/13531.

Would also help with:
1. Help with trying to remove the need of manually define these extra
structs and generate them from the protoc parsed code.
1. Simplifies what we need to manually generate, only the proto type is
enough.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-08-01 20:24:18 +00:00
Bogdan Drutu c1c9314c6d
[chore] Change to auto-generate UnmarshalJSON logic with pdatagen (#13508)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-07-29 15:46:25 +00:00
Bogdan Drutu 424a12102d
Generate marshal JSON without gogo proto jsonpb (#13450)
This PR is part of an effort to remove usage of gogo proto in pdata and
switch to a model where we enhance the pdatagen tool to generate compact
(reflection free to avoid DCE disabling) and faster code.

The list of the PRs will do:
1. Auto generate the JSON marshaling logic (this PR).
1. Auto generate the JSON unmarshaling logic and replace manually
written code.
1. Auto generate the proto marshaling logic.
1. Auto generate the proto unmarshaling logic.
1. Remove the usage of auto-generate gogo proto code completely and
generate field members in the pdata objects.
1. Add support for lazy unmarshaling. 

Performance improvements are more than 30x:

**Before:**
```
BenchmarkLogsMarshalJSON
BenchmarkLogsMarshalJSON-12    	      94	  12541041 ns/op	 8458944 B/op	  196458 allocs/op
BenchmarkMetricsMarshalJSON
BenchmarkMetricsMarshalJSON-12    	       3	 452309069 ns/op	350229024 B/op	 8131400 allocs/op
BenchmarkProfilesMarshalJSON
BenchmarkProfilesMarshalJSON-12    	      30	  36731071 ns/op	20317088 B/op	  531652 allocs/op
BenchmarkTracesMarshalJSON
BenchmarkTracesMarshalJSON-12    	       8	 132521260 ns/op	95920588 B/op	 2208765 allocs/op
```

**After:**
```
BenchmarkLogsMarshalJSON
BenchmarkLogsMarshalJSON-12    	    3000	    403587 ns/op	  282465 B/op	    1487 allocs/op
BenchmarkMetricsMarshalJSON
BenchmarkMetricsMarshalJSON-12    	      72	  16772373 ns/op	11856529 B/op	   72833 allocs/op
BenchmarkProfilesMarshalJSON
BenchmarkProfilesMarshalJSON-12    	    1460	    849419 ns/op	  674545 B/op	    1145 allocs/op
BenchmarkTracesMarshalJSON
BenchmarkTracesMarshalJSON-12    	     271	   4344647 ns/op	 3010259 B/op	   16237 allocs/op
```

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-07-25 19:29:53 +00:00
Bogdan Drutu 9b036ad72f
Extract pdatagen as standalone tool/package (#13398)
Updates
https://github.com/open-telemetry/opentelemetry-collector/issues/12747

Removes one source of DCE disable which is the usage of text/template.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2025-07-15 19:25:33 +00:00
Dmitry Anoshin 627e36fd42
[pdata] Add support for the new resource-entity references in xpdata (#13264)
Add support for the new resource-entity reference API added to the proto
as part of
https://github.com/open-telemetry/opentelemetry-proto/pull/635.

The API is separated into the experimental xpdata module since the new
entity related protobuf definitions are in development

This is the first step towards adopting Entities in Collector which was
drafted in
https://github.com/open-telemetry/opentelemetry-collector/pull/11958
2025-07-02 21:16:44 +00:00
Dmitry Anoshin 6aa2b812b7
[chore] [pdata] Change CopyTo to operate directly on proto (#13267)
Part of
https://github.com/open-telemetry/opentelemetry-collector/pull/13264 but
applied generically to all pdata types
2025-06-26 23:42:57 +00: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
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 fcd68becc8
[chore] [pdata] Split generated code into more files (#7084) 2023-01-31 08:19:12 -08:00
Bogdan Drutu 58fa059da5
Change pdata generated types to use type definition instead of aliases (#5936)
Change the way how objects are generated in `pdata`. Previously the pdata objects were generated in the `internal` package and aliases were created in the public packageas.

This PR changes this, by creating only "wrappers" object inside the internal package, and the public type is a type def of the internal type:

```golang
package internal

type LogRecord struct {
	orig *otlplogs.LogRecord
}

func GetOrigLogRecord(ms LogRecord) *otlplogs.LogRecord {
	return ms.orig
}

func NewLogRecord(orig *otlplogs.LogRecord) LogRecord {
	return LogRecord{orig: orig}
}
```

```golang
package plog

type LogRecord internal.LogRecord
```

With this approach, we still do not allow users access to the internal origin, which allows us flexibility to change to other representation (something like lazy proto, etc), but improves documentation of the pdata packages, see [current documentation](https://pkg.go.dev/go.opentelemetry.io/collector/pdata@v0.58.0/plog).

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

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-08-24 16:32:05 -07:00