Skip to content

Commit

Permalink
monitor: replaced basic RPC with gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
mvisonneau committed May 4, 2022
1 parent 5ceabea commit 0aea812
Show file tree
Hide file tree
Showing 15 changed files with 1,055 additions and 360 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [0ver](https://0ver.org) (more or less).
- Upgraded most dependencies to their lastest versions
- Fixed child pipeline jobs not found whilst looking up through bridges (#345)
- `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)
- Refactored the RPC layer used for CLI monitoring with gRPC

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

Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ release: ## Build & release the binaries (stable)
goreleaser release --rm-dist
find dist -type f -name "*.snap" -exec snapcraft upload --release stable,edge '{}' \;

.PHONY: protoc
protoc: setup ## Generate golang from .proto files
@command -v protoc 2>&1 >/dev/null || (echo "protoc needs to be available in PATH: https://github.com/protocolbuffers/protobuf/releases"; false)
@command -v protoc-gen-go 2>&1 >/dev/null || go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0
protoc \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
pkg/monitor/protobuf/monitor.proto

.PHONY: prerelease
prerelease: setup ## Build & prerelease the binaries (edge)
@\
Expand Down
1 change: 0 additions & 1 deletion examples/opentelemetry/gitlab-ci-pipelines-exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ gitlab:
redis:
url: redis://redis:6379


# Example public projects to monitor
projects:
- name: gitlab-org/gitlab-runner
Expand Down
15 changes: 7 additions & 8 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/controller"
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/monitor/rpc"
monitoringServer "github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/monitor/server"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
Expand All @@ -32,14 +32,13 @@ func Run(cliCtx *cli.Context) (int, error) {

// Start the monitoring RPC server
go func(c *controller.Controller) {
rpc.ServeUNIX(
rpc.NewServer(
c.Gitlab,
c.Config,
c.Store,
c.TaskController.TaskSchedulingMonitoring,
),
s := monitoringServer.NewServer(
c.Gitlab,
c.Config,
c.Store,
c.TaskController.TaskSchedulingMonitoring,
)
s.Serve()
}(&c)

// Graceful shutdowns
Expand Down
7 changes: 2 additions & 5 deletions pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,8 @@ func (c *Controller) ScheduleTaskWithTicker(ctx context.Context, tt schemas.Task

return
case <-ticker.C:
switch tt {
default:
c.ScheduleTask(ctx, tt, "_")
c.TaskController.monitorNextTaskScheduling(tt, intervalSeconds)
}
c.ScheduleTask(ctx, tt, "_")
c.TaskController.monitorNextTaskScheduling(tt, intervalSeconds)
}
}
}(ctx)
Expand Down
36 changes: 36 additions & 0 deletions pkg/monitor/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package client

import (
"context"
"net/url"

pb "github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/monitor/protobuf"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

// Client ..
type Client struct {
pb.MonitorClient
}

// NewClient ..
func NewClient(ctx context.Context, endpoint *url.URL) *Client {
log.WithField("endpoint", endpoint.String()).Debug("establishing gRPC connection to the server..")

conn, err := grpc.DialContext(
ctx,
endpoint.String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
log.WithField("endpoint", endpoint.String()).WithField("error", err).Fatal("could not connect to the server")
}

log.Debug("gRPC connection established")

return &Client{
MonitorClient: pb.NewMonitorClient(conn),
}
}
8 changes: 8 additions & 0 deletions pkg/monitor/monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package monitor

import "time"

type TaskSchedulingStatus struct {
Last time.Time
Next time.Time
}
Loading

0 comments on commit 0aea812

Please sign in to comment.