Skip to content
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

Expose the RemoteAddr via the Connection interface #57

Merged

Conversation

andykellr
Copy link
Contributor

This was originally proposed in a slack message in the CNCF otel-agentmanwg channel.

@andykellr andykellr requested a review from a team March 14, 2022 19:01
RemoteAddr() net.Addr

// Header returns the request header fields of the http request that opened the connection.
Header() http.Header
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the Header here? The header can be already accessed in the OnConnecting callback, so this seems redundant.

Copy link
Contributor Author

@andykellr andykellr Mar 22, 2022

Choose a reason for hiding this comment

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

OnConnecting provides the request but at that point there is no agent information available, e.g. InstanceUid or AgentDescription, which would identify which agent is actually connecting. This information will come later in a message after the connection is established. There is also no Connection because the connection isn't established. Providing the Header on the connection will make this information available in the other callbacks and allow the server to tie this information together.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

My other concern is that we may want to support gRPC in the future (see open-telemetry/opamp-spec#61) and I don't know if HTTP headers are accessible in gRPC server implementations. If they are not then we may not be able to implement this Header() function correctly.

Can you check this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. HTTP headers are generally not accessible in gRPC implementations. This presents an issue with the existing OnConnecting callback because http.Request is also not available in gRPC implementations. We can take this out if you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

Let's add RemoteAddr() in this PR and we can think about what we do with Header() separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

So, looks like it is called Metadata and defined as:

// Metadata is an immutable map, meant to contain request metadata.
type Metadata struct {
	data map[string][]string
}

RemoteAddr() net.Addr

// Header returns the request header fields of the http request that opened the connection.
Header() http.Header
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the Header here? The header can be already accessed in the OnConnecting callback, so this seems redundant.

RemoteAddr() net.Addr

// Header returns the request header fields of the http request that opened the connection.
Header() http.Header
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

My other concern is that we may want to support gRPC in the future (see open-telemetry/opamp-spec#61) and I don't know if HTTP headers are accessible in gRPC server implementations. If they are not then we may not be able to implement this Header() function correctly.

Can you check this?

@andykellr andykellr force-pushed the connection-remoteaddr-and-headers branch from 9b82cb8 to 967d5df Compare March 22, 2022 17:50
@andykellr andykellr changed the title Expose the RemoteAddr and request Header via the Connection interface Expose the RemoteAddr via the Connection interface Mar 22, 2022
@@ -2,13 +2,17 @@ package types

import (
"context"
"net"

"github.com/open-telemetry/opamp-go/protobufs"
)

// Connection represents one OpAMP WebSocket connections.
// The implementation MUST be a comparable type so that it can be used as a map key.
type Connection interface {
Copy link
Member

@tigrannajaryan tigrannajaryan Mar 22, 2022

Choose a reason for hiding this comment

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

@andykellr to support the use case that you have I think we also need to add net.Conn as a field. This will allow to access the TLS certificate. I believe net.Conn is accessible for WebSocket (UnderlyingConn() in ws gorilla). If you can confirm it is also accessible for gRPC connections and for plain HTTP connections then it should be OK to add it to this interface.

Copy link
Member

Choose a reason for hiding this comment

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

@andykellr this PR looks good to me now. I will merge as is and you can address this comment in a separate PR if you need the Conn.

@@ -16,6 +17,10 @@ type connection struct {

var _ types.Connection = (*connection)(nil)

func (c connection) RemoteAddr() net.Addr {
return c.RemoteAddr()
Copy link
Member

Choose a reason for hiding this comment

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

Is this recursively calling itself or I am misreading the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You didn't read that wrong. I put this PR together quickly to begin discussion and it was an oversight. It clearly needs a test case as well.

Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

Please add a test to verify the new functionality.

Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

LGTM.

@tigrannajaryan tigrannajaryan merged commit 405adf8 into open-telemetry:main Apr 5, 2022
@andykellr andykellr deleted the connection-remoteaddr-and-headers branch April 7, 2022 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants