From 91e43ddaea56e398a0b5ab2960e9741a24bbac76 Mon Sep 17 00:00:00 2001 From: Jacob Pleiness Date: Fri, 26 Apr 2024 12:46:06 -0400 Subject: [PATCH] appliance: add API server stub (#62171) Add basic gRPC server for appliance with some generic methods. The gRPC server will be used by other Sourcegraph services to interact with the appliance, while the appliance UI will likely implement it's own API of some kind in the future ## Test plan Tested locally for now. As this is still just a stub more or less, there isn't a huge amount of functionality to test. --- cmd/appliance/shared/BUILD.bazel | 8 +- cmd/appliance/shared/config.go | 17 +- cmd/appliance/shared/main.go | 67 ----- cmd/appliance/shared/shared.go | 120 ++++++++ deps.bzl | 7 + go.mod | 1 + go.sum | 2 + internal/appliance/BUILD.bazel | 2 + internal/appliance/grpc.go | 22 ++ internal/appliance/v1/BUILD.bazel | 28 ++ internal/appliance/v1/appliance.pb.go | 334 +++++++++++++++++++++ internal/appliance/v1/appliance.proto | 27 ++ internal/appliance/v1/appliance_grpc.pb.go | 146 +++++++++ internal/appliance/v1/buf.gen.yaml | 10 + 14 files changed, 720 insertions(+), 71 deletions(-) delete mode 100644 cmd/appliance/shared/main.go create mode 100644 cmd/appliance/shared/shared.go create mode 100644 internal/appliance/grpc.go create mode 100644 internal/appliance/v1/BUILD.bazel create mode 100644 internal/appliance/v1/appliance.pb.go create mode 100644 internal/appliance/v1/appliance.proto create mode 100644 internal/appliance/v1/appliance_grpc.pb.go create mode 100644 internal/appliance/v1/buf.gen.yaml diff --git a/cmd/appliance/shared/BUILD.bazel b/cmd/appliance/shared/BUILD.bazel index 2da613c4c0b..6eb1468d614 100644 --- a/cmd/appliance/shared/BUILD.bazel +++ b/cmd/appliance/shared/BUILD.bazel @@ -4,18 +4,24 @@ go_library( name = "shared", srcs = [ "config.go", - "main.go", "service.go", + "shared.go", ], importpath = "github.com/sourcegraph/sourcegraph/cmd/appliance/shared", visibility = ["//visibility:public"], deps = [ "//internal/appliance", + "//internal/appliance/v1:appliance", "//internal/debugserver", "//internal/env", + "//internal/grpc/defaults", "//internal/observation", "//internal/service", "@com_github_sourcegraph_log//:log", + "@com_github_sourcegraph_log_logr//:logr", "@io_k8s_sigs_controller_runtime//:controller-runtime", + "@io_k8s_sigs_controller_runtime//pkg/metrics/server", + "@org_golang_google_grpc//:go_default_library", + "@org_golang_x_sync//errgroup", ], ) diff --git a/cmd/appliance/shared/config.go b/cmd/appliance/shared/config.go index 97c8aadbda5..9e80e76edbe 100644 --- a/cmd/appliance/shared/config.go +++ b/cmd/appliance/shared/config.go @@ -1,21 +1,32 @@ package shared import ( - "github.com/sourcegraph/sourcegraph/internal/appliance" "github.com/sourcegraph/sourcegraph/internal/env" ) type Config struct { env.BaseConfig - Spec *appliance.Sourcegraph + metrics metricsConfig + grpc grpcConfig } func (c *Config) Load() { - c.Spec = &appliance.Sourcegraph{} + c.metrics.addr = ":8080" + c.metrics.secure = false + c.grpc.addr = ":9000" } func (c *Config) Validate() error { var errs error return errs } + +type metricsConfig struct { + addr string + secure bool +} + +type grpcConfig struct { + addr string +} diff --git a/cmd/appliance/shared/main.go b/cmd/appliance/shared/main.go deleted file mode 100644 index 3b1a691d2b6..00000000000 --- a/cmd/appliance/shared/main.go +++ /dev/null @@ -1,67 +0,0 @@ -package shared - -import ( - "context" - "os" - "os/signal" - "syscall" - - ctrl "sigs.k8s.io/controller-runtime" - - "github.com/sourcegraph/log" - - "github.com/sourcegraph/sourcegraph/internal/appliance" - "github.com/sourcegraph/sourcegraph/internal/observation" - "github.com/sourcegraph/sourcegraph/internal/service" -) - -var onlyOneSignalHandler = make(chan struct{}) - -func Start(ctx context.Context, observationCtx *observation.Context, ready service.ReadyFunc, config *Config) error { - logger := observationCtx.Logger - - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{}) - if err != nil { - logger.Error("unable to start manager", log.Error(err)) - return err - } - - if err = (&appliance.Reconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr); err != nil { - logger.Error("unable to create the appliance controller", log.Error(err)) - return err - } - - // Mark health server as ready - ready() - - logger.Info("starting manager") - if err := mgr.Start(shutdownOnSignal(ctx)); err != nil { - logger.Error("problem running manager", log.Error(err)) - return err - } - - return nil -} - -// shutdownOnSignal registers for SIGTERM and SIGINT. A context is returned -// which is canceled on one of these signals. If a second signal is caught, the program -// is terminated with exit code 1. -func shutdownOnSignal(ctx context.Context) context.Context { - close(onlyOneSignalHandler) - - ctx, cancel := context.WithCancel(ctx) - - c := make(chan os.Signal, 2) - signal.Notify(c, os.Interrupt, syscall.SIGTERM) - go func() { - <-c - cancel() // first signal. Cancel context. - <-c - os.Exit(1) // second signal. Exit now. - }() - - return ctx -} diff --git a/cmd/appliance/shared/shared.go b/cmd/appliance/shared/shared.go new file mode 100644 index 00000000000..cc05d747baf --- /dev/null +++ b/cmd/appliance/shared/shared.go @@ -0,0 +1,120 @@ +package shared + +import ( + "context" + "net" + "os" + "os/signal" + "syscall" + + "golang.org/x/sync/errgroup" + "google.golang.org/grpc" + ctrl "sigs.k8s.io/controller-runtime" + metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" + + "github.com/sourcegraph/log" + sglogr "github.com/sourcegraph/log/logr" + + "github.com/sourcegraph/sourcegraph/internal/appliance" + pb "github.com/sourcegraph/sourcegraph/internal/appliance/v1" + "github.com/sourcegraph/sourcegraph/internal/grpc/defaults" + "github.com/sourcegraph/sourcegraph/internal/observation" + "github.com/sourcegraph/sourcegraph/internal/service" +) + +var onlyOneSignalHandler = make(chan struct{}) + +func Start(ctx context.Context, observationCtx *observation.Context, ready service.ReadyFunc, config *Config) error { + logger := observationCtx.Logger + logr := sglogr.New(logger) + + ctrl.SetLogger(logr) + + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ + Logger: logr, + Metrics: metricsserver.Options{ + BindAddress: config.metrics.addr, + SecureServing: config.metrics.secure, + }, + }) + if err != nil { + logger.Error("unable to start manager", log.Error(err)) + return err + } + + if err = (&appliance.Reconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + logger.Error("unable to create the appliance controller", log.Error(err)) + return err + } + + // Mark health server as ready + ready() + + listener, err := net.Listen("tcp", config.grpc.addr) + if err != nil { + logger.Error("unable to create tcp listener", log.Error(err)) + return err + } + + grpcServer := makeGRPCServer(logger) + + g, ctx := errgroup.WithContext(ctx) + ctx = shutdownOnSignal(ctx) + + g.Go(func() error { + logger.Info("gRPC server listening", log.String("address", listener.Addr().String())) + if err := grpcServer.Serve(listener); err != nil { + logger.Error("problem running gRPC server", log.Error(err)) + return err + } + return nil + }) + + g.Go(func() error { + logger.Info("starting manager") + if err := mgr.Start(ctx); err != nil { + logger.Error("problem running manager", log.Error(err)) + return err + } + return nil + }) + + g.Go(func() error { + <-ctx.Done() + grpcServer.GracefulStop() + logger.Info("shutting down gRPC server gracefully") + return ctx.Err() + }) + + return g.Wait() +} + +func makeGRPCServer(logger log.Logger) *grpc.Server { + grpcServer := defaults.NewServer(logger) + pb.RegisterApplianceServiceServer(grpcServer, &appliance.GRPCServer{}) + + return grpcServer +} + +// shutdownOnSignal registers for SIGTERM and SIGINT. A context is returned +// which is canceled on one of these signals. If a second signal is caught, the program +// is terminated with exit code 1. +func shutdownOnSignal(ctx context.Context) context.Context { + close(onlyOneSignalHandler) + + ctx, cancel := context.WithCancel(ctx) + + c := make(chan os.Signal, 2) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + go func() { + <-c + cancel() // first signal. Cancel context. + <-c + os.Exit(1) // second signal. Exit now. + }() + + return ctx +} diff --git a/deps.bzl b/deps.bzl index 62984d34eed..15b6b03a797 100644 --- a/deps.bzl +++ b/deps.bzl @@ -5370,6 +5370,13 @@ def go_dependencies(): sum = "h1:tHKdC+bXxxGJ0cy/R06kg6Z0zqwVGOWMx8uWsIwsaoY=", version = "v0.0.0-20231018134238-fbadff7458bb", ) + go_repository( + name = "com_github_sourcegraph_log_logr", + build_file_proto_mode = "disable_global", + importpath = "github.com/sourcegraph/log/logr", + sum = "h1:Ov40bLTzue0PfsOCGcRWEJt4Xh8ayq4OwBtawEqHgbM=", + version = "v0.0.0-20240425170707-431bcb6c8668", + ) go_repository( name = "com_github_sourcegraph_managed_services_platform_cdktf_gen_cloudflare", build_file_proto_mode = "disable_global", diff --git a/go.mod b/go.mod index bc83e4d6c87..a68e32ab174 100644 --- a/go.mod +++ b/go.mod @@ -277,6 +277,7 @@ require ( github.com/pkoukk/tiktoken-go-loader v0.0.1 github.com/prometheus/statsd_exporter v0.22.7 github.com/sourcegraph/cloud-api v0.0.0-20231205211631-907f2d5f11b7 + github.com/sourcegraph/log/logr v0.0.0-20240425170707-431bcb6c8668 github.com/sourcegraph/managed-services-platform-cdktf/gen/cloudflare v0.0.0-20230822024612-edb48c530722 github.com/sourcegraph/managed-services-platform-cdktf/gen/google v0.0.0-20240325114905-87053fe51a82 github.com/sourcegraph/managed-services-platform-cdktf/gen/google_beta v0.0.0-20240325114905-87053fe51a82 diff --git a/go.sum b/go.sum index 6c06ea9710d..8f14767f07e 100644 --- a/go.sum +++ b/go.sum @@ -1675,6 +1675,8 @@ github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf h1:oAdWFqhStsWii github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf/go.mod h1:ppFaPm6kpcHnZGqQTFhUIAQRIEhdQDWP1PCv4/ON354= github.com/sourcegraph/log v0.0.0-20231018134238-fbadff7458bb h1:tHKdC+bXxxGJ0cy/R06kg6Z0zqwVGOWMx8uWsIwsaoY= github.com/sourcegraph/log v0.0.0-20231018134238-fbadff7458bb/go.mod h1:IDp09QkoqS8Z3CyN2RW6vXjgABkNpDbyjLIHNQwQ8P8= +github.com/sourcegraph/log/logr v0.0.0-20240425170707-431bcb6c8668 h1:Ov40bLTzue0PfsOCGcRWEJt4Xh8ayq4OwBtawEqHgbM= +github.com/sourcegraph/log/logr v0.0.0-20240425170707-431bcb6c8668/go.mod h1:SMG18ysfwtHJ8CP1z8OOtZ7Pcdr6EXt7ESCtV0hfr4U= github.com/sourcegraph/managed-services-platform-cdktf/gen/cloudflare v0.0.0-20230822024612-edb48c530722 h1:0bXluGjV4O3XBeFA3Kck9kHS3ilvgJo8mW9ADx8oeHE= github.com/sourcegraph/managed-services-platform-cdktf/gen/cloudflare v0.0.0-20230822024612-edb48c530722/go.mod h1:Djd6jHBZqe4/+MEpiBxKvzPS24NqYxNBbAYv/0074JI= github.com/sourcegraph/managed-services-platform-cdktf/gen/google v0.0.0-20240325114905-87053fe51a82 h1:bv17EeWRJavA4xxnXT8iJjKZB9eF9bhV2jOnHl/xcJU= diff --git a/internal/appliance/BUILD.bazel b/internal/appliance/BUILD.bazel index f57d4c3fdef..e168c8ed7c5 100644 --- a/internal/appliance/BUILD.bazel +++ b/internal/appliance/BUILD.bazel @@ -5,6 +5,7 @@ go_library( name = "appliance", srcs = [ "blobstore.go", + "grpc.go", "kubernetes.go", "reconcile.go", "spec.go", @@ -12,6 +13,7 @@ go_library( importpath = "github.com/sourcegraph/sourcegraph/internal/appliance", visibility = ["//:__subpackages__"], deps = [ + "//internal/appliance/v1:appliance", "//internal/k8s/resource/container", "//internal/k8s/resource/deployment", "//internal/k8s/resource/pod", diff --git a/internal/appliance/grpc.go b/internal/appliance/grpc.go new file mode 100644 index 00000000000..519f92064c6 --- /dev/null +++ b/internal/appliance/grpc.go @@ -0,0 +1,22 @@ +package appliance + +import ( + "context" + + pb "github.com/sourcegraph/sourcegraph/internal/appliance/v1" +) + +type GRPCServer struct { + // Embed the UnimplementedApplianceServiceServer structs to ensure forwards compatibility (if the service is + // compiled against a newer version of the proto file, the server will still have default implementations of any new + // RPCs). + pb.UnimplementedApplianceServiceServer +} + +func (s *GRPCServer) GetApplianceVersion(ctx context.Context, request *pb.GetApplianceVersionRequest) (*pb.GetApplianceVersionResponse, error) { + return nil, nil +} + +func (s *GRPCServer) GetApplianceStage(ctx context.Context, request *pb.GetApplianceStageRequest) (*pb.GetApplianceStageResponse, error) { + return nil, nil +} diff --git a/internal/appliance/v1/BUILD.bazel b/internal/appliance/v1/BUILD.bazel new file mode 100644 index 00000000000..d31eeba12bb --- /dev/null +++ b/internal/appliance/v1/BUILD.bazel @@ -0,0 +1,28 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +proto_library( + name = "v1_proto", + srcs = ["appliance.proto"], + strip_import_prefix = "/internal", + visibility = ["//:__subpackages__"], +) + +go_proto_library( + name = "v1_go_proto", + compilers = [ + "//:gen-go-grpc", + "@io_bazel_rules_go//proto:go_proto", + ], + importpath = "github.com/sourcegraph/sourcegraph/internal/appliance/v1", + proto = ":v1_proto", + visibility = ["//:__subpackages__"], +) + +go_library( + name = "appliance", + embed = [":v1_go_proto"], + importpath = "github.com/sourcegraph/sourcegraph/internal/appliance/v1", + visibility = ["//:__subpackages__"], +) diff --git a/internal/appliance/v1/appliance.pb.go b/internal/appliance/v1/appliance.pb.go new file mode 100644 index 00000000000..d3bb88f33d8 --- /dev/null +++ b/internal/appliance/v1/appliance.pb.go @@ -0,0 +1,334 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.29.1 +// protoc (unknown) +// source: appliance.proto + +package v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetApplianceVersionRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetApplianceVersionRequest) Reset() { + *x = GetApplianceVersionRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_appliance_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetApplianceVersionRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetApplianceVersionRequest) ProtoMessage() {} + +func (x *GetApplianceVersionRequest) ProtoReflect() protoreflect.Message { + mi := &file_appliance_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetApplianceVersionRequest.ProtoReflect.Descriptor instead. +func (*GetApplianceVersionRequest) Descriptor() ([]byte, []int) { + return file_appliance_proto_rawDescGZIP(), []int{0} +} + +type GetApplianceVersionResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` +} + +func (x *GetApplianceVersionResponse) Reset() { + *x = GetApplianceVersionResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_appliance_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetApplianceVersionResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetApplianceVersionResponse) ProtoMessage() {} + +func (x *GetApplianceVersionResponse) ProtoReflect() protoreflect.Message { + mi := &file_appliance_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetApplianceVersionResponse.ProtoReflect.Descriptor instead. +func (*GetApplianceVersionResponse) Descriptor() ([]byte, []int) { + return file_appliance_proto_rawDescGZIP(), []int{1} +} + +func (x *GetApplianceVersionResponse) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +type GetApplianceStageRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetApplianceStageRequest) Reset() { + *x = GetApplianceStageRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_appliance_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetApplianceStageRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetApplianceStageRequest) ProtoMessage() {} + +func (x *GetApplianceStageRequest) ProtoReflect() protoreflect.Message { + mi := &file_appliance_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetApplianceStageRequest.ProtoReflect.Descriptor instead. +func (*GetApplianceStageRequest) Descriptor() ([]byte, []int) { + return file_appliance_proto_rawDescGZIP(), []int{2} +} + +type GetApplianceStageResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Stage string `protobuf:"bytes,1,opt,name=stage,proto3" json:"stage,omitempty"` +} + +func (x *GetApplianceStageResponse) Reset() { + *x = GetApplianceStageResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_appliance_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetApplianceStageResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetApplianceStageResponse) ProtoMessage() {} + +func (x *GetApplianceStageResponse) ProtoReflect() protoreflect.Message { + mi := &file_appliance_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetApplianceStageResponse.ProtoReflect.Descriptor instead. +func (*GetApplianceStageResponse) Descriptor() ([]byte, []int) { + return file_appliance_proto_rawDescGZIP(), []int{3} +} + +func (x *GetApplianceStageResponse) GetStage() string { + if x != nil { + return x.Stage + } + return "" +} + +var File_appliance_proto protoreflect.FileDescriptor + +var file_appliance_proto_rawDesc = []byte{ + 0x0a, 0x0f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x0c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x22, + 0x1c, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x56, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x37, 0x0a, + 0x1b, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x56, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x1a, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, + 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x53, 0x74, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x22, 0x31, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, + 0x63, 0x65, 0x53, 0x74, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x73, 0x74, 0x61, 0x67, 0x65, 0x32, 0xee, 0x01, 0x0a, 0x10, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x61, + 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6f, 0x0a, 0x13, 0x47, 0x65, + 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x12, 0x28, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x76, 0x31, + 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x56, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x61, 0x70, + 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, + 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x03, 0x90, 0x02, 0x01, 0x12, 0x69, 0x0a, 0x11, 0x47, + 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x53, 0x74, 0x61, 0x67, 0x65, + 0x12, 0x26, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, + 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x53, 0x74, 0x61, 0x67, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, + 0x61, 0x6e, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, + 0x61, 0x6e, 0x63, 0x65, 0x53, 0x74, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x03, 0x90, 0x02, 0x01, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, + 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x67, 0x72, 0x61, 0x70, 0x68, 0x2f, 0x69, 0x6e, 0x74, + 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x2f, + 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_appliance_proto_rawDescOnce sync.Once + file_appliance_proto_rawDescData = file_appliance_proto_rawDesc +) + +func file_appliance_proto_rawDescGZIP() []byte { + file_appliance_proto_rawDescOnce.Do(func() { + file_appliance_proto_rawDescData = protoimpl.X.CompressGZIP(file_appliance_proto_rawDescData) + }) + return file_appliance_proto_rawDescData +} + +var file_appliance_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_appliance_proto_goTypes = []interface{}{ + (*GetApplianceVersionRequest)(nil), // 0: appliance.v1.GetApplianceVersionRequest + (*GetApplianceVersionResponse)(nil), // 1: appliance.v1.GetApplianceVersionResponse + (*GetApplianceStageRequest)(nil), // 2: appliance.v1.GetApplianceStageRequest + (*GetApplianceStageResponse)(nil), // 3: appliance.v1.GetApplianceStageResponse +} +var file_appliance_proto_depIdxs = []int32{ + 0, // 0: appliance.v1.ApplianceService.GetApplianceVersion:input_type -> appliance.v1.GetApplianceVersionRequest + 2, // 1: appliance.v1.ApplianceService.GetApplianceStage:input_type -> appliance.v1.GetApplianceStageRequest + 1, // 2: appliance.v1.ApplianceService.GetApplianceVersion:output_type -> appliance.v1.GetApplianceVersionResponse + 3, // 3: appliance.v1.ApplianceService.GetApplianceStage:output_type -> appliance.v1.GetApplianceStageResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_appliance_proto_init() } +func file_appliance_proto_init() { + if File_appliance_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_appliance_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetApplianceVersionRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_appliance_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetApplianceVersionResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_appliance_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetApplianceStageRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_appliance_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetApplianceStageResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_appliance_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_appliance_proto_goTypes, + DependencyIndexes: file_appliance_proto_depIdxs, + MessageInfos: file_appliance_proto_msgTypes, + }.Build() + File_appliance_proto = out.File + file_appliance_proto_rawDesc = nil + file_appliance_proto_goTypes = nil + file_appliance_proto_depIdxs = nil +} diff --git a/internal/appliance/v1/appliance.proto b/internal/appliance/v1/appliance.proto new file mode 100644 index 00000000000..d0af08a7a44 --- /dev/null +++ b/internal/appliance/v1/appliance.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package appliance.v1; + +option go_package = "github.com/sourcegraph/sourcegraph/internal/appliance/v1"; + +service ApplianceService { + rpc GetApplianceVersion(GetApplianceVersionRequest) returns (GetApplianceVersionResponse) { + option idempotency_level = NO_SIDE_EFFECTS; + } + + rpc GetApplianceStage(GetApplianceStageRequest) returns (GetApplianceStageResponse) { + option idempotency_level = NO_SIDE_EFFECTS; + } +} + +message GetApplianceVersionRequest {} + +message GetApplianceVersionResponse { + string version = 1; +} + +message GetApplianceStageRequest {} + +message GetApplianceStageResponse { + string stage = 1; +} diff --git a/internal/appliance/v1/appliance_grpc.pb.go b/internal/appliance/v1/appliance_grpc.pb.go new file mode 100644 index 00000000000..545510586ee --- /dev/null +++ b/internal/appliance/v1/appliance_grpc.pb.go @@ -0,0 +1,146 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: appliance.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + ApplianceService_GetApplianceVersion_FullMethodName = "/appliance.v1.ApplianceService/GetApplianceVersion" + ApplianceService_GetApplianceStage_FullMethodName = "/appliance.v1.ApplianceService/GetApplianceStage" +) + +// ApplianceServiceClient is the client API for ApplianceService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ApplianceServiceClient interface { + GetApplianceVersion(ctx context.Context, in *GetApplianceVersionRequest, opts ...grpc.CallOption) (*GetApplianceVersionResponse, error) + GetApplianceStage(ctx context.Context, in *GetApplianceStageRequest, opts ...grpc.CallOption) (*GetApplianceStageResponse, error) +} + +type applianceServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewApplianceServiceClient(cc grpc.ClientConnInterface) ApplianceServiceClient { + return &applianceServiceClient{cc} +} + +func (c *applianceServiceClient) GetApplianceVersion(ctx context.Context, in *GetApplianceVersionRequest, opts ...grpc.CallOption) (*GetApplianceVersionResponse, error) { + out := new(GetApplianceVersionResponse) + err := c.cc.Invoke(ctx, ApplianceService_GetApplianceVersion_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *applianceServiceClient) GetApplianceStage(ctx context.Context, in *GetApplianceStageRequest, opts ...grpc.CallOption) (*GetApplianceStageResponse, error) { + out := new(GetApplianceStageResponse) + err := c.cc.Invoke(ctx, ApplianceService_GetApplianceStage_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ApplianceServiceServer is the server API for ApplianceService service. +// All implementations must embed UnimplementedApplianceServiceServer +// for forward compatibility +type ApplianceServiceServer interface { + GetApplianceVersion(context.Context, *GetApplianceVersionRequest) (*GetApplianceVersionResponse, error) + GetApplianceStage(context.Context, *GetApplianceStageRequest) (*GetApplianceStageResponse, error) + mustEmbedUnimplementedApplianceServiceServer() +} + +// UnimplementedApplianceServiceServer must be embedded to have forward compatible implementations. +type UnimplementedApplianceServiceServer struct { +} + +func (UnimplementedApplianceServiceServer) GetApplianceVersion(context.Context, *GetApplianceVersionRequest) (*GetApplianceVersionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetApplianceVersion not implemented") +} +func (UnimplementedApplianceServiceServer) GetApplianceStage(context.Context, *GetApplianceStageRequest) (*GetApplianceStageResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetApplianceStage not implemented") +} +func (UnimplementedApplianceServiceServer) mustEmbedUnimplementedApplianceServiceServer() {} + +// UnsafeApplianceServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ApplianceServiceServer will +// result in compilation errors. +type UnsafeApplianceServiceServer interface { + mustEmbedUnimplementedApplianceServiceServer() +} + +func RegisterApplianceServiceServer(s grpc.ServiceRegistrar, srv ApplianceServiceServer) { + s.RegisterService(&ApplianceService_ServiceDesc, srv) +} + +func _ApplianceService_GetApplianceVersion_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetApplianceVersionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ApplianceServiceServer).GetApplianceVersion(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ApplianceService_GetApplianceVersion_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ApplianceServiceServer).GetApplianceVersion(ctx, req.(*GetApplianceVersionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ApplianceService_GetApplianceStage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetApplianceStageRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ApplianceServiceServer).GetApplianceStage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ApplianceService_GetApplianceStage_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ApplianceServiceServer).GetApplianceStage(ctx, req.(*GetApplianceStageRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ApplianceService_ServiceDesc is the grpc.ServiceDesc for ApplianceService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ApplianceService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "appliance.v1.ApplianceService", + HandlerType: (*ApplianceServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetApplianceVersion", + Handler: _ApplianceService_GetApplianceVersion_Handler, + }, + { + MethodName: "GetApplianceStage", + Handler: _ApplianceService_GetApplianceStage_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "appliance.proto", +} diff --git a/internal/appliance/v1/buf.gen.yaml b/internal/appliance/v1/buf.gen.yaml new file mode 100644 index 00000000000..8d1f631d1bd --- /dev/null +++ b/internal/appliance/v1/buf.gen.yaml @@ -0,0 +1,10 @@ +version: v1 +plugins: + - plugin: buf.build/protocolbuffers/go:v1.29.1 + out: . + opt: + - paths=source_relative + - plugin: buf.build/grpc/go:v1.3.0 + out: . + opt: + - paths=source_relative