Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-11261 Update PMM via watchtower #2844

Merged
merged 20 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions api/serverpb/json/client/server/start_update_parameters.go

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

37 changes: 37 additions & 0 deletions api/serverpb/json/client/server/start_update_responses.go

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

8 changes: 7 additions & 1 deletion api/serverpb/json/serverpb.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
601 changes: 306 additions & 295 deletions api/serverpb/server.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/serverpb/server.pb.validate.go

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

4 changes: 3 additions & 1 deletion api/serverpb/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ message CheckUpdatesResponse {
google.protobuf.Timestamp last_check = 5;
}

message StartUpdateRequest {}
message StartUpdateRequest {
string new_image = 1;
}

message StartUpdateResponse {
// Authentication token for getting update statuses.
Expand Down
8 changes: 7 additions & 1 deletion api/swagger/swagger-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -3649,7 +3649,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
8 changes: 7 additions & 1 deletion api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ services:
- ENABLE_RBAC=${ENABLE_RBAC:-0}
- LESS_LOG_NOISE=1
- PERCONA_TEST_VERSION_SERVICE_URL=${PERCONA_TEST_VERSION_SERVICE_URL}
- PMM_WATCHTOWER_HOST=${PMM_WATCHTOWER_HOST:-http://watchtower:8080}
- PMM_WATCHTOWER_TOKEN=${PMM_WATCHTOWER_TOKEN:-123}
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
# - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost
# - PERCONA_TEST_PLATFORM_INSECURE=1
# - PERCONA_TEST_PLATFORM_PUBLIC_KEY=<public key>
Expand Down Expand Up @@ -94,6 +96,22 @@ services:
# /opt/entrypoint.sh
# "

# docker run -v /var/run/docker.sock:/var/run/docker.sock -e WATCHTOWER_HTTP_API_UPDATE=1 -e WATCHTOWER_HTTP_API_TOKEN=123 --hostname=watchtower --network=pmm_default docker.io/bupychuk/watchtower
watchtower:
profiles:
- pmm
image: ${WATCHTOWER_IMAGE:-perconalab/watchtower}
container_name: watchtower
environment:
- WATCHTOWER_HTTP_LISTEN_PORT=8080
- WATCHTOWER_HTTP_API_UPDATE=1
- WATCHTOWER_HTTP_API_TOKEN=${PMM_WATCHTOWER_TOKEN:-123}
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
hostname: watchtower
networks:
- ${NETWORK:-default}
volumes:
- /var/run/docker.sock:${DOCKER_PATH:-/var/run/docker.sock}

# PMM with external DBs
ch:
profiles:
Expand Down
5 changes: 5 additions & 0 deletions managed/cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ func main() { //nolint:cyclop,maintidx
clickHouseDatabaseF := kingpin.Flag("clickhouse-name", "Clickhouse database name").Default("pmm").Envar("PERCONA_TEST_PMM_CLICKHOUSE_DATABASE").String()
clickhouseAddrF := kingpin.Flag("clickhouse-addr", "Clickhouse database address").Default("127.0.0.1:9000").Envar("PERCONA_TEST_PMM_CLICKHOUSE_ADDR").String()

watchtowerHostF := kingpin.Flag("watchtower-host", "Watchtower host").Default("http://watchtower:8080").Envar("PMM_WATCHTOWER_HOST").URL()

kingpin.Parse()

logger.SetupGlobalLogger()
Expand Down Expand Up @@ -969,6 +971,8 @@ func main() { //nolint:cyclop,maintidx

dumpService := dump.New(db)

updater := server.NewUpdater(supervisord, *watchtowerHostF)

serverParams := &server.Params{
DB: db,
VMDB: vmdb,
Expand All @@ -981,6 +985,7 @@ func main() { //nolint:cyclop,maintidx
AwsInstanceChecker: awsInstanceChecker,
GrafanaClient: grafanaClient,
VMAlertExternalRules: externalRules,
Updater: updater,
}

server, err := server.NewServer(serverParams)
Expand Down
36 changes: 10 additions & 26 deletions managed/services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Server struct {
awsInstanceChecker *AWSInstanceChecker
grafanaClient grafanaClient
haService haService
updater *Updater

l *logrus.Entry

Expand Down Expand Up @@ -91,6 +92,7 @@ type Params struct {
TelemetryService telemetryService
AwsInstanceChecker *AWSInstanceChecker
GrafanaClient grafanaClient
Updater *Updater
}

// NewServer returns new server for Server service.
Expand All @@ -113,6 +115,7 @@ func NewServer(params *Params) (*Server, error) {
telemetryService: params.TelemetryService,
awsInstanceChecker: params.AwsInstanceChecker,
grafanaClient: params.GrafanaClient,
updater: params.Updater,
l: logrus.WithField("component", "server"),
pmmUpdateAuthFile: path,
envSettings: &models.ChangeSettingsParams{},
Expand Down Expand Up @@ -232,42 +235,23 @@ func (s *Server) LeaderHealthCheck(ctx context.Context, req *serverpb.LeaderHeal
return nil, status.Error(codes.FailedPrecondition, "this PMM Server isn't the leader")
}

func (s *Server) onlyInstalledVersionResponse(ctx context.Context) *serverpb.CheckUpdatesResponse {
v := s.supervisord.InstalledPMMVersion(ctx)
r := &serverpb.CheckUpdatesResponse{
Installed: &serverpb.VersionInfo{
Version: v.Version,
FullVersion: v.FullVersion,
},
}

if v.BuildTime != nil {
t := v.BuildTime.UTC().Truncate(24 * time.Hour) // return only date
r.Installed.Timestamp = timestamppb.New(t)
}

r.LastCheck = timestamppb.New(time.Now())

return r
}

// CheckUpdates checks PMM Server updates availability.
func (s *Server) CheckUpdates(ctx context.Context, req *serverpb.CheckUpdatesRequest) (*serverpb.CheckUpdatesResponse, error) {
s.envRW.RLock()
updatesDisabled := s.envSettings.DisableUpdates
s.envRW.RUnlock()

if req.OnlyInstalledVersion {
return s.onlyInstalledVersionResponse(ctx), nil
return s.updater.onlyInstalledVersionResponse(), nil
}

if req.Force {
if err := s.supervisord.ForceCheckUpdates(ctx); err != nil {
if err := s.updater.ForceCheckUpdates(ctx); err != nil {
return nil, err
}
}

v, lastCheck := s.supervisord.LastCheckUpdatesResult(ctx)
v, lastCheck := s.updater.LastCheckUpdatesResult(ctx)
if v == nil {
return nil, status.Error(codes.Unavailable, "failed to check for updates")
}
Expand All @@ -281,7 +265,7 @@ func (s *Server) CheckUpdates(ctx context.Context, req *serverpb.CheckUpdatesReq
Version: v.Latest.Version,
FullVersion: v.Latest.FullVersion,
},
UpdateAvailable: v.UpdateAvailable,
UpdateAvailable: true,
LatestNewsUrl: v.LatestNewsURL,
}

Expand Down Expand Up @@ -314,19 +298,19 @@ func (s *Server) StartUpdate(ctx context.Context, req *serverpb.StartUpdateReque
return nil, status.Error(codes.FailedPrecondition, "Updates are disabled via DISABLE_UPDATES environment variable.")
}

offset, err := s.supervisord.StartUpdate()
err := s.updater.StartUpdate(ctx, req.GetNewImage())
if err != nil {
return nil, err
}

authToken := uuid.New().String()
if err = s.writeUpdateAuthToken(authToken); err != nil {
if err := s.writeUpdateAuthToken(authToken); err != nil {
return nil, err
}

return &serverpb.StartUpdateResponse{
AuthToken: authToken,
LogOffset: offset,
LogOffset: 0,
}, nil
}

Expand Down
Loading
Loading