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-12762 Get notified about new version. #2951

Merged
merged 42 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9da3fd8
PMM-11261 Update PMM via watchtower
BupycHuk Feb 16, 2024
185ee21
PMM-11261 address comments and fix linter
BupycHuk Mar 8, 2024
cbfa33a
Merge branch 'v3' into PMM-11261-update-via-watchtower
BupycHuk Mar 8, 2024
dd60f3b
PMM-11261 fix linters and tests.
BupycHuk Mar 8, 2024
5cd04a0
PMM-11261 fix linters and tests.
BupycHuk Mar 8, 2024
036dffb
PMM-11261 fix linters.
BupycHuk Mar 13, 2024
ed7bcfe
PMM-11261 fix linters.
BupycHuk Mar 13, 2024
7179b9f
Merge branch 'v3' into PMM-11261-update-via-watchtower
BupycHuk Mar 13, 2024
7111d84
Update managed/cmd/pmm-managed/main.go
BupycHuk Mar 19, 2024
8178764
Update managed/cmd/pmm-managed/main.go
BupycHuk Mar 19, 2024
d66bea8
PMM-11261 Address comments.
BupycHuk Mar 19, 2024
1c3600a
PMM-11261 fix build.
BupycHuk Mar 19, 2024
4d62067
Merge branch 'v3' into PMM-11261-update-via-watchtower
BupycHuk Mar 21, 2024
1967263
Update docker-compose.yml
BupycHuk Mar 27, 2024
671ee0e
Merge branch 'v3' into PMM-11261-update-via-watchtower
BupycHuk Mar 27, 2024
f78a642
Update docker-compose.yml
BupycHuk Apr 2, 2024
cc7bb6f
Update docker-compose.yml
BupycHuk Apr 2, 2024
7bd962b
PMM-12762 Get notified about new version.
BupycHuk Apr 3, 2024
4104986
PMM-11261 Replace switch with if-else
BupycHuk Apr 8, 2024
3374e10
Merge branch 'PMM-11261-update-via-watchtower' into PMM-12762-get-not…
BupycHuk Apr 8, 2024
018ded1
PMM-12762 Fix conflicts, tests and linters.
BupycHuk Apr 8, 2024
2e7228b
PMM-12762 Add license header.
BupycHuk Apr 8, 2024
42baca0
PMM-12762 Get notified about new version.
BupycHuk Apr 15, 2024
32e669d
PMM-12762 Fix deadlock
BupycHuk Apr 15, 2024
302441b
PMM-12762 Fix linters.
BupycHuk Apr 15, 2024
d49ce3f
PMM-12762 add more log info.
BupycHuk Apr 16, 2024
d9357f6
PMM-12762 add more log info.
BupycHuk Apr 16, 2024
b1f4d64
PMM-12762 add more log info.
BupycHuk Apr 16, 2024
fe9a6b9
PMM-12762 add more log info.
BupycHuk Apr 16, 2024
1adc8f5
PMM-12762 add more log info.
BupycHuk Apr 16, 2024
2255735
PMM-12762 add more log info.
BupycHuk Apr 16, 2024
0479c9f
PMM-12762 set PMM version.
BupycHuk Apr 16, 2024
7045e32
PMM-12762 set PMM version.
BupycHuk Apr 16, 2024
9d89d22
Update managed/services/server/updater.go
BupycHuk Apr 16, 2024
e0f768c
Merge branch 'PMM-11261-update-via-watchtower' into PMM-12762-get-not…
BupycHuk Apr 16, 2024
3c36ad6
Merge branch 'v3' into PMM-12762-get-notified-about-new-version
BupycHuk Apr 19, 2024
e07cc83
PMM-12762 fix merge conflicts.
BupycHuk Apr 19, 2024
6291737
Update .github/workflows/managed.yml
BupycHuk Apr 20, 2024
26b57d5
PMM-12762 sort env variables.
BupycHuk Apr 22, 2024
a2766fa
Merge branch 'v3' into PMM-12762-get-notified-about-new-version
idoqo Jun 17, 2024
c6323b7
Merge branch 'v3' into PMM-12762-get-notified-about-new-version
idoqo Jun 22, 2024
dac9a3f
PMM-13028 Non blocking StartUpgrade operation (#2972)
BupycHuk Jun 24, 2024
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:-INSECURE_TOKEN}
# - 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:-INSECURE_TOKEN}
hostname: watchtower
networks:
- ${NETWORK:-default}
volumes:
- /var/run/docker.sock:${DOCKER_PATH:-/var/run/docker.sock}

