opamp-spec icon indicating copy to clipboard operation
opamp-spec copied to clipboard

Unable to set multiple Capabilities in a single message when using Java/Kotlin protobuf

Open nephyst opened this issue 3 years ago • 3 comments

AgentCapabilities capabilities = 4;

ServerCapabilities capabilities = 7;

The intent of these fields is to pack multiple flags into a single field. According to the protobuf docs, Enum fields only allow a single value. When compiled to Java or Kotlin the generated objects do not allow for setting multiple capability flags to a single enum.

This can be fixed by changing the field to be an int32 with manual bit packing, or by repeating the enum fields.

nephyst avatar Aug 18 '22 22:08 nephyst

This is the setCapabilities method in the java ServerToAgent object builder:

      public Builder setCapabilities(opamp.proto.Opamp.ServerCapabilities value) {
        if (value == null) {
          throw new NullPointerException();
        }
        
        capabilities_ = value.getNumber();
        onChanged();
        return this;
      }

nephyst avatar Aug 18 '22 22:08 nephyst

I think we need to change the bit fields to uint64. The enum declarations can stay to show what the bit values are.

tigrannajaryan avatar Sep 20 '22 16:09 tigrannajaryan

@nephyst thanks for reporting the problem. Does this fix the problem in Java/Kotlin: https://github.com/open-telemetry/opamp-spec/pull/125 ?

tigrannajaryan avatar Sep 20 '22 17:09 tigrannajaryan

Yes, thank you!

nephyst avatar Sep 22 '22 01:09 nephyst