-
Notifications
You must be signed in to change notification settings - Fork 351
[OpAMP.Client] Add support for plain http transport #2926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b236c0b
OpAmp plain http transport
RassK 34fea2b
fix warnings
RassK f1fe378
spelling fix
RassK 0ce14b0
feedback
RassK f494074
remove aot verification
RassK 84bfe5e
Merge branch 'main' into opamp-client-http
Kielek 9591147
Update proto namespaces
RassK f96fec1
Merge branch 'opamp-client-http' of https://github.com/RassK/opentele…
RassK 886be93
Merge branch 'main' into opamp-client-http
RassK 8db011f
fix test proto namespace
RassK 559c42b
remove aot test
RassK 5c4ee57
Merge branch 'main' into opamp-client-http
RassK dcc3b61
Merge branch 'main' into opamp-client-http
RassK 4c90ba3
seal classes
RassK 8506ef0
add guid v7 support for .net9+
RassK bd930fa
Update src/OpenTelemetry.OpAmp.Client/OpenTelemetry.OpAmp.Client.csproj
RassK 54d57a8
Merge branch 'main' into opamp-client-http
Kielek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using Google.Protobuf; | ||
using OpAmp.Proto.V1; | ||
|
||
namespace OpenTelemetry.OpAmp.Client; | ||
|
||
internal sealed class FrameBuilder : IFrameBuilder | ||
{ | ||
private readonly OpAmpClientSettings settings; | ||
|
||
private AgentToServer? currentMessage; | ||
private ByteString instanceUid; | ||
private ulong sequenceNum; | ||
|
||
public FrameBuilder(OpAmpClientSettings settings) | ||
{ | ||
this.settings = settings; | ||
this.instanceUid = ByteString.CopyFrom(this.settings.InstanceUid.ToByteArray()); | ||
} | ||
|
||
public IFrameBuilder StartBaseMessage() | ||
{ | ||
if (this.currentMessage != null) | ||
{ | ||
throw new InvalidOperationException("Message base is already initialized."); | ||
} | ||
|
||
var message = new AgentToServer() | ||
{ | ||
InstanceUid = this.instanceUid, | ||
SequenceNum = ++this.sequenceNum, | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
this.currentMessage = message; | ||
return this; | ||
} | ||
|
||
AgentToServer IFrameBuilder.Build() | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (this.currentMessage == null) | ||
{ | ||
throw new InvalidOperationException("Message base is not initialized."); | ||
} | ||
|
||
var message = this.currentMessage; | ||
this.currentMessage = null; // Reset for the next message | ||
|
||
return message; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
this.currentMessage = null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using OpenTelemetry.Internal; | ||
using OpenTelemetry.OpAmp.Client.Transport; | ||
|
||
namespace OpenTelemetry.OpAmp.Client; | ||
|
||
internal class FrameDispatcher : IDisposable | ||
{ | ||
private readonly IOpAmpTransport transport; | ||
private readonly FrameBuilder frameBuilder; | ||
private readonly SemaphoreSlim syncRoot = new(1, 1); | ||
|
||
public FrameDispatcher(IOpAmpTransport transport, OpAmpClientSettings settings) | ||
{ | ||
Guard.ThrowIfNull(transport, nameof(transport)); | ||
Guard.ThrowIfNull(settings, nameof(settings)); | ||
|
||
this.transport = transport; | ||
this.frameBuilder = new FrameBuilder(settings); | ||
} | ||
|
||
// TODO: May need to redesign to request only partials | ||
// so any other message waiting to be sent can be included to optimize transport usage and locking time. | ||
public async Task DispatchServerFrameAsync(CancellationToken token) | ||
{ | ||
await this.syncRoot.WaitAsync(token) | ||
.ConfigureAwait(false); | ||
|
||
try | ||
{ | ||
var message = this.frameBuilder | ||
.StartBaseMessage() | ||
.Build(); | ||
|
||
// TODO: change to proper logging | ||
Console.WriteLine("Sending identification message."); | ||
|
||
await this.transport.SendAsync(message, token) | ||
.ConfigureAwait(false); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// TODO: change to proper logging | ||
Console.WriteLine($"[Error]: {ex.Message}"); | ||
|
||
this.frameBuilder.Reset(); // Reset the builder in case of failure | ||
} | ||
finally | ||
{ | ||
this.syncRoot.Release(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
this.syncRoot.Dispose(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Buffers; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Immutable; | ||
using OpAmp.Proto.V1; | ||
using OpenTelemetry.Internal; | ||
using OpenTelemetry.OpAmp.Client.Listeners; | ||
using OpenTelemetry.OpAmp.Client.Listeners.Messages; | ||
|
||
namespace OpenTelemetry.OpAmp.Client; | ||
|
||
internal class FrameProcessor | ||
martincostello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
private readonly ConcurrentDictionary<Type, ImmutableList<IOpAmpListener>> listeners = []; | ||
|
||
public void Subscribe<T>(IOpAmpListener<T> listener) | ||
where T : IOpAmpMessage | ||
{ | ||
Guard.ThrowIfNull(listener, nameof(listener)); | ||
|
||
// It is expected to be much more read-heavy than write-heavy, so we use ImmutableList for thread safety | ||
this.listeners.AddOrUpdate( | ||
typeof(T), | ||
_ => [listener], | ||
(_, list) => list.Add(listener)); | ||
} | ||
|
||
public void Unsubscribe<T>(IOpAmpListener<T> listener) | ||
where T : IOpAmpMessage | ||
{ | ||
Guard.ThrowIfNull(listener, nameof(listener)); | ||
|
||
this.listeners.AddOrUpdate( | ||
typeof(T), | ||
_ => ImmutableList<IOpAmpListener>.Empty, | ||
(_, list) => | ||
{ | ||
if (list.Count == 1 && list[0] == listener) | ||
{ | ||
return ImmutableList<IOpAmpListener>.Empty; | ||
} | ||
|
||
return list.Remove(listener); | ||
}); | ||
} | ||
|
||
public void OnServerFrame(ReadOnlySequence<byte> sequence) | ||
{ | ||
this.Deserialize(sequence); | ||
} | ||
|
||
private void Deserialize(ReadOnlySequence<byte> sequence) | ||
{ | ||
var message = ServerToAgent.Parser.ParseFrom(sequence); | ||
|
||
if (message.ErrorResponse != null) | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
this.Dispatch(new ErrorResponseMessage(message.ErrorResponse)); | ||
} | ||
|
||
if (message.RemoteConfig != null) | ||
{ | ||
this.Dispatch(new RemoteConfigMessage(message.RemoteConfig)); | ||
} | ||
|
||
if (message.ConnectionSettings != null) | ||
{ | ||
this.Dispatch(new ConnectionSettingsMessage(message.ConnectionSettings)); | ||
} | ||
|
||
if (message.PackagesAvailable != null) | ||
{ | ||
this.Dispatch(new PackagesAvailableMessage(message.PackagesAvailable)); | ||
} | ||
|
||
if (message.Flags != 0) | ||
{ | ||
this.Dispatch(new FlagsMessage((ServerToAgentFlags)message.Flags)); | ||
} | ||
|
||
if (message.Capabilities != 0) | ||
{ | ||
this.Dispatch(new CapabilitiesMessage((ServerCapabilities)message.Capabilities)); | ||
} | ||
|
||
if (message.AgentIdentification != null) | ||
{ | ||
this.Dispatch(new AgentIdentificationMessage(message.AgentIdentification)); | ||
} | ||
|
||
if (message.Command != null) | ||
{ | ||
this.Dispatch(new CommandMessage(message.Command)); | ||
} | ||
|
||
if (message.CustomCapabilities != null) | ||
{ | ||
this.Dispatch(new CustomCapabilitiesMessage(message.CustomCapabilities)); | ||
} | ||
|
||
if (message.CustomMessage != null) | ||
{ | ||
this.Dispatch(new CustomMessageMessage(message.CustomMessage)); | ||
} | ||
} | ||
|
||
private void Dispatch<T>(T message) | ||
where T : IOpAmpMessage | ||
{ | ||
if (this.listeners.TryGetValue(typeof(T), out var list)) | ||
{ | ||
foreach (var listener in list) | ||
{ | ||
if (listener is IOpAmpListener<T> typedListener) | ||
{ | ||
typedListener.HandleMessage(message); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using OpAmp.Proto.V1; | ||
|
||
namespace OpenTelemetry.OpAmp.Client; | ||
|
||
internal interface IFrameBuilder | ||
{ | ||
AgentToServer Build(); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/OpenTelemetry.OpAmp.Client/Listeners/IOpAmpListener.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
namespace OpenTelemetry.OpAmp.Client.Listeners; | ||
|
||
internal interface IOpAmpListener | ||
{ | ||
} | ||
|
||
internal interface IOpAmpListener<TMessage> : IOpAmpListener | ||
where TMessage : IOpAmpMessage | ||
{ | ||
void HandleMessage(TMessage message); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
namespace OpenTelemetry.OpAmp.Client.Listeners; | ||
|
||
internal interface IOpAmpMessage | ||
{ | ||
} | ||
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this just intended to be a marker interface? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, due some partials in ServerToAgent aren't IMessages, just flags. |
16 changes: 16 additions & 0 deletions
16
src/OpenTelemetry.OpAmp.Client/Listeners/Messages/AgentIdentificationMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using OpAmp.Proto.V1; | ||
|
||
namespace OpenTelemetry.OpAmp.Client.Listeners.Messages; | ||
|
||
internal class AgentIdentificationMessage : IOpAmpMessage | ||
{ | ||
public AgentIdentificationMessage(AgentIdentification agentIdentification) | ||
{ | ||
this.AgentIdentification = agentIdentification; | ||
} | ||
|
||
public AgentIdentification AgentIdentification { get; set; } | ||
} | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
16 changes: 16 additions & 0 deletions
16
src/OpenTelemetry.OpAmp.Client/Listeners/Messages/CapabilitiesMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using OpAmp.Proto.V1; | ||
|
||
namespace OpenTelemetry.OpAmp.Client.Listeners.Messages; | ||
|
||
internal class CapabilitiesMessage : IOpAmpMessage | ||
{ | ||
public CapabilitiesMessage(ServerCapabilities capabilities) | ||
{ | ||
this.Capabilities = capabilities; | ||
} | ||
|
||
public ServerCapabilities Capabilities { get; set; } | ||
} |
16 changes: 16 additions & 0 deletions
16
src/OpenTelemetry.OpAmp.Client/Listeners/Messages/CommandMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using OpAmp.Proto.V1; | ||
|
||
namespace OpenTelemetry.OpAmp.Client.Listeners.Messages; | ||
|
||
internal class CommandMessage : IOpAmpMessage | ||
{ | ||
public CommandMessage(ServerToAgentCommand command) | ||
{ | ||
this.Command = command; | ||
} | ||
|
||
public ServerToAgentCommand Command { get; set; } | ||
} |
16 changes: 16 additions & 0 deletions
16
src/OpenTelemetry.OpAmp.Client/Listeners/Messages/ConnectionSettingsMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using OpAmp.Proto.V1; | ||
|
||
namespace OpenTelemetry.OpAmp.Client.Listeners.Messages; | ||
|
||
internal class ConnectionSettingsMessage : IOpAmpMessage | ||
{ | ||
public ConnectionSettingsMessage(ConnectionSettingsOffers connectionSettingsOffers) | ||
{ | ||
this.ConnectionSettings = connectionSettingsOffers; | ||
} | ||
|
||
public ConnectionSettingsOffers ConnectionSettings { get; set; } | ||
} |
16 changes: 16 additions & 0 deletions
16
src/OpenTelemetry.OpAmp.Client/Listeners/Messages/CustomCapabilitiesMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using OpAmp.Proto.V1; | ||
|
||
namespace OpenTelemetry.OpAmp.Client.Listeners.Messages; | ||
|
||
internal class CustomCapabilitiesMessage : IOpAmpMessage | ||
{ | ||
public CustomCapabilitiesMessage(CustomCapabilities customCapabilities) | ||
{ | ||
this.CustomCapabilities = customCapabilities; | ||
} | ||
|
||
public CustomCapabilities CustomCapabilities { get; set; } | ||
} |
16 changes: 16 additions & 0 deletions
16
src/OpenTelemetry.OpAmp.Client/Listeners/Messages/CustomMessageMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using OpAmp.Proto.V1; | ||
|
||
namespace OpenTelemetry.OpAmp.Client.Listeners.Messages; | ||
|
||
internal class CustomMessageMessage : IOpAmpMessage | ||
{ | ||
public CustomMessageMessage(CustomMessage customMessage) | ||
{ | ||
this.CustomMessage = customMessage; | ||
} | ||
|
||
public CustomMessage CustomMessage { get; set; } | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.