Skip to content

[OpAMP] Enhance EffectiveConfigFile: stream APIs, size limits, tests#4285

Merged
martincostello merged 7 commits intoopen-telemetry:mainfrom
stevejgordon:effective-config-stream
Apr 27, 2026
Merged

[OpAMP] Enhance EffectiveConfigFile: stream APIs, size limits, tests#4285
martincostello merged 7 commits intoopen-telemetry:mainfrom
stevejgordon:effective-config-stream

Conversation

@stevejgordon
Copy link
Copy Markdown
Contributor

@stevejgordon stevejgordon commented Apr 22, 2026

Fixes #4151

Changes

  • Add CreateFromStream and CreateFromStreamAsync to EffectiveConfigFile for safe, size-limited config loading from streams (sync/async) with enforced max byte length.
  • Remove CreateFromFilePath.
  • Content is now ReadOnlyMemory.
  • Enforce non-null contentType and fileName (default to empty string).
  • Improve OpAmpClient API docs with thrown exception details.
  • Add comprehensive EffectiveConfigFile tests (validation, limits, event logging).
  • Update FrameBuilderTests and OpAmpClientTests for new APIs.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

- Add CreateFromStream and CreateFromStreamAsync to EffectiveConfigFile for safe, size-limited config loading from streams (sync/async) with enforced max byte length.
- Remove CreateFromFilePath.
- Content is now ReadOnlyMemory<byte>.
- Enforce non-null contentType and fileName (default to empty string).
- Improve OpAmpClient API docs with thrown exception details.
- Add comprehensive EffectiveConfigFile tests (validation, limits, event logging).
- Update FrameBuilderTests and OpAmpClientTests for new APIs.
@stevejgordon stevejgordon requested a review from a team as a code owner April 22, 2026 13:19
@stevejgordon stevejgordon changed the title Enhance EffectiveConfigFile: stream APIs, size limits, tests [OpAMP] Enhance EffectiveConfigFile: stream APIs, size limits, tests Apr 22, 2026
@github-actions github-actions Bot requested a review from RassK April 22, 2026 13:19
@github-actions github-actions Bot added the comp:opamp.client Things related to OpenTelemetry.OpAmp.Client label Apr 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.80%. Comparing base (a545405) to head (4a816eb).
⚠️ Report is 43 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4285      +/-   ##
==========================================
- Coverage   73.85%   73.80%   -0.06%     
==========================================
  Files         459      467       +8     
  Lines       18327    18501     +174     
==========================================
+ Hits        13535    13654     +119     
- Misses       4792     4847      +55     
Flag Coverage Δ
unittests-Contrib.Shared.Tests 89.38% <ø> (ø)
unittests-Exporter.Geneva 54.70% <ø> (-0.14%) ⬇️
unittests-Exporter.InfluxDB 95.81% <ø> (ø)
unittests-Exporter.Instana 74.86% <ø> (ø)
unittests-Exporter.OneCollector 94.61% <ø> (ø)
unittests-Extensions 90.78% <ø> (ø)
unittests-Extensions.Enrichment 100.00% <ø> (ø)
unittests-Extensions.Enrichment.AspNetCore 86.27% <ø> (ø)
unittests-Extensions.Enrichment.Http 94.33% <ø> (ø)
unittests-Instrumentation.AWS 83.54% <ø> (ø)
unittests-Instrumentation.AspNet 76.61% <ø> (ø)
unittests-Instrumentation.AspNetCore 70.44% <ø> (ø)
unittests-Instrumentation.Cassandra 23.52% <ø> (?)
unittests-Instrumentation.ConfluentKafka 47.37% <ø> (ø)
unittests-Instrumentation.ElasticsearchClient 80.60% <ø> (ø)
unittests-Instrumentation.EntityFrameworkCore 81.39% <ø> (ø)
unittests-Instrumentation.EventCounters 77.27% <ø> (ø)
unittests-Instrumentation.GrpcCore 91.27% <ø> (ø)
unittests-Instrumentation.GrpcNetClient 73.78% <ø> (ø)
unittests-Instrumentation.Hangfire 86.05% <ø> (ø)
unittests-Instrumentation.Http 74.62% <ø> (ø)
unittests-Instrumentation.Owin 88.62% <ø> (ø)
unittests-Instrumentation.Process 100.00% <ø> (ø)
unittests-Instrumentation.Quartz 78.76% <ø> (ø)
unittests-Instrumentation.Remoting 64.28% <ø> (ø)
unittests-Instrumentation.Runtime 100.00% <ø> (ø)
unittests-Instrumentation.ServiceFabricRemoting 40.83% <ø> (ø)
unittests-Instrumentation.SqlClient 84.73% <ø> (-0.49%) ⬇️
unittests-Instrumentation.StackExchangeRedis 93.63% <ø> (ø)
unittests-Instrumentation.Wcf 80.77% <ø> (ø)
unittests-OpAmp.Client 83.77% <100.00%> (+1.17%) ⬆️
unittests-PersistentStorage 68.81% <ø> (-0.33%) ⬇️
unittests-Resources.AWS 74.49% <ø> (ø)
unittests-Resources.Azure 88.31% <ø> (ø)
unittests-Resources.Container 67.34% <ø> (ø)
unittests-Resources.Gcp 71.42% <ø> (ø)
unittests-Resources.Host 72.26% <ø> (ø)
unittests-Resources.OperatingSystem 76.98% <ø> (ø)
unittests-Resources.Process 100.00% <ø> (ø)
unittests-Resources.ProcessRuntime 79.59% <ø> (ø)
unittests-Sampler.AWS 94.27% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...penTelemetry.OpAmp.Client/Internal/FrameBuilder.cs 76.41% <100.00%> (+0.45%) ⬆️
...ry.OpAmp.Client/Internal/OpAmpClientEventSource.cs 44.18% <100.00%> (+3.44%) ⬆️
...essages/RemoteConfiguration/EffectiveConfigFile.cs 100.00% <100.00%> (+14.28%) ⬆️
src/OpenTelemetry.OpAmp.Client/OpAmpClient.cs 94.73% <ø> (ø)
src/Shared/Guard.cs 0.00% <ø> (ø)

