-
Notifications
You must be signed in to change notification settings - Fork 86
Make it possible to set capabilities #366
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
base: main
Are you sure you want to change the base?
Make it possible to set capabilities #366
Conversation
For context i need this to solve open-telemetry/opentelemetry-operator#3822. Introducing leader election to the bridge for HA would mean one of the bridge pods would need to change its capabilities while running. I could accomplish this by shutting down and then re-starting the opamp client, but that's very heavy and unnecessary IMO. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #366 +/- ##
==========================================
+ Coverage 80.10% 80.14% +0.04%
==========================================
Files 25 26 +1
Lines 2423 2549 +126
==========================================
+ Hits 1941 2043 +102
- Misses 374 391 +17
- Partials 108 115 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@@ -10,6 +10,8 @@ import ( | |||
"github.com/open-telemetry/opamp-go/protobufs" | |||
) | |||
|
|||
var _ OpAMPClient = &httpClient{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We use both styles in the code, but this one is more common.
var _ OpAMPClient = &httpClient{} | |
var _ OpAMPClient = (*httpClient)(nil) |
@@ -22,6 +22,8 @@ const ( | |||
defaultShutdownTimeout = 5 * time.Second | |||
) | |||
|
|||
var _ OpAMPClient = &wsClient{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var _ OpAMPClient = &wsClient{} | |
var _ OpAMPClient = (*wsClient)(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The spec does not say whether this is a support operation (to change capabilities after they are first reported). Let me think about it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking temporarily, give me a bit time to think about the implications of this.
Sounds good. I held off on merging until you had a chance to look at it. My reading of the spec was that since it was not specifically mentioned or prohibited that it would be ok to allow it. Some servers may expect this to stay the same for the life of the connection (based on the existing go implementation and not a requirement of the spec) but since it is passed with every message I think the server should be able to adjust as needed. |
I don't think we can make this blanket change. There are capabilities which are checked at the Start() and the corresponding invariants for the capabilities are checked at the same time. For example, in PrepareStart() we verify that if AcceptsPackages is set then PackagesStateProvider is also provided. Later in receivedProcessor we rely on this invariant. If we break the invariant (which you can easily do via SetCapabilities) then receivedProcessor will attempt to use a nil PackagesStateProvider (which will either crash or error, I didn't look further). At least from implementation perspective this is not a change we can make. I am also not sure conceptually it works for every single capability, to allow changing them on the fly. Before we make this blanket change I would like to see the analysis which explain why it is OK to change each particular capability on the fly (I am not sure that is true). Then we will need to make sure the implementation is ready for that (it is currently not). We will also need to update the spec to explain that this is an allowed mode of operation. As an alternate, is there a particular capability that you need to change after Start()? we can look at supporting just that. |
Yes, i did notice that. I think we could do instantiation on demand though based on the capabilities being set. Initially, I just need to be able to enable |
I think AcceptsRemoteConfig is doable. I don't see any special invariants for this capability in the codebase. We can do this:
|
@tigrannajaryan made the updates, i have one open question on this |
// QUESTION: DO we want this? | ||
// SetPackagesStateProvider allows the confgiguration of the packages state provider after start. | ||
// func (c *ClientCommon) SetPackagesStateProvider(packagesStateProvider types.PackagesStateProvider) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now there would be no way for a client to set the package state provider if they wanted to modify the package capabilities. Should this be exposed to allow for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand. Why would the client need to set the state provider after the Start? It can be set before Start, but can return a different set of packages anytime.
// | ||
// For more details, refer to the OpAMP specification: | ||
// https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agenttoservercapabilities | ||
SetCapabilities(capabilities *protobufs.AgentCapabilities) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This results in inconsistent way of setting capabilities depending on when you want to do it: before Start() requires setting a field in StartSettings, after Start() requires calling this method.
For functionality that MUST be set before Start() and MAY be set after Start() we previously used only a method. See for example SetAgentDescription().
Should we do the same for SetCapabilities() and deprecate Capabilities field from StartSettings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... I think that makes sense to me. @andykellr does that sound alright to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaronoff97 I am not sure if you updated the PR to make this change. Is it ready for another review round?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was waiting on andy's review and when you said "we decided to go ahead with this feature" I thought it was dismissing this comment. I see now, i'll update the PR based on what you said above in this thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no problem, I just wasn't sure if I need to take another look.
I would like @andykellr's opinion too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaronoff97 in case I wasn't clear, I am waiting for you to tell me if this is ready for another round of review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was waiting on andy's opinion here, but either way i can make your requested changes from above before its ready for more review. apologies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaronoff97 sounds good, thanks. Ping me when you update the PR, I will take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tigrannajaryan i had two questions for the implementation below, but i think this should be good! Thank you for your patience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is fine with me.
We decided to go ahead with this feature.
@@ -129,6 +131,12 @@ func prepareClient(t *testing.T, settings *types.StartSettings, c OpAMPClient) { | |||
prepareSettings(t, settings, c) | |||
err := c.SetAgentDescription(createAgentDescr()) | |||
assert.NoError(t, err) | |||
// We ignore the error here. | |||
if settings.Capabilities != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had to ignore the error here because a later test depended on the checks happening in the start client
if err := c.ClientSyncedState.SetCapabilities(&capabilities); err != nil { | ||
return err | ||
// Deprecated: Use client.SetCapabilities() instead. | ||
if settings.Capabilities != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tigrannajaryan this technically could be a breaking change if someone isn't setting any capabilities, should I just default to setting reports status here and then in the future we remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should emit a warning in the log if SetCapabilities is not called before Start. Later, we can make it an error. Then finally some time after that we remove Settings.Capabilities field.
In any of these 3 states, ReportsStatus should always be automatically added, regardless of how the Capabilities are set (via Settings or via method call).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tigrannajaryan i do make sure reportsstatus is always set (I do the add in this method as well in the clientcommon setcapabilities), but I'll add in a log right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tigrannajaryan should be all good now. PTAL 🙇
Closes #365