Skip to content

Commit 41d2a53

Browse files
hossainemruztamalsaha
authored andcommitted
Remove metrics options from function (#5)
1 parent d276da0 commit 41d2a53

File tree

23 files changed

+378
-192
lines changed

23 files changed

+378
-192
lines changed

chart/stash-postgres/README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,11 @@ The following table lists the configurable parameters of the `stash-postgres` ch
6161
| `docker.tag` | Tag of the image that is used to backup/restore PostgreSQL database. This is usually same as the database version it can backup. | `11.2` |
6262
| `backup.pgArgs` | Optional arguments to pass to `pgdump` command during bakcup process | |
6363
| `restore.pgArgs` | Optional arguments to pass to `psql` command during restore process | |
64-
| `metrics.enabled` | Specifies whether to send Prometheus metrics | `true` |
65-
| `metrics.labels` | Optional comma separated labels to add to the Prometheus metrics | |
6664

6765
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.
6866

6967
For example:
7068

7169
```console
72-
helm install --name stash-postgres-11.2 --set metrics.enabled=false appscode/stash-postgres
73-
```
74-
75-
**Tips:** Use escape character (`\`) while providing multiple comma-separated labels for `metrics.labels`.
76-
77-
```console
78-
helm install chart/stash-postgres --set metrics.labels="k1=v1\,k2=v2"
70+
helm install --name stash-postgres-11.2 --set docker.registry=my-registry appscode/stash-postgres
7971
```

chart/stash-postgres/templates/postgres-backup-function.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ spec:
3535
- --retention-dry-run=${RETENTION_DRY_RUN:=false}
3636
# output & metric information
3737
- --output-dir=${outputDir:=}
38-
- --metrics-enabled={{ .Values.metrics.enabled }}
39-
- --metrics-pushgateway-url=${PROMETHEUS_PUSHGATEWAY_URL:=}
40-
{{- if .Values.metrics.labels }}
41-
- --metrics-labels={{ .Values.metrics.labels | quote }}
42-
{{- end }}
4338
volumeMounts:
4439
- name: ${secretVolume}
4540
mountPath: /etc/repository/secret

chart/stash-postgres/templates/postgres-restore-function.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ spec:
2727
- --snapshot=${RESTORE_SNAPSHOTS:=}
2828
# output & metric information
2929
- --output-dir=${outputDir:=}
30-
- --metrics-enabled={{ .Values.metrics.enabled }}
31-
- --metrics-pushgateway-url=${PROMETHEUS_PUSHGATEWAY_URL:=}
32-
{{- if .Values.metrics.labels }}
33-
- --metrics-labels={{ .Values.metrics.labels | quote }}
34-
{{- end }}
3530
volumeMounts:
3631
- name: ${secretVolume}
3732
mountPath: /etc/repository/secret

chart/stash-postgres/values.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,3 @@ backup:
1313
pgArgs: ""
1414
restore:
1515
pgArgs: ""
16-
17-
# default values for prometheus metrics
18-
metrics:
19-
enabled: true
20-
labels: []

docs/postgres.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ So, from the above output, we can see the table `company` that we had created in
683683
To cleanup the Kubernetes resources created by this tutorial, run:
684684

685685
```console
686+
kubectl delete backupconfiguration -n demo sample-postgres-backup
686687
kubectl delete restoresession -n demo sample-postgres-restore
687688
kubectl delete pg -n demo restored-postgres
688689
kubectl delete pg -n demo sample-postgres

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ require (
99
k8s.io/client-go v11.0.0+incompatible
1010
kmodules.xyz/client-go v0.0.0-20190808141354-bbb9e14f60ab
1111
kmodules.xyz/custom-resources v0.0.0-20190808144301-114abf10dfe2
12-
stash.appscode.dev/stash v0.9.0-rc.0
12+
stash.appscode.dev/stash v0.9.0-rc.0.0.20190826131715-3be27ba2689e
1313
)
1414

1515
replace (
1616
github.com/Azure/go-autorest => github.com/Azure/go-autorest v12.4.2+incompatible
1717
k8s.io/api => k8s.io/api v0.0.0-20190313235455-40a48860b5ab
1818
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190315093550-53c4693659ed
1919
k8s.io/apimachinery => github.com/kmodules/apimachinery v0.0.0-20190508045248-a52a97a7a2bf
20-
k8s.io/apiserver => github.com/kmodules/apiserver v0.0.0-20190508082252-8397d761d4b5
20+
k8s.io/apiserver => github.com/kmodules/apiserver v0.0.0-20190811223248-5a95b2df4348
2121
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20190314001948-2899ed30580f
2222
k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20190314002645-c892ea32361a
2323
k8s.io/component-base => k8s.io/component-base v0.0.0-20190314000054-4a91899592f4

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
177177
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
178178
github.com/kmodules/apimachinery v0.0.0-20190508045248-a52a97a7a2bf h1:XUigLZjjxvtR+TD7mncq0wUOaaG2H/zslqM42crk0SY=
179179
github.com/kmodules/apimachinery v0.0.0-20190508045248-a52a97a7a2bf/go.mod h1:1nbDY1cBTGna53FTjqnehJWker1BB75r+ElWRqNcYo8=
180-
github.com/kmodules/apiserver v0.0.0-20190508082252-8397d761d4b5/go.mod h1:rMEImsX8dFD0jGmDQXq3zbWddcIU8vlcrMWPzpXEm9g=
180+
github.com/kmodules/apiserver v0.0.0-20190811223248-5a95b2df4348/go.mod h1:rMEImsX8dFD0jGmDQXq3zbWddcIU8vlcrMWPzpXEm9g=
181181
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
182182
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
183183
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -431,8 +431,8 @@ kmodules.xyz/client-go v0.0.0-20190808141354-bbb9e14f60ab h1:rnKcFaDLtqpdooase2B
431431
kmodules.xyz/client-go v0.0.0-20190808141354-bbb9e14f60ab/go.mod h1:1GI6h5D31op/2D+Hrn9DhXW6iUd5wsHBQRoLeY7fndM=
432432
kmodules.xyz/custom-resources v0.0.0-20190808144301-114abf10dfe2 h1:u0zEFCvAttk09O64UzY1DVXNke9uAANmf4vllnVquS8=
433433
kmodules.xyz/custom-resources v0.0.0-20190808144301-114abf10dfe2/go.mod h1:vlKyFcCXC+2Kfn3Fa5Z7RnBWyp4t46FSeEutNqpqMm8=
434-
kmodules.xyz/objectstore-api v0.0.0-20190808153322-733e8798e8de h1:Z/z3SSS+mvRGzLT5HXLazogjnOYIfbYTYWrKBsiLtp8=
435-
kmodules.xyz/objectstore-api v0.0.0-20190808153322-733e8798e8de/go.mod h1:Wx+Ffc7weI6zv7NQvq0GWXMGGQFn6LqVb0KcXQFwRFs=
434+
kmodules.xyz/objectstore-api v0.0.0-20190824212210-196174aa0fc0 h1:ELq3ybK3noQP9SyZx34QsnZgU2As9r8hPAGEnuIy7Co=
435+
kmodules.xyz/objectstore-api v0.0.0-20190824212210-196174aa0fc0/go.mod h1:vFvmrMvRlkcUANfU4Ko3dZR3HUhWMUQc1sEHcwufims=
436436
kmodules.xyz/offshoot-api v0.0.0-20190808152534-e3dc715f844b h1:VZUtg4L9Qm2C7PBwa4sp/SvHckKidZSpkA33GoB24SA=
437437
kmodules.xyz/offshoot-api v0.0.0-20190808152534-e3dc715f844b/go.mod h1:AzvHBjJvhFwUEiWrEKfdsgoqt5Ulio44Beo1vPoq7ww=
438438
kmodules.xyz/openshift v0.0.0-20190808144841-c8f9a927f1d1 h1:NmVj5+kPpUgoxRans2XZt5SXm9cVy8E3b4yHaeVzqak=
@@ -444,5 +444,5 @@ sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5
444444
sigs.k8s.io/structured-merge-diff v0.0.0-20190302045857-e85c7b244fd2/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
445445
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
446446
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
447-
stash.appscode.dev/stash v0.9.0-rc.0 h1:GhzBnqHYBgq+2bcuwsDK3nhq2PPEhGkBH0EFAXp2OmY=
448-
stash.appscode.dev/stash v0.9.0-rc.0/go.mod h1:/YjAPx/9E4ScxWea1mbJC6qx9TomhqS83AUy2LufVVk=
447+
stash.appscode.dev/stash v0.9.0-rc.0.0.20190826131715-3be27ba2689e h1:AYVMg2yTN7lxe7IThGH0fc4iaBS4H8eBjCcu7w0OLmo=
448+
stash.appscode.dev/stash v0.9.0-rc.0.0.20190826131715-3be27ba2689e/go.mod h1:6WrRpjkI1av7305B60BLRx+PZzwMAoiGmOd5ewYAAyw=

pkg/backup.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/appscode/go/log"
1111
"github.com/spf13/cobra"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13-
"k8s.io/apimachinery/pkg/util/errors"
1413
"k8s.io/client-go/kubernetes"
1514
"k8s.io/client-go/tools/clientcmd"
1615
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
@@ -44,9 +43,6 @@ func NewCmdBackup() *cobra.Command {
4443
Host: restic.DefaultHost,
4544
StdinFileName: PgDumpFile,
4645
}
47-
metrics = restic.MetricsOptions{
48-
JobName: JobPGBackup,
49-
}
5046
)
5147

5248
cmd := &cobra.Command{
@@ -117,13 +113,7 @@ func NewCmdBackup() *cobra.Command {
117113

118114
// Run backup
119115
backupOutput, backupErr := resticWrapper.RunBackup(backupOpt)
120-
// If metrics are enabled then generate metrics
121-
if metrics.Enabled {
122-
err := backupOutput.HandleMetrics(&metrics, backupErr)
123-
if err != nil {
124-
return errors.NewAggregate([]error{backupErr, err})
125-
}
126-
}
116+
127117
// If output directory specified, then write the output in "output.json" file in the specified directory
128118
if backupErr == nil && outputDir != "" {
129119
err := backupOutput.WriteOutput(filepath.Join(outputDir, restic.DefaultOutputFileName))
@@ -166,11 +156,6 @@ func NewCmdBackup() *cobra.Command {
166156

167157
cmd.Flags().StringVar(&outputDir, "output-dir", outputDir, "Directory where output.json file will be written (keep empty if you don't need to write output in file)")
168158

169-
cmd.Flags().BoolVar(&metrics.Enabled, "metrics-enabled", metrics.Enabled, "Specify whether to export Prometheus metrics")
170-
cmd.Flags().StringVar(&metrics.PushgatewayURL, "metrics-pushgateway-url", metrics.PushgatewayURL, "Pushgateway URL where the metrics will be pushed")
171-
cmd.Flags().StringVar(&metrics.MetricFileDir, "metrics-dir", metrics.MetricFileDir, "Directory where to write metric.prom file (keep empty if you don't want to write metric in a text file)")
172-
cmd.Flags().StringSliceVar(&metrics.Labels, "metrics-labels", metrics.Labels, "Labels to apply in exported metrics")
173-
174159
return cmd
175160
}
176161

pkg/restore.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/appscode/go/flags"
77
"github.com/spf13/cobra"
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9-
"k8s.io/apimachinery/pkg/util/errors"
109
"k8s.io/client-go/kubernetes"
1110
"k8s.io/client-go/tools/clientcmd"
1211
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
@@ -30,9 +29,6 @@ func NewCmdRestore() *cobra.Command {
3029
Host: restic.DefaultHost,
3130
FileName: PgDumpFile,
3231
}
33-
metrics = restic.MetricsOptions{
34-
JobName: JobPGBackup,
35-
}
3632
)
3733

3834
cmd := &cobra.Command{
@@ -103,13 +99,7 @@ func NewCmdRestore() *cobra.Command {
10399

104100
// Run dump
105101
dumpOutput, backupErr := resticWrapper.Dump(dumpOpt)
106-
// If metrics are enabled then generate metrics
107-
if metrics.Enabled {
108-
err := dumpOutput.HandleMetrics(&metrics, backupErr)
109-
if err != nil {
110-
return errors.NewAggregate([]error{backupErr, err})
111-
}
112-
}
102+
113103
// If output directory specified, then write the output in "output.json" file in the specified directory
114104
if backupErr == nil && outputDir != "" {
115105
err := dumpOutput.WriteOutput(filepath.Join(outputDir, restic.DefaultOutputFileName))
@@ -144,11 +134,5 @@ func NewCmdRestore() *cobra.Command {
144134
cmd.Flags().StringVar(&dumpOpt.Snapshot, "snapshot", dumpOpt.Snapshot, "Snapshot to dump")
145135

146136
cmd.Flags().StringVar(&outputDir, "output-dir", outputDir, "Directory where output.json file will be written (keep empty if you don't need to write output in file)")
147-
148-
cmd.Flags().BoolVar(&metrics.Enabled, "metrics-enabled", metrics.Enabled, "Specify whether to export Prometheus metrics")
149-
cmd.Flags().StringVar(&metrics.PushgatewayURL, "metrics-pushgateway-url", metrics.PushgatewayURL, "Pushgateway URL where the metrics will be pushed")
150-
cmd.Flags().StringVar(&metrics.MetricFileDir, "metrics-dir", metrics.MetricFileDir, "Directory where to write metric.prom file (keep empty if you don't want to write metric in a text file)")
151-
cmd.Flags().StringSliceVar(&metrics.Labels, "metrics-labels", metrics.Labels, "Labels to apply in exported metrics")
152-
153137
return cmd
154138
}
Lines changed: 109 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,61 @@
11
package v1
22

33
import (
4+
"net/url"
5+
46
"github.com/pkg/errors"
57
core "k8s.io/api/core/v1"
68
)
79

8-
func (s Backend) Container() (string, error) {
9-
if s.S3 != nil {
10-
return s.S3.Bucket, nil
11-
} else if s.GCS != nil {
12-
return s.GCS.Bucket, nil
13-
} else if s.Azure != nil {
14-
return s.Azure.Container, nil
15-
} else if s.Local != nil {
16-
return s.Local.MountPath, nil
17-
} else if s.Swift != nil {
18-
return s.Swift.Container, nil
10+
const (
11+
ProviderLocal = "local"
12+
ProviderS3 = "s3"
13+
ProviderGCS = "gcs"
14+
ProviderAzure = "azure"
15+
ProviderSwift = "swift"
16+
ProviderB2 = "b2"
17+
ProviderRest = "rest"
18+
)
19+
20+
// Container returns name of the bucket
21+
func (backend Backend) Container() (string, error) {
22+
if backend.Local != nil {
23+
return backend.Local.MountPath, nil
24+
} else if backend.S3 != nil {
25+
return backend.S3.Bucket, nil
26+
} else if backend.GCS != nil {
27+
return backend.GCS.Bucket, nil
28+
} else if backend.Azure != nil {
29+
return backend.Azure.Container, nil
30+
} else if backend.Swift != nil {
31+
return backend.Swift.Container, nil
32+
} else if backend.Rest != nil {
33+
u, err := url.Parse(backend.Rest.URL)
34+
if err != nil {
35+
return "", err
36+
}
37+
return u.Host, nil
1938
}
20-
return "", errors.New("no storage provider is configured")
39+
return "", errors.New("failed to get container. Reason: Unknown backend type.")
2140
}
2241

23-
func (s Backend) Location() (string, error) {
24-
if s.S3 != nil {
25-
return "s3:" + s.S3.Bucket, nil
26-
} else if s.GCS != nil {
27-
return "gs:" + s.GCS.Bucket, nil
28-
} else if s.Azure != nil {
29-
return "azure:" + s.Azure.Container, nil
30-
} else if s.Local != nil {
31-
return "local:" + s.Local.MountPath, nil
32-
} else if s.Swift != nil {
33-
return "swift:" + s.Swift.Container, nil
42+
// Location returns the location of backend (<provider>:<bucket name>)
43+
func (backend Backend) Location() (string, error) {
44+
if backend.S3 != nil {
45+
return "s3:" + backend.S3.Bucket, nil
46+
} else if backend.GCS != nil {
47+
return "gs:" + backend.GCS.Bucket, nil
48+
} else if backend.Azure != nil {
49+
return "azure:" + backend.Azure.Container, nil
50+
} else if backend.Local != nil {
51+
return "local:" + backend.Local.MountPath, nil
52+
} else if backend.Swift != nil {
53+
return "swift:" + backend.Swift.Container, nil
3454
}
3555
return "", errors.New("no storage provider is configured")
3656
}
3757

58+
// ToVolumeAndMount returns volumes and mounts for local backend
3859
func (l LocalSpec) ToVolumeAndMount(volName string) (core.Volume, core.VolumeMount) {
3960
vol := core.Volume{
4061
Name: volName,
@@ -47,3 +68,68 @@ func (l LocalSpec) ToVolumeAndMount(volName string) (core.Volume, core.VolumeMou
4768
}
4869
return vol, mnt
4970
}
71+
72+
// Prefix returns the prefix used in the backend
73+
func (backend Backend) Prefix() (string, error) {
74+
if backend.Local != nil {
75+
return "", nil
76+
} else if backend.S3 != nil {
77+
return backend.S3.Prefix, nil
78+
} else if backend.GCS != nil {
79+
return backend.GCS.Prefix, nil
80+
} else if backend.Azure != nil {
81+
return backend.Azure.Prefix, nil
82+
} else if backend.Swift != nil {
83+
return backend.Swift.Prefix, nil
84+
} else if backend.Rest != nil {
85+
u, err := url.Parse(backend.Rest.URL)
86+
if err != nil {
87+
return "", err
88+
}
89+
return u.Path, nil
90+
}
91+
return "", errors.New("failed to get prefix. Reason: Unknown backend type.")
92+
}
93+
94+
// Provider returns the provider of the backend
95+
func (backend Backend) Provider() (string, error) {
96+
if backend.Local != nil {
97+
return ProviderLocal, nil
98+
} else if backend.S3 != nil {
99+
return ProviderS3, nil
100+
} else if backend.GCS != nil {
101+
return ProviderGCS, nil
102+
} else if backend.Azure != nil {
103+
return ProviderAzure, nil
104+
} else if backend.Swift != nil {
105+
return ProviderSwift, nil
106+
} else if backend.B2 != nil {
107+
return ProviderB2, nil
108+
} else if backend.Rest != nil {
109+
return ProviderRest, nil
110+
}
111+
return "", errors.New("unknown provider.")
112+
}
113+
114+
// MaxConnections returns maximum parallel connection to use to connect with the backend
115+
// returns 0 if not specified
116+
func (backend Backend) MaxConnections() int {
117+
if backend.GCS != nil {
118+
return backend.GCS.MaxConnections
119+
} else if backend.Azure != nil {
120+
return backend.Azure.MaxConnections
121+
} else if backend.B2 != nil {
122+
return backend.B2.MaxConnections
123+
}
124+
return 0
125+
}
126+
127+
// Endpoint returns endpoint of Restic rest server and S3/S3 compatible backend
128+
func (backend Backend) Endpoint() (string, bool) {
129+
if backend.S3 != nil {
130+
return backend.S3.Endpoint, true
131+
} else if backend.Rest != nil {
132+
return backend.Rest.URL, true
133+
}
134+
return "", false
135+
}

0 commit comments

Comments
 (0)