Repository: open-telemetry/opamp-go
Pull request #34 (2021-12-06 22:24:19)

Make protobufs and client CallbacksStruct public
This PR exports protobufs and client callbacks

Protobufs are required to use the Callbacks interface

CallbacksStruct make it easier to initialise Client (no need to implement the whole interface, only specific functions)

pmm-sumo: > Need to also fix makefile since it contains the path to protobufs dir.

Good point @tigrannajaryan . Updated gen-proto section and package name

Patch:
diff --git a/client/internal/callbacks.go b/client/callbacks.go
similarity index 97%
rename from client/internal/callbacks.go
rename to client/callbacks.go
index 9aed5c8..60c02b3 100644
--- a/client/internal/callbacks.go
+++ b/client/callbacks.go
@@ -1,10 +1,10 @@
-package internal
+package client
 
 import (
 	"context"
 
 	"github.com/open-telemetry/opamp-go/client/types"
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 type CallbacksStruct struct {
diff --git a/client/client.go b/client/client.go
index 6926482..24dba03 100644
--- a/client/client.go
+++ b/client/client.go
@@ -6,7 +6,7 @@ import (
 	"time"
 
 	"github.com/open-telemetry/opamp-go/client/types"
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 type StartSettings struct {
diff --git a/client/clientimpl.go b/client/clientimpl.go
index 64f41fc..a223195 100644
--- a/client/clientimpl.go
+++ b/client/clientimpl.go
@@ -16,7 +16,7 @@ import (
 	"github.com/open-telemetry/opamp-go/client/internal"
 	"github.com/open-telemetry/opamp-go/client/types"
 	sharedinternal "github.com/open-telemetry/opamp-go/internal"
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 var (
diff --git a/client/internal/mockserver.go b/client/internal/mockserver.go
index f9e8066..ce64886 100644
--- a/client/internal/mockserver.go
+++ b/client/internal/mockserver.go
@@ -11,8 +11,8 @@ import (
 	"github.com/stretchr/testify/assert"
 	"google.golang.org/protobuf/proto"
 
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
 	"github.com/open-telemetry/opamp-go/internal/testhelpers"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 type MockServer struct {
diff --git a/client/internal/receiver.go b/client/internal/receiver.go
index 58decc5..f21889a 100644
--- a/client/internal/receiver.go
+++ b/client/internal/receiver.go
@@ -8,7 +8,7 @@ import (
 	"google.golang.org/protobuf/proto"
 
 	"github.com/open-telemetry/opamp-go/client/types"
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 // Receiver implements the client's receiving portion of OpAMP protocol.
diff --git a/client/internal/sender.go b/client/internal/sender.go
index 243004b..498d735 100644
--- a/client/internal/sender.go
+++ b/client/internal/sender.go
@@ -8,7 +8,7 @@ import (
 	"google.golang.org/protobuf/proto"
 
 	"github.com/open-telemetry/opamp-go/client/types"
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 // Sender implements the client's sending portion of OpAMP protocol.
diff --git a/client/types/callbacks.go b/client/types/callbacks.go
index 10c1cc5..d5f90ca 100644
--- a/client/types/callbacks.go
+++ b/client/types/callbacks.go
@@ -3,7 +3,7 @@ package types
 import (
 	"context"
 
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 type OwnTelemetryType int
diff --git a/internal/proto/anyvalue.proto b/internal/proto/anyvalue.proto
index 0ff2ba3..8ed9731 100644
--- a/internal/proto/anyvalue.proto
+++ b/internal/proto/anyvalue.proto
@@ -22,7 +22,7 @@ syntax = "proto3";
 
 package opamp.proto;
 
-option go_package = "github.com/open-telemetry/opamp-go/internal/protobufs";
+option go_package = "github.com/open-telemetry/opamp-go/protobufs";
 
 // AnyValue is used to represent any type of attribute value. AnyValue may contain a
 // primitive value such as a string or integer or it may contain an arbitrary nested
diff --git a/internal/proto/opamp.proto b/internal/proto/opamp.proto
index 37cf30b..b81517a 100644
--- a/internal/proto/opamp.proto
+++ b/internal/proto/opamp.proto
@@ -20,7 +20,7 @@ package opamp.proto;
 
 import "anyvalue.proto";
 
-option go_package = "github.com/open-telemetry/opamp-go/internal/protobufs";
+option go_package = "github.com/open-telemetry/opamp-go/protobufs";
 
 message AgentToServer {
     // Globally unique identifier of the running instance of the agent. SHOULD remain
diff --git a/makefile b/makefile
index 54e7688..046c922 100644
--- a/makefile
+++ b/makefile
@@ -21,7 +21,7 @@ gen-proto:
         -w${PWD} otel/build-protobuf:latest --proto_path=${PWD}/internal/proto/ \
         --go_out=${PWD}/internal/proto/ -I${PWD}/internal/proto/ ${PWD}/$(file)))
 
-	cp -R internal/proto/github.com/open-telemetry/opamp-go/internal/protobufs/* internal/protobufs/
+	cp -R internal/proto/github.com/open-telemetry/opamp-go/protobufs/* protobufs/
 	rm -rf internal/proto/github.com/
 
 .PHONY: gomoddownload
diff --git a/internal/protobufs/anyvalue.pb.go b/protobufs/anyvalue.pb.go
similarity index 100%
rename from internal/protobufs/anyvalue.pb.go
rename to protobufs/anyvalue.pb.go
diff --git a/internal/protobufs/opamp.pb.go b/protobufs/opamp.pb.go
similarity index 100%
rename from internal/protobufs/opamp.pb.go
rename to protobufs/opamp.pb.go
diff --git a/server/internal/callbacks.go b/server/callbacks.go
similarity index 93%
rename from server/internal/callbacks.go
rename to server/callbacks.go
index 5d0d6b8..e8dc6be 100644
--- a/server/internal/callbacks.go
+++ b/server/callbacks.go
@@ -1,9 +1,9 @@
-package internal
+package server
 
 import (
 	"net/http"
 
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 	"github.com/open-telemetry/opamp-go/server/types"
 )
 
diff --git a/server/connection.go b/server/connection.go
index 2b19de1..64947ba 100644
--- a/server/connection.go
+++ b/server/connection.go
@@ -6,7 +6,7 @@ import (
 	"github.com/gorilla/websocket"
 	"google.golang.org/protobuf/proto"
 
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 	"github.com/open-telemetry/opamp-go/server/types"
 )
 
diff --git a/server/serverimpl.go b/server/serverimpl.go
index 0caf9ea..8ce004d 100644
--- a/server/serverimpl.go
+++ b/server/serverimpl.go
@@ -10,7 +10,7 @@ import (
 
 	"github.com/open-telemetry/opamp-go/client/types"
 	"github.com/open-telemetry/opamp-go/internal"
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 var (
diff --git a/server/types/callbacks.go b/server/types/callbacks.go
index 1303ceb..0305d4a 100644
--- a/server/types/callbacks.go
+++ b/server/types/callbacks.go
@@ -3,7 +3,7 @@ package types
 import (
 	"net/http"
 
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 // ConnectionResponse is the return type of the OnConnecting callback.
diff --git a/server/types/connection.go b/server/types/connection.go
index d4dba6b..fe706be 100644
--- a/server/types/connection.go
+++ b/server/types/connection.go
@@ -3,7 +3,7 @@ package types
 import (
 	"context"
 
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 // Connection represents one OpAMP WebSocket connections.


Test patch:
diff --git a/client/clientimpl_test.go b/client/clientimpl_test.go
index 9fe0cb0..9357732 100644
--- a/client/clientimpl_test.go
+++ b/client/clientimpl_test.go
@@ -9,14 +9,14 @@ import (
 	"time"
 
 	"github.com/gorilla/websocket"
-	"github.com/oklog/ulid/v2"
+	ulid "github.com/oklog/ulid/v2"
 	"github.com/stretchr/testify/assert"
 	"google.golang.org/protobuf/proto"
 
 	"github.com/open-telemetry/opamp-go/client/internal"
 	"github.com/open-telemetry/opamp-go/client/types"
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
 	"github.com/open-telemetry/opamp-go/internal/testhelpers"
+	"github.com/open-telemetry/opamp-go/protobufs"
 )
 
 func TestConnectInvalidURL(t *testing.T) {
@@ -63,7 +63,7 @@ func TestOnConnectFail(t *testing.T) {
 	var connectErr atomic.Value
 	settings := StartSettings{
 		OpAMPServerURL: "ws://" + testhelpers.GetAvailableLocalAddress(),
-		Callbacks: internal.CallbacksStruct{
+		Callbacks: CallbacksStruct{
 			OnConnectFailedFunc: func(err error) {
 				connectErr.Store(err)
 			},
@@ -117,7 +117,7 @@ func TestConnectWithServer(t *testing.T) {
 	// Start a client.
 	var connected int64
 	settings := StartSettings{
-		Callbacks: internal.CallbacksStruct{
+		Callbacks: CallbacksStruct{
 			OnConnectFunc: func() {
 				atomic.StoreInt64(&connected, 1)
 			},
@@ -153,7 +153,7 @@ func TestConnectWithServer503(t *testing.T) {
 	var clientConnected int64
 	var connectErr atomic.Value
 	settings := StartSettings{
-		Callbacks: internal.CallbacksStruct{
+		Callbacks: CallbacksStruct{
 			OnConnectFunc: func() {
 				atomic.StoreInt64(&clientConnected, 1)
 				assert.Fail(t, "Client should not be able to connect")
@@ -214,7 +214,7 @@ func TestDisconnectByServer(t *testing.T) {
 	var connected int64
 	var connectErr atomic.Value
 	settings := StartSettings{
-		Callbacks: internal.CallbacksStruct{
+		Callbacks: CallbacksStruct{
 			OnConnectFunc: func() {
 				atomic.StoreInt64(&connected, 1)
 			},
@@ -262,7 +262,7 @@ func TestFirstStatusReport(t *testing.T) {
 	// Start a client.
 	var connected, remoteConfigReceived int64
 	settings := StartSettings{
-		Callbacks: internal.CallbacksStruct{
+		Callbacks: CallbacksStruct{
 			OnConnectFunc: func() {
 				atomic.AddInt64(&connected, 1)
 			},
@@ -382,7 +382,7 @@ func TestConnectionSettings(t *testing.T) {
 
 	// Start a client.
 	settings := StartSettings{
-		Callbacks: internal.CallbacksStruct{
+		Callbacks: CallbacksStruct{
 			OnOpampConnectionSettingsFunc: func(
 				ctx context.Context, settings *protobufs.ConnectionSettings,
 			) error {
diff --git a/server/serverimpl_test.go b/server/serverimpl_test.go
index 1d068cb..71ae2f7 100644
--- a/server/serverimpl_test.go
+++ b/server/serverimpl_test.go
@@ -10,9 +10,8 @@ import (
 
 	"github.com/gorilla/websocket"
 	sharedinternal "github.com/open-telemetry/opamp-go/internal"
-	"github.com/open-telemetry/opamp-go/internal/protobufs"
 	"github.com/open-telemetry/opamp-go/internal/testhelpers"
-	"github.com/open-telemetry/opamp-go/server/internal"
+	"github.com/open-telemetry/opamp-go/protobufs"
 	"github.com/open-telemetry/opamp-go/server/types"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
@@ -53,7 +52,7 @@ func TestServerStartStop(t *testing.T) {
 }
 
 func TestServerStartRejectConnection(t *testing.T) {
-	callbacks := internal.CallbacksStruct{
+	callbacks := CallbacksStruct{
 		OnConnectingFunc: func(request *http.Request) types.ConnectionResponse {
 			// Reject the incoming HTTP connection.
 			return types.ConnectionResponse{
@@ -87,7 +86,7 @@ func TestServerStartAcceptConnection(t *testing.T) {
 	connectedCalled := int32(0)
 	connectionCloseCalled := int32(0)
 	var srvConn types.Connection
-	callbacks := internal.CallbacksStruct{
+	callbacks := CallbacksStruct{
 		OnConnectingFunc: func(request *http.Request) types.ConnectionResponse {
 			return types.ConnectionResponse{Accept: true}
 		},
@@ -125,7 +124,7 @@ func TestServerStartAcceptConnection(t *testing.T) {
 
 func TestServerReceiveSendMessage(t *testing.T) {
 	var rcvMsg atomic.Value
-	callbacks := internal.CallbacksStruct{
+	callbacks := CallbacksStruct{
 		OnConnectingFunc: func(request *http.Request) types.ConnectionResponse {
 			return types.ConnectionResponse{Accept: true}
 		},
@@ -184,7 +183,7 @@ func TestServerAttachAcceptConnection(t *testing.T) {
 	connectedCalled := int32(0)
 	connectionCloseCalled := int32(0)
 	var srvConn types.Connection
-	callbacks := internal.CallbacksStruct{
+	callbacks := CallbacksStruct{
 		OnConnectingFunc: func(request *http.Request) types.ConnectionResponse {
 			return types.ConnectionResponse{Accept: true}
 		},