# PMM with external DBs
ch:
profiles:
Expand Down
19 changes: 10 additions & 9 deletions managed/cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const (

var pprofSemaphore = semaphore.NewWeighted(1)

func addLogsHandler(mux *http.ServeMux, logs *supervisord.Logs) {
func addLogsHandler(mux *http.ServeMux, logs *server.Logs) {
l := logrus.WithField("component", "logs.zip")

mux.HandleFunc("/logs.zip", func(rw http.ResponseWriter, req *http.Request) {
Expand All @@ -147,7 +147,7 @@ func addLogsHandler(mux *http.ServeMux, logs *supervisord.Logs) {
if err != nil {
l.Debug("Unable to read 'pprof' query param. Using default: pprof=false")
}
var pprofConfig *supervisord.PprofConfig
var pprofConfig *server.PprofConfig
if pprofQueryParameter {
if !pprofSemaphore.TryAcquire(1) {
rw.WriteHeader(http.StatusLocked)
Expand All @@ -160,7 +160,7 @@ func addLogsHandler(mux *http.ServeMux, logs *supervisord.Logs) {
defer pprofSemaphore.Release(1)

contextTimeout += pProfProfileDuration + pProfTraceDuration
pprofConfig = &supervisord.PprofConfig{
pprofConfig = &server.PprofConfig{
ProfileDuration: pProfProfileDuration,
TraceDuration: pProfTraceDuration,
}
Expand Down Expand Up @@ -334,7 +334,7 @@ func runGRPCServer(ctx context.Context, deps *gRPCServerDeps) {
}

type http1ServerDeps struct {
logs *supervisord.Logs
logs *server.Logs
authServer *grafana.AuthServer
}

Expand Down 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 @@ -873,13 +875,12 @@ func main() { //nolint:cyclop,maintidx
connectionCheck := agents.NewConnectionChecker(agentsRegistry)
serviceInfoBroker := agents.NewServiceInfoBroker(agentsRegistry)

pmmUpdateCheck := supervisord.NewPMMUpdateChecker(logrus.WithField("component", "supervisord/pmm-update-checker"))
updater := server.NewUpdater(*watchtowerHostF, gRPCMessageMaxSize)

logs := supervisord.NewLogs(version.FullInfo(), pmmUpdateCheck, vmParams)
logs := server.NewLogs(version.FullInfo(), updater, vmParams)

supervisord := supervisord.New(
*supervisordConfigDirF,
pmmUpdateCheck,
&models.Params{
VMParams: vmParams,
PGParams: &models.PGParams{
Expand All @@ -893,8 +894,7 @@ func main() { //nolint:cyclop,maintidx
SSLCertPath: *postgresSSLCertPathF,
},
HAParams: haParams,
},
gRPCMessageMaxSize)
})

haService.AddLeaderService(ha.NewStandardService("pmm-agent-runner", func(ctx context.Context) error {
return supervisord.StartSupervisedService("pmm-agent")
Expand Down Expand Up @@ -981,6 +981,7 @@ func main() { //nolint:cyclop,maintidx
AwsInstanceChecker: awsInstanceChecker,
GrafanaClient: grafanaClient,
VMAlertExternalRules: externalRules,
Updater: updater,
}

server, err := server.NewServer(serverParams)
Expand Down
23 changes: 15 additions & 8 deletions managed/services/server/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package server

import (
"context"
"net/url"
"time"

"github.com/percona/pmm/api/serverpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/version"
)

// healthChecker interface wraps all services that implements the IsReady method to report the
Expand Down Expand Up @@ -73,13 +73,13 @@ type vmAlertExternalRules interface {
// supervisordService is a subset of methods of supervisord.Service used by this package.
// We use it instead of real type for testing and to avoid dependency cycle.
type supervisordService interface {
InstalledPMMVersion(ctx context.Context) *version.PackageInfo
LastCheckUpdatesResult(ctx context.Context) (*version.UpdateCheckResult, time.Time)
ForceCheckUpdates(ctx context.Context) error

StartUpdate() (uint32, error)
UpdateRunning() bool
UpdateLog(offset uint32) ([]string, uint32, error)
//InstalledPMMVersion(ctx context.Context) *version.PackageInfo
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
//LastCheckUpdatesResult(ctx context.Context) (*version.UpdateCheckResult, time.Time)
//ForceCheckUpdates(ctx context.Context) error
//
//StartUpdate() (uint32, error)
//UpdateRunning() bool
//UpdateLog(offset uint32) ([]string, uint32, error)

UpdateConfiguration(settings *models.Settings, ssoDetails *models.PerconaSSODetails) error
}
Expand Down Expand Up @@ -108,3 +108,10 @@ type templatesService interface {
type haService interface {
IsLeader() bool
}

// victoriaMetricsParams is a subset of methods of models.VMParams used by this package.
// We use it instead of real type to avoid dependency cycle.
type victoriaMetricsParams interface {
ExternalVM() bool
URLFor(path string) (*url.URL, error)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package supervisord
package server

import (
"archive/zip"
Expand Down Expand Up @@ -56,12 +56,12 @@ type fileContent struct {
// Logs is responsible for interactions with logs.
type Logs struct {
pmmVersion string
pmmUpdateChecker *PMMUpdateChecker
pmmUpdateChecker *Updater
vmParams victoriaMetricsParams
}

// NewLogs creates a new Logs service.
func NewLogs(pmmVersion string, pmmUpdateChecker *PMMUpdateChecker, vmParams victoriaMetricsParams) *Logs {
func NewLogs(pmmVersion string, pmmUpdateChecker *Updater, vmParams victoriaMetricsParams) *Logs {
return &Logs{
pmmVersion: pmmVersion,
pmmUpdateChecker: pmmUpdateChecker,
Expand Down Expand Up @@ -204,7 +204,7 @@ func (l *Logs) files(ctx context.Context, pprofConfig *PprofConfig) []fileConten
})

// update checker installed info
b, err = json.Marshal(l.pmmUpdateChecker.Installed(ctx))
b, err = json.Marshal(l.pmmUpdateChecker.InstalledPMMVersion())
files = append(files, fileContent{
Name: "installed.json",
Data: b,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package supervisord
package server

import (
"archive/zip"
Expand All @@ -27,7 +27,6 @@ import (
"testing"
"time"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -143,10 +142,10 @@ func TestAddAdminSummary(t *testing.T) {
}

func TestFiles(t *testing.T) {
checker := NewPMMUpdateChecker(logrus.WithField("test", t.Name()))
updater := &Updater{}
params, err := models.NewVictoriaMetricsParams(models.BasePrometheusConfigPath, models.VMBaseURL)
require.NoError(t, err)
l := NewLogs("2.4.5", checker, params)
l := NewLogs("2.4.5", updater, params)
ctx := logger.Set(context.Background(), t.Name())

files := l.files(ctx, nil)
Expand Down Expand Up @@ -184,10 +183,10 @@ func TestFiles(t *testing.T) {
func TestZip(t *testing.T) {
t.Skip("FIXME")

checker := NewPMMUpdateChecker(logrus.WithField("test", t.Name()))
updater := &Updater{}
params, err := models.NewVictoriaMetricsParams(models.BasePrometheusConfigPath, models.VMBaseURL)
require.NoError(t, err)
l := NewLogs("2.4.5", checker, params)
l := NewLogs("2.4.5", updater, params)
ctx := logger.Set(context.Background(), t.Name())

var buf bytes.Buffer
Expand Down
Loading
Loading