... and 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

override OpenTelemetry.OpAmp.Client.Settings.AnyValueUnion.Equals(object? obj) -> bool
override OpenTelemetry.OpAmp.Client.Settings.AnyValueUnion.GetHashCode() -> int
static OpenTelemetry.OpAmp.Client.Messages.EffectiveConfigFile.CreateFromFilePath(string! filePath, string! contentType, string? filename = null) -> OpenTelemetry.OpAmp.Client.Messages.EffectiveConfigFile!
static OpenTelemetry.OpAmp.Client.Messages.EffectiveConfigFile.CreateFromStream(System.IO.Stream! stream, string! contentType = "", string! fileName = "", int maxBytes = 524288) -> OpenTelemetry.OpAmp.Client.Messages.EffectiveConfigFile!
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just skimming the API.

The default value attributes are bad practice from the public API perspective and long term of maintenance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I can tweak that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mostly to provide a sensible max bytes default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An options class to hold the possible values also has the flexibility to make additions without the complexity of binary breaking changes with default/optional parameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content type and file name don't need defaults, I did that to mirror the original method null defaults which are not really valid here. On reflection, requiring those explicitly makes sense. For max size, as nothing else is likely to be needed here, I think an options type is overkill. I think either just requiring that explicitly, or having an overload without it (which then applies the default by calling the limited overload) is better. Open to opinions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of 524288, so something like StreamReader does and have -1 as a sentinel for the default size?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that also isn't my favourite API design for discoverability. I'm now leaning toward just requiring everything as it has a clear purpose and the ctor can be used with a pre-limited block of memory for alternative scenarios.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I've made everything required on both this factory methods and the ctor. In general, I think this is fine for this API, but I'm happy to tweak it further.

Comment thread src/OpenTelemetry.OpAmp.Client/CHANGELOG.md Outdated
Comment thread src/OpenTelemetry.OpAmp.Client/Internal/FrameBuilder.cs Outdated
return new EffectiveConfigFile(ReadOnlyMemory<byte>.Empty, contentType, fileName);
}

var buffer = ArrayPool<byte>.Shared.Rent(maxBytes);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff looks like the code we added recently to encode limits in a shared place - can we add this code there and consume it, rather than make more copies of the pattern we need to verify?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite similar to the stuff added to HttpClientHelpers, but that code isn't quite the right fit as-is and would need generalising futher (exception messages etc) for this use case. Could investigate that as a low-priority follow-up?

stevejgordon and others added 2 commits April 22, 2026 15:11
Co-authored-by: Martin Costello <martin@martincostello.com>
Comment thread test/OpenTelemetry.OpAmp.Client.Tests/Messages/EffectiveConfigFileTests.cs Outdated
Copy link
Copy Markdown
Contributor

@RassK RassK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me

@martincostello martincostello added this pull request to the merge queue Apr 27, 2026
Merged via the queue into open-telemetry:main with commit e338ef4 Apr 27, 2026
637 of 640 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:opamp.client Things related to OpenTelemetry.OpAmp.Client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OpAMP] Change effective config CreateFromFilePath signature

4 participants