Skip to content

Commit 0f96ab9

Browse files
feat: kill and stable RPCs [DTSS-595] (#118)
1 parent 57b709c commit 0f96ab9

File tree

18 files changed

+650
-361
lines changed

18 files changed

+650
-361
lines changed

api/v1/v1.go renamed to api/v1.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package v1
14+
package api
1515

16-
//go:generate ../../scripts/shell-wrapper.sh protoc.sh ./v1.proto
16+
//go:generate ../scripts/shell-wrapper.sh protoc.sh ./v1.proto

api/v1/v1.pb.go renamed to api/v1.pb.go

Lines changed: 491 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/v1.proto renamed to api/v1.proto

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
syntax = "proto3";
1616

1717
package api.v1;
18-
option go_package = "github.com/getoutreach/localizer/api/v1";
18+
option go_package = "github.com/getoutreach/localizer/api";
1919

2020
message ExposeServiceRequest {
2121
string namespace = 1;
@@ -65,9 +65,17 @@ message ListResponse {
6565
repeated ListService services = 1;
6666
}
6767

68+
message Empty {}
69+
70+
message StableResponse {
71+
bool stable = 1;
72+
}
73+
6874
service LocalizerService {
6975
rpc ExposeService(ExposeServiceRequest) returns (stream ConsoleResponse) {}
7076
rpc StopExpose(StopExposeRequest) returns (stream ConsoleResponse) {}
7177
rpc List(ListRequest) returns (ListResponse) {}
7278
rpc Ping(PingRequest) returns (PingResponse) {}
79+
rpc Kill(Empty) returns (Empty) {}
80+
rpc Stable(Empty) returns (StableResponse) {}
7381
}

api/v1/v1_grpc.pb.go

Lines changed: 0 additions & 261 deletions
This file was deleted.

cmd/localizer/expose.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"strings"
2222
"time"
2323

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

6363
log.Info("connecting to localizer daemon")
6464

65-
client, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure())
65+
client, closer, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure())
6666
if err != nil {
6767
return errors.Wrap(err, "failed to connect to localizer daemon")
6868
}
69+
defer closer()
6970

70-
var stream apiv1.LocalizerService_ExposeServiceClient
71+
var stream api.LocalizerService_ExposeServiceClient
7172
if c.Bool("stop") {
7273
log.Info("sending stop expose request to daemon")
73-
stream, err = client.StopExpose(ctx, &apiv1.StopExposeRequest{
74+
stream, err = client.StopExpose(ctx, &api.StopExposeRequest{
7475
Namespace: serviceNamespace,
7576
Service: serviceName,
7677
})
7778
} else {
7879
log.Info("sending expose request to daemon")
79-
stream, err = client.ExposeService(ctx, &apiv1.ExposeServiceRequest{
80+
stream, err = client.ExposeService(ctx, &api.ExposeServiceRequest{
8081
PortMap: c.StringSlice("map"),
8182
Namespace: serviceNamespace,
8283
Service: serviceName,
@@ -96,10 +97,10 @@ func NewExposeCommand(log logrus.FieldLogger) *cli.Command { //nolint:funlen
9697

9798
logger := log.Info
9899
switch res.Level {
99-
case apiv1.ConsoleLevel_CONSOLE_LEVEL_INFO, apiv1.ConsoleLevel_CONSOLE_LEVEL_UNSPECIFIED:
100-
case apiv1.ConsoleLevel_CONSOLE_LEVEL_WARN:
100+
case api.ConsoleLevel_CONSOLE_LEVEL_INFO, api.ConsoleLevel_CONSOLE_LEVEL_UNSPECIFIED:
101+
case api.ConsoleLevel_CONSOLE_LEVEL_WARN:
101102
logger = log.Warn
102-
case apiv1.ConsoleLevel_CONSOLE_LEVEL_ERROR:
103+
case api.ConsoleLevel_CONSOLE_LEVEL_ERROR:
103104
logger = log.Error
104105
}
105106

cmd/localizer/list.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"text/tabwriter"
2424
"time"
2525

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

47-
client, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure())
47+
client, closer, err := localizer.Connect(ctx, grpc.WithBlock(), grpc.WithInsecure())
4848
if err != nil {
4949
return errors.Wrap(err, "failed to connect to localizer daemon")
5050
}
51+
defer closer()
5152

52-
resp, err := client.List(ctx, &apiv1.ListRequest{})
53+
resp, err := client.List(ctx, &api.ListRequest{})
5354
if err != nil {
5455
return err
5556
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/function61/gokit v0.0.0-20210402130425-341c2c9ecfd0
1313
github.com/go-logr/logr v0.4.0
1414
github.com/go-sql-driver/mysql v1.6.0 // indirect
15-
github.com/golang/protobuf v1.5.2
1615
github.com/google/go-cmp v0.5.5
1716
github.com/gorilla/mux v1.8.0 // indirect
1817
github.com/imdario/mergo v0.3.12 // indirect
@@ -25,6 +24,7 @@ require (
2524
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect
2625
golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c // indirect
2726
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
27+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
2828
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
2929
google.golang.org/genproto v0.0.0-20210505142820-a42aa055cf76 // indirect
3030
google.golang.org/grpc v1.37.0

go.sum

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)