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

K8SPSMDB-1174: Improve telemetry requests #1725

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ ENVTEST = $(shell pwd)/bin/setup-envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

SWAGGER = $(shell pwd)/bin/swagger
swagger: ## Download swagger locally if necessary.
$(call go-get-tool,$(SWAGGER),github.com/go-swagger/go-swagger/cmd/swagger@latest)

# Prepare release
CERT_MANAGER_VER := $(shell grep -Eo "cert-manager v.*" go.mod|grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
release: manifests
Expand Down Expand Up @@ -124,3 +128,13 @@ after-release: manifests
-e "/^ backup:/,/^ image:/{s#image: .*#image: perconalab/percona-server-mongodb-operator:main-backup#}" \
-e "s#initImage: .*#initImage: perconalab/percona-server-mongodb-operator:main#g" \
-e "/^ pmm:/,/^ image:/{s#image: .*#image: perconalab/pmm-client:dev-latest#}" deploy/cr.yaml

version-service-client: swagger
curl https://raw.githubusercontent.com/Percona-Lab/percona-version-service/$(VS_BRANCH)/api/version.swagger.yaml \
--output ./version.swagger.yaml
rm -rf ./versionserviceclient
swagger generate client \
-f ./version.swagger.yaml \
-c ./versionserviceclient/ \
-m ./versionserviceclient/models
rm ./version.swagger.yaml
31 changes: 21 additions & 10 deletions pkg/controller/perconaservermongodb/psmdb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,27 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
}

type CronRegistry struct {
crons *cron.Cron
jobs map[string]Schedule
backupJobs *sync.Map
crons *cron.Cron
ensureVersionJobs *sync.Map
backupJobs *sync.Map
}

type Schedule struct {
ID int
CronSchedule string
// AddFuncWithSeconds does the same as cron.AddFunc but changes the schedule so that the function will run the exact second that this method is called.
func (r *CronRegistry) AddFuncWithSeconds(spec string, cmd func()) (cron.EntryID, error) {
schedule, err := cron.ParseStandard(spec)
if err != nil {
return 0, errors.Wrap(err, "failed to parse cron schedule")
}
schedule.(*cron.SpecSchedule).Second = uint64(1 << time.Now().Second())
id := r.crons.Schedule(schedule, cron.FuncJob(cmd))
return id, nil
}

func NewCronRegistry() CronRegistry {
c := CronRegistry{
crons: cron.New(),
jobs: make(map[string]Schedule),
backupJobs: new(sync.Map),
crons: cron.New(),
ensureVersionJobs: new(sync.Map),
backupJobs: new(sync.Map),
}

c.crons.Start()
Expand Down Expand Up @@ -455,7 +461,12 @@ func (r *ReconcilePerconaServerMongoDB) Reconcile(ctx context.Context, request r

err = r.scheduleEnsureVersion(ctx, cr, VersionServiceClient{})
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to ensure version")
return reconcile.Result{}, errors.Wrap(err, "schedule ensure version job")
}

err = r.scheduleTelemetryRequests(ctx, cr, VersionServiceClient{})
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "schedule telemetry job")
}

if err = r.updatePITR(ctx, cr); err != nil {
Expand Down
Loading
Loading