Skip to content

Commit ddd2b01

Browse files
committed
monitor: replaced basic RPC with gRPC
1 parent 0d7cea2 commit ddd2b01

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [0ver](https://0ver.org) (more or less).
2323
- Upgraded most dependencies to their lastest versions
2424
- Fixed child pipeline jobs not found whilst looking up through bridges (#345)
2525
- `gitlab_ci_pipeline_job_queued_duration_seconds` & `gitlab_ci_pipeline_queued_duration_seconds` will now be leveraging the value returned through the GitLab API instead of computing it with (startedAt - createdAt)
26+
- Refactored the RPC layer used for CLI monitoring with gRPC
2627

2728
## [v0.5.3] - 2022-02-11
2829

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ REPOSITORY := mvisonneau/$(NAME)
77
setup: ## Install required libraries/tools for build tasks
88
@command -v gofumpt 2>&1 >/dev/null || go install mvdan.cc/[email protected]
99
@command -v golangci-lint 2>&1 >/dev/null || go install github.com/golangci/golangci-lint/cmd/[email protected]
10-
@command -v protoc 2>&1 >/dev/null || (echo "protoc needs to be available in PATH: https://github.com/protocolbuffers/protobuf/releases"; false)
11-
@command -v protoc-gen-go 2>&1 >/dev/null || go install google.golang.org/grpc/cmd/[email protected]
1210

1311
.PHONY: fmt
1412
fmt: setup ## Format source code
@@ -38,7 +36,9 @@ release: ## Build & release the binaries (stable)
3836

3937
.PHONY: protoc
4038
protoc: setup ## Generate golang from .proto files
41-
@protoc \
39+
@command -v protoc 2>&1 >/dev/null || (echo "protoc needs to be available in PATH: https://github.com/protocolbuffers/protobuf/releases"; false)
40+
@command -v protoc-gen-go 2>&1 >/dev/null || go install google.golang.org/grpc/cmd/[email protected]
41+
protoc \
4242
--go_out=. --go_opt=paths=source_relative \
4343
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
4444
pkg/monitor/protobuf/monitor.proto

internal/cmd/monitor.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cmd
22

33
import (
4-
"context"
5-
64
monitorUI "github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/monitor/ui"
75
"github.com/urfave/cli/v2"
86
)
@@ -15,7 +13,6 @@ func Monitor(ctx *cli.Context) (int, error) {
1513
}
1614

1715
monitorUI.Start(
18-
context.Background(),
1916
ctx.App.Version,
2017
cfg.InternalMonitoringListenerAddress,
2118
)

pkg/monitor/client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Client struct {
1818
// NewClient ..
1919
func NewClient(ctx context.Context, endpoint *url.URL) *Client {
2020
log.WithField("endpoint", endpoint.String()).Debug("establishing gRPC connection to the server..")
21+
2122
conn, err := grpc.DialContext(
2223
ctx,
2324
endpoint.String(),

pkg/monitor/server/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import (
99
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/config"
1010
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/gitlab"
1111
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/monitor"
12+
pb "github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/monitor/protobuf"
1213
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/schemas"
1314
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/store"
15+
log "github.com/sirupsen/logrus"
1416
"google.golang.org/grpc"
1517
"google.golang.org/protobuf/types/known/timestamppb"
16-
17-
pb "github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/monitor/protobuf"
18-
log "github.com/sirupsen/logrus"
1918
)
2019

2120
// Server ..

pkg/monitor/ui/ui.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ func max(a, b int) int {
120120
}
121121

122122
type model struct {
123-
ctx context.Context
124123
version string
125124
client *client.Client
126125
vp viewport.Model
@@ -131,7 +130,7 @@ type model struct {
131130
}
132131

133132
func (m *model) renderConfigViewport() string {
134-
config, err := m.client.GetConfig(m.ctx, &pb.Empty{})
133+
config, err := m.client.GetConfig(context.TODO(), &pb.Empty{})
135134
if err != nil || config == nil {
136135
log.WithError(err).Fatal()
137136
}
@@ -225,24 +224,23 @@ func prettyTimeago(t time.Time) string {
225224
return timeago.English.Format(t)
226225
}
227226

228-
func newModel(ctx context.Context, version string, endpoint *url.URL) (m *model) {
227+
func newModel(version string, endpoint *url.URL) (m *model) {
229228
p := progress.NewModel(progress.WithScaledGradient("#80c904", "#ff9d5c"))
230229

231230
m = &model{
232-
ctx: ctx,
233231
version: version,
234232
vp: viewport.Model{},
235233
telemetryStream: make(chan *pb.Telemetry),
236234
progress: &p,
237-
client: client.NewClient(ctx, endpoint),
235+
client: client.NewClient(context.TODO(), endpoint),
238236
}
239237

240238
return
241239
}
242240

243241
func (m *model) Init() tea.Cmd {
244242
return tea.Batch(
245-
m.streamTelemetry(m.ctx),
243+
m.streamTelemetry(context.TODO()),
246244
waitForTelemetryUpdate(m.telemetryStream),
247245
)
248246
}
@@ -279,11 +277,11 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
279277
m.vp = vp
280278

281279
return m, cmd
282-
283280
}
284281
case *pb.Telemetry:
285282
m.telemetry = msg
286283
m.setPaneContent()
284+
287285
return m, waitForTelemetryUpdate(m.telemetryStream)
288286
}
289287

@@ -359,9 +357,9 @@ func waitForTelemetryUpdate(t chan *pb.Telemetry) tea.Cmd {
359357
}
360358

361359
// Start ..
362-
func Start(ctx context.Context, version string, listenerAddress *url.URL) {
360+
func Start(version string, listenerAddress *url.URL) {
363361
if err := tea.NewProgram(
364-
newModel(ctx, version, listenerAddress),
362+
newModel(version, listenerAddress),
365363
tea.WithAltScreen(),
366364
).Start(); err != nil {
367365
fmt.Println("Error running program:", err)

0 commit comments

Comments
 (0)