2024-09-05 17:52:30 +08:00
|
|
|
package resource
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/fullstorydev/grpchan"
|
|
|
|
|
"github.com/fullstorydev/grpchan/inprocgrpc"
|
|
|
|
|
grpcAuth "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth"
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
|
|
grpcUtils "github.com/grafana/grafana/pkg/storage/unified/resource/grpc"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ResourceClient interface {
|
|
|
|
|
ResourceStoreClient
|
|
|
|
|
ResourceIndexClient
|
|
|
|
|
DiagnosticsClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Internal implementation
|
|
|
|
|
type resourceClient struct {
|
|
|
|
|
ResourceStoreClient
|
|
|
|
|
ResourceIndexClient
|
|
|
|
|
DiagnosticsClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewResourceClient(channel *grpc.ClientConn) ResourceClient {
|
|
|
|
|
cc := grpchan.InterceptClientConn(channel, grpcUtils.UnaryClientInterceptor, grpcUtils.StreamClientInterceptor)
|
|
|
|
|
return &resourceClient{
|
|
|
|
|
ResourceStoreClient: NewResourceStoreClient(cc),
|
|
|
|
|
ResourceIndexClient: NewResourceIndexClient(cc),
|
|
|
|
|
DiagnosticsClient: NewDiagnosticsClient(cc),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewLocalResourceClient(server ResourceServer) ResourceClient {
|
|
|
|
|
channel := &inprocgrpc.Channel{}
|
|
|
|
|
|
|
|
|
|
auth := &grpcUtils.Authenticator{}
|
2024-09-19 22:16:48 +08:00
|
|
|
for _, desc := range []*grpc.ServiceDesc{
|
|
|
|
|
&ResourceStore_ServiceDesc,
|
|
|
|
|
&ResourceIndex_ServiceDesc,
|
|
|
|
|
&Diagnostics_ServiceDesc,
|
|
|
|
|
} {
|
|
|
|
|
channel.RegisterService(
|
|
|
|
|
grpchan.InterceptServer(
|
|
|
|
|
desc,
|
|
|
|
|
grpcAuth.UnaryServerInterceptor(auth.Authenticate),
|
|
|
|
|
grpcAuth.StreamServerInterceptor(auth.Authenticate),
|
|
|
|
|
),
|
|
|
|
|
server,
|
|
|
|
|
)
|
|
|
|
|
}
|
2024-09-05 17:52:30 +08:00
|
|
|
|
|
|
|
|
cc := grpchan.InterceptClientConn(channel, grpcUtils.UnaryClientInterceptor, grpcUtils.StreamClientInterceptor)
|
|
|
|
|
return &resourceClient{
|
|
|
|
|
ResourceStoreClient: NewResourceStoreClient(cc),
|
|
|
|
|
ResourceIndexClient: NewResourceIndexClient(cc),
|
|
|
|
|
DiagnosticsClient: NewDiagnosticsClient(cc),
|
|
|
|
|
}
|
|
|
|
|
}
|