Skip to content

go: add REMOTE_CONFIG DebugService ping handler for example client - #247

Merged
domodwyer merged 2 commits into
mainfrom
kyle.ames/go-magic-tunnel-pingpong
Sep 4, 2026
Merged

go: add REMOTE_CONFIG DebugService ping handler for example client#247
domodwyer merged 2 commits into
mainfrom
kyle.ames/go-magic-tunnel-pingpong

Conversation

@ameske

@ameske ameske commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Adds a handler to allow us to handle the ping/pong magic tunnel dispatch messages as an example of how to do this, and to also help enable our e2e PoC.

Adds a handler to allow us to handle the ping/pong magic tunnel
dispatch messages as an example of how to do this, and to also
help enable our e2e PoC.
Copilot AI lite review requested due to automatic review settings September 3, 2026 19:48
@ameske
ameske requested a review from a team as a code owner September 3, 2026 19:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new handler logs untrusted input without quoting (log forging risk) and leaves the correlation ID unused, which should be addressed before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an example REMOTE_CONFIG DebugService ping handler to the testx509 Go example client so it can participate in magic-tunnel ping/pong dispatches (useful for the e2e PoC).

Changes:

  • Add handleDebugService that unmarshals DebugServiceRequest and answers Ping with a PingResponse timestamp.
  • Add unit tests covering Ping handling and unset/unsupported subtopic behavior.
  • Register the REMOTE_CONFIG namespace handler from the testx509 example’s main.
File summaries
File Description
ffi-hosts/go/cmd/testx509/pingpong.go Implements the REMOTE_CONFIG DebugService dispatch handler and response creation.
ffi-hosts/go/cmd/testx509/pingpong_test.go Adds tests validating ping response behavior and unsupported/unset subtopic handling.
ffi-hosts/go/cmd/testx509/main.go Registers the new handler for the REMOTE_CONFIG namespace in the example client.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ffi-hosts/go/cmd/testx509/pingpong.go Outdated

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Datadog Autotest: PASS

More details

The handler uses the expected DebugService request and response envelopes. It registers before the client starts.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit 02ff775 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

aya-shimizu24
aya-shimizu24 previously approved these changes Sep 3, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines +16 to +41
// handleDebugService implements libddrcffi.HandlerFunc for the
// NAMESPACE_REMOTE_CONFIG namespace. It answers a Ping subtopic with a Pong
// carrying the current time.
func handleDebugService(correlationID uint64, payload []byte) ([]byte, error) {
var req remoteconfigv1.DebugServiceRequest
if err := proto.Unmarshal(payload, &req); err != nil {
return nil, err
}

switch subtopic := req.GetSubtopic().(type) {
case *remoteconfigv1.DebugServiceRequest_Ping:
ping := subtopic.Ping
log.Printf("received ping (correlation_id=%d) from connection %q: reason=%q", correlationID, ping.GetConnectionId(), ping.GetReason())

resp := &remoteconfigv1.DebugServiceResponse{
Subtopic: &remoteconfigv1.DebugServiceResponse_Ping{
Ping: &remoteconfigv1.PingResponse{
Now: timestamppb.Now(),
},
},
}
return proto.Marshal(resp)
default:
return nil, errUnsupportedSubtopic
}
}

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.

So this is the amount of code needed to integrate a magic tunnel handler + response for external teams 👌

Top stuff - this has very nicely abstracted away all the connection complexity 🙏

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new tests will emit log output on every run due to the handler’s global log.Printf, which should be silenced in tests to avoid noisy CI output.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

ffi-hosts/go/cmd/testx509/pingpong_test.go:45

  • This test also triggers log output from handleDebugService; call the shared test helper to discard logs here as well.
func TestHandleDebugService_UnsetSubtopic(t *testing.T) {
	req := &remoteconfigv1.DebugServiceRequest{}
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +3 to +12
import (
"errors"
"testing"

remoteconfigv1 "github.com/DataDog/libdd-rc/ffi-hosts/go/rcproto/magic_tunnel/remote_config"
"google.golang.org/protobuf/proto"
)

func TestHandleDebugService_Ping(t *testing.T) {
req := &remoteconfigv1.DebugServiceRequest{
@domodwyer
domodwyer enabled auto-merge September 4, 2026 09:24
}
return proto.Marshal(resp)
default:
return nil, errUnsupportedSubtopic

@hithwen hithwen Sep 4, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: Should the error also contain which subtopic was received for debugging purposes?

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 error will include the correlation_id in the backend / client logs that specifies which exact request caused the error 👍

Additionally, this error message will be returned to the team sending the request in the backend as the response to their gRPC call!

@domodwyer
domodwyer added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit 667effe Sep 4, 2026
25 checks passed
@domodwyer
domodwyer deleted the kyle.ames/go-magic-tunnel-pingpong branch September 4, 2026 09:35
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.

6 participants