Skip to content

Commit e88ab54

Browse files
authored
Use backup/restore invoker information as prometheus job name (#1248)
Signed-off-by: Emruz Hossain <emruz@appscode.com>
1 parent d0a4751 commit e88ab54

File tree

10 files changed

+23
-17
lines changed

10 files changed

+23
-17
lines changed

pkg/cmds/create_volumesnapshot.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func NewCmdCreateVolumeSnapshot() *cobra.Command {
7373
namespace: meta.Namespace(),
7474
metrics: restic.MetricsOptions{
7575
Enabled: true,
76-
JobName: "stash-volumesnapshotter",
7776
},
7877
}
7978
)
@@ -104,6 +103,8 @@ func NewCmdCreateVolumeSnapshot() *cobra.Command {
104103
return err
105104
}
106105

106+
opt.metrics.JobName = fmt.Sprintf("%s-%s-%s", strings.ToLower(inv.TypeMeta.Kind), inv.ObjectMeta.Namespace, inv.ObjectMeta.Name)
107+
107108
for _, targetInfo := range inv.TargetsInfo {
108109
if targetInfo.Target != nil && targetMatched(targetInfo.Target.Ref, opt.targetKind, opt.targetName) {
109110
backupOutput, err := opt.createVolumeSnapshot(backupSession.ObjectMeta, inv, targetInfo)

pkg/cmds/restore.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package cmds
1818

1919
import (
20+
"fmt"
21+
"strings"
2022
"time"
2123

2224
v1beta1_api "stash.appscode.dev/apimachinery/apis/stash/v1beta1"
@@ -61,7 +63,7 @@ func NewCmdRestore() *cobra.Command {
6163
opt.Config = config
6264
opt.KubeClient = kubernetes.NewForConfigOrDie(config)
6365
opt.StashClient = cs.NewForConfigOrDie(config)
64-
opt.Metrics.JobName = opt.InvokerName
66+
opt.Metrics.JobName = fmt.Sprintf("%s-%s-%s", strings.ToLower(opt.InvokerKind), opt.Namespace, opt.InvokerName)
6567

6668
inv, err := invoker.ExtractRestoreInvokerInfo(opt.KubeClient, opt.StashClient, opt.InvokerKind, opt.InvokerName, opt.Namespace)
6769
if err != nil {

pkg/cmds/restore_volumesnapshot.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"os"
23+
"strings"
2324
"time"
2425

2526
"stash.appscode.dev/apimachinery/apis"
@@ -53,7 +54,6 @@ func NewCmdRestoreVolumeSnapshot() *cobra.Command {
5354
namespace: meta.Namespace(),
5455
metrics: restic.MetricsOptions{
5556
Enabled: true,
56-
JobName: "stash-volumesnapshot-restorer",
5757
},
5858
}
5959
)
@@ -77,6 +77,8 @@ func NewCmdRestoreVolumeSnapshot() *cobra.Command {
7777
return err
7878
}
7979

80+
opt.metrics.JobName = fmt.Sprintf("%s-%s-%s", strings.ToLower(inv.TypeMeta.Kind), inv.ObjectMeta.Namespace, inv.ObjectMeta.Name)
81+
8082
for _, targetInfo := range inv.TargetsInfo {
8183
if targetInfo.Target != nil && targetMatched(targetInfo.Target.Ref, opt.targetKind, opt.targetName) {
8284
restoreOutput, err := opt.restoreVolumeSnapshot(inv, targetInfo)

pkg/cmds/run_backup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package cmds
1818

1919
import (
20+
"fmt"
21+
"strings"
2022
"time"
2123

2224
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
@@ -70,7 +72,7 @@ func NewCmdRunBackup() *cobra.Command {
7072
stashinformers.WithTweakListOptions(nil),
7173
)
7274
opt.Recorder = eventer.NewEventRecorder(opt.K8sClient, backup.BackupEventComponent)
73-
opt.Metrics.JobName = opt.InvokerName
75+
opt.Metrics.JobName = fmt.Sprintf("%s-%s-%s", strings.ToLower(opt.InvokerKind), opt.Namespace, opt.InvokerName)
7476

7577
inv, err := invoker.ExtractBackupInvokerInfo(opt.StashClient, opt.InvokerKind, opt.InvokerName, opt.Namespace)
7678
if err != nil {

pkg/cmds/run_hook.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"path/filepath"
24+
"strings"
2425

2526
"stash.appscode.dev/apimachinery/apis"
2627
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
@@ -83,6 +84,7 @@ func NewCmdRunHook() *cobra.Command {
8384
opt.kubeClient = kubernetes.NewForConfigOrDie(config)
8485
opt.stashClient = cs.NewForConfigOrDie(config)
8586
opt.appClient = appcatalog_cs.NewForConfigOrDie(config)
87+
opt.metricOpts.JobName = fmt.Sprintf("%s-%s-%s", strings.ToLower(opt.invokerKind), opt.namespace, opt.invokerName)
8688

8789
err = opt.executeHook()
8890
if err != nil {
@@ -111,7 +113,6 @@ func NewCmdRunHook() *cobra.Command {
111113
cmd.Flags().BoolVar(&opt.metricOpts.Enabled, "metrics-enabled", opt.metricOpts.Enabled, "Specify whether to export Prometheus metrics")
112114
cmd.Flags().StringVar(&opt.metricOpts.PushgatewayURL, "metrics-pushgateway-url", opt.metricOpts.PushgatewayURL, "Pushgateway URL where the metrics will be pushed")
113115
cmd.Flags().StringSliceVar(&opt.metricOpts.Labels, "metrics-labels", opt.metricOpts.Labels, "Labels to apply in exported metrics")
114-
cmd.Flags().StringVar(&opt.metricOpts.JobName, "prom-job-name", StashDefaultMetricJob, "Metrics job name")
115116
cmd.Flags().StringVar(&opt.outputDir, "output-dir", opt.outputDir, "Directory where output.json file will be written (keep empty if you don't need to write output in file)")
116117
return cmd
117118
}

pkg/cmds/update_status.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ limitations under the License.
1717
package cmds
1818

1919
import (
20+
"fmt"
21+
"strings"
22+
2023
cs "stash.appscode.dev/apimachinery/client/clientset/versioned"
2124
"stash.appscode.dev/apimachinery/pkg/restic"
2225
"stash.appscode.dev/stash/pkg/status"
@@ -27,10 +30,6 @@ import (
2730
"k8s.io/client-go/tools/clientcmd"
2831
)
2932

30-
const (
31-
StashDefaultMetricJob = "stash-prom-metrics"
32-
)
33-
3433
func NewCmdUpdateStatus() *cobra.Command {
3534
var (
3635
masterURL string
@@ -61,6 +60,8 @@ func NewCmdUpdateStatus() *cobra.Command {
6160
}
6261

6362
opt.Config = config
63+
opt.Metrics.JobName = fmt.Sprintf("%s-%s-%s", strings.ToLower(opt.InvokerKind), opt.Namespace, opt.InvokerName)
64+
6465
if opt.BackupSession != "" {
6566
return opt.UpdateBackupStatusFromFile()
6667
} else {
@@ -93,7 +94,6 @@ func NewCmdUpdateStatus() *cobra.Command {
9394
cmd.Flags().BoolVar(&opt.Metrics.Enabled, "metrics-enabled", opt.Metrics.Enabled, "Specify whether to export Prometheus metrics")
9495
cmd.Flags().StringVar(&opt.Metrics.PushgatewayURL, "metrics-pushgateway-url", opt.Metrics.PushgatewayURL, "Pushgateway URL where the metrics will be pushed")
9596
cmd.Flags().StringSliceVar(&opt.Metrics.Labels, "metrics-labels", opt.Metrics.Labels, "Labels to apply in exported metrics")
96-
cmd.Flags().StringVar(&opt.Metrics.JobName, "prom-job-name", StashDefaultMetricJob, "Metrics job name")
9797

9898
return cmd
9999
}

pkg/controller/backup_session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ func (c *StashController) setBackupSessionSucceeded(inv invoker.BackupInvoker, b
639639
metricsOpt := &restic.MetricsOptions{
640640
Enabled: true,
641641
PushgatewayURL: apis.PushgatewayLocalURL,
642-
JobName: apis.PromJobStashBackup,
642+
JobName: fmt.Sprintf("%s-%s-%s", strings.ToLower(inv.TypeMeta.Kind), inv.ObjectMeta.Namespace, inv.ObjectMeta.Name),
643643
}
644644

645645
// send backup session related metrics
@@ -691,7 +691,7 @@ func (c *StashController) setBackupSessionFailed(inv invoker.BackupInvoker, back
691691
metricsOpt := &restic.MetricsOptions{
692692
Enabled: true,
693693
PushgatewayURL: apis.PushgatewayLocalURL,
694-
JobName: apis.PromJobStashBackup,
694+
JobName: fmt.Sprintf("%s-%s-%s", strings.ToLower(inv.TypeMeta.Kind), inv.ObjectMeta.Namespace, inv.ObjectMeta.Name),
695695
}
696696

697697
// send backup session related metrics

pkg/controller/restore_session.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ func (c *StashController) setRestorePhaseSucceeded(inv invoker.RestoreInvoker) e
870870
metricsOpt := &restic.MetricsOptions{
871871
Enabled: true,
872872
PushgatewayURL: apis.PushgatewayLocalURL,
873-
JobName: apis.PromJobStashRestore,
873+
JobName: fmt.Sprintf("%s-%s-%s", strings.ToLower(inv.TypeMeta.Kind), inv.ObjectMeta.Namespace, inv.ObjectMeta.Name),
874874
}
875875
// send target specific metrics
876876
for _, target := range inv.Status.TargetStatus {
@@ -918,7 +918,7 @@ func (c *StashController) setRestorePhaseFailed(inv invoker.RestoreInvoker, rest
918918
metricsOpt := &restic.MetricsOptions{
919919
Enabled: true,
920920
PushgatewayURL: apis.PushgatewayLocalURL,
921-
JobName: apis.PromJobStashRestore,
921+
JobName: fmt.Sprintf("%s-%s-%s", strings.ToLower(inv.TypeMeta.Kind), inv.ObjectMeta.Namespace, inv.ObjectMeta.Name),
922922
}
923923
// send target specific metrics
924924
for _, target := range inv.Status.TargetStatus {
@@ -967,7 +967,7 @@ func (c *StashController) setRestorePhaseUnknown(inv invoker.RestoreInvoker, res
967967
metricsOpt := &restic.MetricsOptions{
968968
Enabled: true,
969969
PushgatewayURL: apis.PushgatewayLocalURL,
970-
JobName: apis.PromJobStashRestore,
970+
JobName: fmt.Sprintf("%s-%s-%s", strings.ToLower(inv.TypeMeta.Kind), inv.ObjectMeta.Namespace, inv.ObjectMeta.Name),
971971
}
972972
// send target specific metrics
973973
for _, target := range inv.Status.TargetStatus {

pkg/util/crds.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ func updateStatusFunction(image docker.Docker) *api_v1beta1.Function {
120120
"--output-dir=${outputDir:=}",
121121
"--metrics-enabled=true",
122122
fmt.Sprintf("--metrics-pushgateway-url=%s", pushgateway.URL()),
123-
"--prom-job-name=${PROMETHEUS_JOB_NAME:=}",
124123
},
125124
VolumeMounts: []core.VolumeMount{
126125
{

pkg/util/util.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ func HookExecutorContainer(name string, shiblings []core.Container, invokerKind,
486486
"--output-dir=${outputDir:=}",
487487
"--metrics-enabled=true",
488488
fmt.Sprintf("--metrics-pushgateway-url=%s", pushgateway.URL()),
489-
"--prom-job-name=${PROMETHEUS_JOB_NAME:=}",
490489
},
491490
Env: []core.EnvVar{
492491
{

0 commit comments

Comments
 (0)