-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
create_jobs_metrics_polling_job.go
61 lines (56 loc) · 1.95 KB
/
create_jobs_metrics_polling_job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package upgrades
import (
"context"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/jobs"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/sql/isql"
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
"github.com/cockroachdb/cockroach/pkg/upgrade"
)
func createJobsMetricsPollingJob(
ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps,
) error {
if d.TestingKnobs != nil && d.TestingKnobs.SkipJobMetricsPollingJobBootstrap {
return nil
}
return d.DB.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
row, err := d.DB.Executor().QueryRowEx(
ctx,
"check for existing job metrics polling job",
nil,
sessiondata.InternalExecutorOverride{User: username.RootUserName()},
"SELECT * FROM system.jobs WHERE id = $1",
jobs.JobMetricsPollerJobID,
)
if err != nil {
return err
}
// If there isn't a row for the key visualizer job, create the job.
if row == nil {
jr := jobs.Record{
JobID: jobs.JobMetricsPollerJobID,
Description: jobspb.TypePollJobsStats.String(),
Details: jobspb.PollJobsStatsDetails{},
Progress: jobspb.PollJobsStatsProgress{},
CreatedBy: &jobs.CreatedByInfo{Name: username.RootUser, ID: username.RootUserID},
Username: username.RootUserName(),
NonCancelable: true,
}
if _, err := d.JobRegistry.CreateAdoptableJobWithTxn(ctx, jr, jobs.JobMetricsPollerJobID, txn); err != nil {
return err
}
}
return nil
})
}