Skip to content

Commit 4cee079

Browse files
wujinhuGiedriusS
authored andcommitted
objstore : implement Aliyun OSS (#1573)
* add oss support Signed-off-by: wujinhu <wujinhu920@126.com> * fix docs Signed-off-by: wujinhu <wujinhu920@126.com> * fix Makefile Signed-off-by: wujinhu <wujinhu920@126.com> * review comments Signed-off-by: wujinhu <wujinhu920@126.com> * fix style Signed-off-by: wujinhu <wujinhu920@126.com> * review comments Signed-off-by: wujinhu <wujinhu920@126.com> * review comments Signed-off-by: wujinhu <wujinhu920@126.com> * review comments Signed-off-by: wujinhu <wujinhu920@126.com> * review comments Signed-off-by: wujinhu <wujinhu920@126.com> Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
1 parent 8ab9e78 commit 4cee079

File tree

10 files changed

+406
-13
lines changed

10 files changed

+406
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel
1414
### Added
1515

1616
- [#1660](https://github.com/thanos-io/thanos/pull/1660) Add a new `--prometheus.ready_timeout` CLI option to the sidecar to set how long to wait until Prometheus starts up.
17+
- [#1573](https://github.com/thanos-io/thanos/pull/1573) `AliYun OSS` object storage, see [documents](docs/storage.md#aliyun-oss-configuration) for further information.
1718

1819
### Fixed
1920

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ $ git push origin <your_branch_for_new_pr>
5757
- THANOS_SKIP_AZURE_TESTS to skip Azure tests.
5858
- THANOS_SKIP_SWIFT_TESTS to skip SWIFT tests.
5959
- THANOS_SKIP_TENCENT_COS_TESTS to skip Tencent COS tests.
60+
- THANOS_SKIP_ALIYUN_OSS_TESTS to skip Aliyun OSS tests.
6061

6162
If you skip all of these, the store specific tests will be run against memory object storage only.
6263
CI runs GCS and inmem tests only for now. Not having these variables will produce auth errors against GCS, AWS, Azure or COS tests.

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ docs: $(EMBEDMD) build
160160
.PHONY: check-docs
161161
check-docs: $(EMBEDMD) $(LICHE) build
162162
@EMBEDMD_BIN="$(EMBEDMD)" scripts/genflagdocs.sh check
163-
@$(LICHE) --recursive docs --exclude "cloud.tencent.com" --document-root .
164-
@$(LICHE) --exclude "cloud.tencent.com|goreportcard.com" --document-root . *.md
163+
@$(LICHE) --recursive docs --exclude "(cloud.tencent.com|alibabacloud.com)" --document-root .
164+
@$(LICHE) --exclude "(cloud.tencent.com|goreportcard.com|alibabacloud.com)" --document-root . *.md
165165

166166
# checks Go code comments if they have trailing period (excludes protobuffers and vendor files).
167167
# Comments with more than 3 spaces at beginning are omitted from the check, example: '// - foo'.
@@ -203,17 +203,19 @@ test: check-git install-deps
203203
@go install github.com/thanos-io/thanos/cmd/thanos
204204
# Be careful on GOCACHE. Those tests are sometimes using built Thanos/Prometheus binaries directly. Don't cache those.
205205
@rm -rf ${GOCACHE}
206-
@echo ">> running all tests. Do export THANOS_SKIP_GCS_TESTS='true' or/and THANOS_SKIP_S3_AWS_TESTS='true' or/and THANOS_SKIP_AZURE_TESTS='true' and/or THANOS_SKIP_SWIFT_TESTS='true' and/or THANOS_SKIP_TENCENT_COS_TESTS='true' if you want to skip e2e tests against real store buckets"
206+
@echo ">> running all tests. Do export THANOS_SKIP_GCS_TESTS='true' or/and THANOS_SKIP_S3_AWS_TESTS='true' or/and THANOS_SKIP_AZURE_TESTS='true' and/or THANOS_SKIP_SWIFT_TESTS='true' and/or THANOS_SKIP_ALIYUN_OSS_TESTS='true' and/or THANOS_SKIP_TENCENT_COS_TESTS='true' if you want to skip e2e tests against real store buckets"
207207
@go test $(shell go list ./... | grep -v /vendor/);
208208

209209
.PHONY: test-ci
210210
test-ci: export THANOS_SKIP_AZURE_TESTS = true
211211
test-ci: export THANOS_SKIP_SWIFT_TESTS = true
212212
test-ci: export THANOS_SKIP_TENCENT_COS_TESTS = true
213+
test-ci: export THANOS_SKIP_ALIYUN_OSS_TESTS = true
213214
test-ci:
214215
@echo ">> Skipping AZURE tests"
215216
@echo ">> Skipping SWIFT tests"
216217
@echo ">> Skipping TENCENT tests"
218+
@echo ">> Skipping ALIYUN tests"
217219
$(MAKE) test
218220

219221
.PHONY: test-local

docs/storage.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Current object storage client implementations:
6060
| [Azure Storage Account](./storage.md#azure) | Stable (production usage) | yes | @vglafirov |
6161
| [OpenStack Swift](./storage.md#openstack-swift) | Beta (working PoCs, testing usage) | no | @sudhi-vm |
6262
| [Tencent COS](./storage.md#tencent-cos) | Beta (testing usage) | no | @jojohappy |
63+
| [AliYun OSS](./storage.md#aliyun-oss) | Beta (testing usage) | no | @shaulboozhiao,@wujinhu |
6364

6465
NOTE: Currently Thanos requires strong consistency (write-read) for object store implementation.
6566

@@ -336,3 +337,20 @@ config:
336337
```
337338

338339
Set the flags `--objstore.config-file` to reference to the configuration file.
340+
341+
## AliYun OSS Configuration
342+
In order to use AliYun OSS object storage, you should first create a bucket with proper Storage Class , ACLs and get the access key on the AliYun cloud. Go to [https://www.alibabacloud.com/product/oss](https://www.alibabacloud.com/product/oss) for more detail.
343+
344+
To use AliYun OSS object storage, please specify following yaml configuration file in `objstore.config*` flag.
345+
346+
[embedmd]:# (flags/config_bucket_aliyunoss.txt $)
347+
```$
348+
type: ALIYUNOSS
349+
config:
350+
endpoint: ""
351+
bucket: ""
352+
access_key_id: ""
353+
access_key_secret: ""
354+
```
355+
356+
Use --objstore.config-file to reference to this configuration file.

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ require (
44
cloud.google.com/go v0.44.1
55
github.com/Azure/azure-storage-blob-go v0.7.0
66
github.com/NYTimes/gziphandler v1.1.1
7+
github.com/aliyun/aliyun-oss-go-sdk v2.0.1+incompatible
78
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878
9+
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
810
github.com/cespare/xxhash v1.1.0
911
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
1012
github.com/dustin/go-humanize v1.0.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZq
3535
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
3636
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E=
3737
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
38+
github.com/aliyun/aliyun-oss-go-sdk v2.0.1+incompatible h1:/MzpJOMHn/uBtd1dkS7Q9PF2ZjT6xTQMXSvv1e6ydXc=
39+
github.com/aliyun/aliyun-oss-go-sdk v2.0.1+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
3840
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
3941
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I=
4042
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
@@ -47,6 +49,8 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:l
4749
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
4850
github.com/aws/aws-sdk-go v1.23.12 h1:2UnxgNO6Y5J1OrkXS8XNp0UatDxD1bWHiDT62RDPggI=
4951
github.com/aws/aws-sdk-go v1.23.12/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
52+
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
53+
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
5054
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
5155
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
5256
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=

pkg/objstore/client/factory.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/thanos-io/thanos/pkg/objstore/azure"
1414
"github.com/thanos-io/thanos/pkg/objstore/cos"
1515
"github.com/thanos-io/thanos/pkg/objstore/gcs"
16+
"github.com/thanos-io/thanos/pkg/objstore/oss"
1617
"github.com/thanos-io/thanos/pkg/objstore/s3"
1718
"github.com/thanos-io/thanos/pkg/objstore/swift"
1819
yaml "gopkg.in/yaml.v2"
@@ -21,11 +22,12 @@ import (
2122
type ObjProvider string
2223

2324
const (
24-
GCS ObjProvider = "GCS"
25-
S3 ObjProvider = "S3"
26-
AZURE ObjProvider = "AZURE"
27-
SWIFT ObjProvider = "SWIFT"
28-
COS ObjProvider = "COS"
25+
GCS ObjProvider = "GCS"
26+
S3 ObjProvider = "S3"
27+
AZURE ObjProvider = "AZURE"
28+
SWIFT ObjProvider = "SWIFT"
29+
COS ObjProvider = "COS"
30+
ALIYUNOSS ObjProvider = "ALIYUNOSS"
2931
)
3032

3133
type BucketConfig struct {
@@ -59,6 +61,8 @@ func NewBucket(logger log.Logger, confContentYaml []byte, reg prometheus.Registe
5961
bucket, err = swift.NewContainer(logger, config)
6062
case string(COS):
6163
bucket, err = cos.NewBucket(logger, config, component)
64+
case string(ALIYUNOSS):
65+
bucket, err = oss.NewBucket(logger, config, component)
6266
default:
6367
return nil, errors.Errorf("bucket with type %s is not supported", bucketConf.Type)
6468
}

pkg/objstore/objtesting/foreach.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/thanos-io/thanos/pkg/objstore/cos"
1010
"github.com/thanos-io/thanos/pkg/objstore/gcs"
1111
"github.com/thanos-io/thanos/pkg/objstore/inmem"
12+
"github.com/thanos-io/thanos/pkg/objstore/oss"
1213
"github.com/thanos-io/thanos/pkg/objstore/s3"
1314
"github.com/thanos-io/thanos/pkg/objstore/swift"
1415
"github.com/thanos-io/thanos/pkg/testutil"
@@ -114,4 +115,21 @@ func ForeachStore(t *testing.T, testFn func(t testing.TB, bkt objstore.Bucket))
114115
} else {
115116
t.Log("THANOS_SKIP_TENCENT_COS_TESTS envvar present. Skipping test against Tencent COS.")
116117
}
118+
119+
// Optional OSS.
120+
if _, ok := os.LookupEnv("THANOS_SKIP_ALIYUN_OSS_TESTS"); !ok {
121+
bkt, closeFn, err := oss.NewTestBucket(t)
122+
testutil.Ok(t, err)
123+
124+
ok := t.Run("AliYun oss", func(t *testing.T) {
125+
testFn(t, bkt)
126+
})
127+
128+
closeFn()
129+
if !ok {
130+
return
131+
}
132+
} else {
133+
t.Log("THANOS_SKIP_ALIYUN_OSS_TESTS envvar present. Skipping test against AliYun OSS.")
134+
}
117135
}

0 commit comments

Comments
 (0)