Skip to content

Commit

Permalink
feat: kill and stable RPCs [DTSS-595] (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
george-e-shaw-iv authored Aug 9, 2021
1 parent 57b709c commit 0f96ab9
Show file tree
Hide file tree
Showing 18 changed files with 650 additions and 361 deletions.
4 changes: 2 additions & 2 deletions api/v1/v1.go → api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1
package api

//go:generate ../../scripts/shell-wrapper.sh protoc.sh ./v1.proto
//go:generate ../scripts/shell-wrapper.sh protoc.sh ./v1.proto
544 changes: 491 additions & 53 deletions api/v1/v1.pb.go → api/v1.pb.go

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion api/v1/v1.proto → api/v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
syntax = "proto3";

package api.v1;
option go_package = "github.com/getoutreach/localizer/api/v1";
option go_package = "github.com/getoutreach/localizer/api";

message ExposeServiceRequest {
string namespace = 1;
Expand Down Expand Up @@ -65,9 +65,17 @@ message ListResponse {
repeated ListService services = 1;
}

message Empty {}

message StableResponse {
bool stable = 1;
}

service LocalizerService {
rpc ExposeService(ExposeServiceRequest) returns (stream ConsoleResponse) {}
rpc StopExpose(StopExposeRequest) returns (stream ConsoleResponse) {}
rpc List(ListRequest) returns (ListResponse) {}
rpc Ping(PingRequest) returns (PingResponse) {}
rpc Kill(Empty) returns (Empty) {}
rpc Stable(Empty) returns (StableResponse) {}
}
261 changes: 0 additions & 261 deletions api/v1/v1_grpc.pb.go

This file was deleted.

17 changes: 9 additions & 8 deletions cmd/localizer/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"
"time"

apiv1 "github.com/getoutreach/localizer/api/v1"
"github.com/getoutreach/localizer/api"
"github.com/getoutreach/localizer/pkg/localizer"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -62,21 +62,22 @@ func NewExposeCommand(log logrus.FieldLogger) *cli.Command { //nolint:funlen

log.Info("connecting to localizer daemon")

client, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure())
client, closer, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure())
if err != nil {
return errors.Wrap(err, "failed to connect to localizer daemon")
}
defer closer()

var stream apiv1.LocalizerService_ExposeServiceClient
var stream api.LocalizerService_ExposeServiceClient
if c.Bool("stop") {
log.Info("sending stop expose request to daemon")
stream, err = client.StopExpose(ctx, &apiv1.StopExposeRequest{
stream, err = client.StopExpose(ctx, &api.StopExposeRequest{
Namespace: serviceNamespace,
Service: serviceName,
})
} else {
log.Info("sending expose request to daemon")
stream, err = client.ExposeService(ctx, &apiv1.ExposeServiceRequest{
stream, err = client.ExposeService(ctx, &api.ExposeServiceRequest{
PortMap: c.StringSlice("map"),
Namespace: serviceNamespace,
Service: serviceName,
Expand All @@ -96,10 +97,10 @@ func NewExposeCommand(log logrus.FieldLogger) *cli.Command { //nolint:funlen

logger := log.Info
switch res.Level {
case apiv1.ConsoleLevel_CONSOLE_LEVEL_INFO, apiv1.ConsoleLevel_CONSOLE_LEVEL_UNSPECIFIED:
case apiv1.ConsoleLevel_CONSOLE_LEVEL_WARN:
case api.ConsoleLevel_CONSOLE_LEVEL_INFO, api.ConsoleLevel_CONSOLE_LEVEL_UNSPECIFIED:
case api.ConsoleLevel_CONSOLE_LEVEL_WARN:
logger = log.Warn
case apiv1.ConsoleLevel_CONSOLE_LEVEL_ERROR:
case api.ConsoleLevel_CONSOLE_LEVEL_ERROR:
logger = log.Error
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/localizer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"text/tabwriter"
"time"

apiv1 "github.com/getoutreach/localizer/api/v1"
"github.com/getoutreach/localizer/api"
"github.com/getoutreach/localizer/pkg/localizer"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand All @@ -44,12 +44,13 @@ func NewListCommand(_ logrus.FieldLogger) *cli.Command { //nolint:funlen
ctx, cancel := context.WithTimeout(c.Context, 30*time.Second)
defer cancel()

client, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure())
client, closer, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure())
if err != nil {
return errors.Wrap(err, "failed to connect to localizer daemon")
}
defer closer()

resp, err := client.List(ctx, &apiv1.ListRequest{})
resp, err := client.List(ctx, &api.ListRequest{})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/function61/gokit v0.0.0-20210402130425-341c2c9ecfd0
github.com/go-logr/logr v0.4.0
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.5
github.com/gorilla/mux v1.8.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
Expand All @@ -25,6 +24,7 @@ require (
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect
golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
google.golang.org/genproto v0.0.0-20210505142820-a42aa055cf76 // indirect
google.golang.org/grpc v1.37.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0f96ab9

Please sign in to comment.