From 37962216ede4468c54744160536d9f8a109933ee Mon Sep 17 00:00:00 2001 From: William Date: Tue, 12 Sep 2017 05:56:43 -0400 Subject: [PATCH 1/5] get s3 url via aws-sdk-go, fix #9189 --- pkg/components/imguploader/s3uploader.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/components/imguploader/s3uploader.go b/pkg/components/imguploader/s3uploader.go index 302420a27f4..5122adfcc6d 100644 --- a/pkg/components/imguploader/s3uploader.go +++ b/pkg/components/imguploader/s3uploader.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds" "github.com/aws/aws-sdk-go/aws/ec2metadata" + "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/grafana/grafana/pkg/log" @@ -53,8 +54,10 @@ func (u *S3Uploader) Upload(imageDiskPath string) (string, error) { Credentials: creds, } + s3_endpoint, _ := endpoints.DefaultResolver().EndpointFor("s3", u.region) key := util.GetRandomString(20) + ".png" - log.Debug("Uploading image to s3", "bucket = ", u.bucket, ", key = ", key) + image_url := s3_endpoint.URL + "/" + u.bucket + "/" + key + log.Debug("Uploading image to s3", "url = ", image_url) file, err := os.Open(imageDiskPath) if err != nil { @@ -77,10 +80,5 @@ func (u *S3Uploader) Upload(imageDiskPath string) (string, error) { if err != nil { return "", err } - - if u.region == "us-east-1" { - return "https://" + u.bucket + ".s3.amazonaws.com/" + key, nil - } else { - return "https://" + u.bucket + ".s3-" + u.region + ".amazonaws.com/" + key, nil - } + return image_url, nil } From 88a89917222e12699470b1bdfc2ac4c80f605e60 Mon Sep 17 00:00:00 2001 From: William Date: Tue, 19 Sep 2017 04:17:22 -0400 Subject: [PATCH 2/5] config bucket and region for s3 uploader this is to support cn-north-1 region as it can get s3 url programatically. also keeps support 'bucket_url' for backward compatiblity --- conf/defaults.ini | 3 ++- conf/sample.ini | 3 ++- docs/sources/installation/configuration.md | 6 +++++- pkg/components/imguploader/imguploader.go | 14 ++++++++++---- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index f0156b70511..f46cfd28a8a 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -458,7 +458,8 @@ url = https://grafana.com provider = [external_image_storage.s3] -bucket_url = +bucket = +region = access_key = secret_key = diff --git a/conf/sample.ini b/conf/sample.ini index 80c7464f89c..8470d49109e 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -403,7 +403,8 @@ ;provider = [external_image_storage.s3] -;bucket_url = +;bucket = +;region = ;access_key = ;secret_key = diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index ae2541b4a7f..a4d080e212e 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -648,12 +648,16 @@ These options control how images should be made public so they can be shared on You can choose between (s3, webdav). If left empty Grafana will ignore the upload action. ## [external_image_storage.s3] +### bucket +Bucket name for S3. e.g. grafana.snapshot +### region +Region name for S3. e.g. 'us-east-1', 'cn-north-1', etc ### bucket_url +(for backward compatibility, only works when no bucket or region are configured) Bucket URL for S3. AWS region can be specified within URL or defaults to 'us-east-1', e.g. - http://grafana.s3.amazonaws.com/ - https://grafana.s3-ap-southeast-2.amazonaws.com/ -- https://grafana.s3-cn-north-1.amazonaws.com.cn ### access_key Access key. e.g. AAAAAAAAAAAAAAAAAAAA diff --git a/pkg/components/imguploader/imguploader.go b/pkg/components/imguploader/imguploader.go index 883ef8eefda..e00672121a0 100644 --- a/pkg/components/imguploader/imguploader.go +++ b/pkg/components/imguploader/imguploader.go @@ -27,15 +27,21 @@ func NewImageUploader() (ImageUploader, error) { return nil, err } + bucket := s3sec.Key("bucket").MustString("") + region := s3sec.Key("region").MustString("") bucketUrl := s3sec.Key("bucket_url").MustString("") accessKey := s3sec.Key("access_key").MustString("") secretKey := s3sec.Key("secret_key").MustString("") - info, err := getRegionAndBucketFromUrl(bucketUrl) - if err != nil { - return nil, err + if bucket == "" || region == "" { + info, err := getRegionAndBucketFromUrl(bucketUrl) + if err != nil { + return nil, err + } + bucket = info.bucket + region = info.region } - return NewS3Uploader(info.region, info.bucket, "public-read", accessKey, secretKey), nil + return NewS3Uploader(region, bucket, "public-read", accessKey, secretKey), nil case "webdav": webdavSec, err := setting.Cfg.GetSection("external_image_storage.webdav") if err != nil { From eaefa3c1fa29cf7110d95e08439f43557e788b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 27 Sep 2017 09:43:32 +0200 Subject: [PATCH 3/5] s3: minor fix for PR #9223 --- conf/defaults.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/defaults.ini b/conf/defaults.ini index cb841e57cf9..dfa6bf99017 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -476,6 +476,7 @@ sampler_param = 1 provider = [external_image_storage.s3] +bucket_url = bucket = region = access_key = From 0e5e2f3fb990293632402b20107aa09999c3f844 Mon Sep 17 00:00:00 2001 From: chrisrd Date: Wed, 27 Sep 2017 17:46:56 +1000 Subject: [PATCH 4/5] Fix export_modal message (#9353) Remove duplicate "to", and "others" is plural not possessive. --- public/app/features/dashboard/export/export_modal.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/dashboard/export/export_modal.html b/public/app/features/dashboard/export/export_modal.html index 01e47849439..0598c612fd6 100644 --- a/public/app/features/dashboard/export/export_modal.html +++ b/public/app/features/dashboard/export/export_modal.html @@ -11,7 +11,7 @@
From 5373a6027cbad584b90a5b469e040ccdde2841b8 Mon Sep 17 00:00:00 2001 From: bergquist Date: Wed, 27 Sep 2017 10:49:39 +0200 Subject: [PATCH 5/5] alertlist: toggle play/pause button closes #9355 --- .../alerting/partials/alert_list.html | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/public/app/features/alerting/partials/alert_list.html b/public/app/features/alerting/partials/alert_list.html index cb76e381bec..aed99432a9f 100644 --- a/public/app/features/alerting/partials/alert_list.html +++ b/public/app/features/alerting/partials/alert_list.html @@ -1,18 +1,18 @@
-
@@ -34,9 +34,10 @@