IMGPROXY_REPORT_DOWNLOADING_ERRORS config

This commit is contained in:
DarthSim
2019-10-01 15:18:37 +06:00
parent cc5d3804fb
commit 0de6fc0aa6
5 changed files with 15 additions and 9 deletions

View File

@@ -5,7 +5,8 @@
- Reimplemented and more errors-tolerant image size parsing; - Reimplemented and more errors-tolerant image size parsing;
- TIFF and BMP support; - TIFF and BMP support;
- Using Application Default Credentials when `IMGPROXY_USE_GCS` is set to `true` but `IMGPROXY_GCS_KEY` is not set. - Using Application Default Credentials when `IMGPROXY_USE_GCS` is set to `true` but `IMGPROXY_GCS_KEY` is not set.
**Note:** If you use `IMGPROXY_GCS_KEY`, it's recommended to set `IMGPROXY_USE_GCS` to `true` since it may be required by future versions to enable GCS support. **Note:** If you use `IMGPROXY_GCS_KEY`, it's recommended to set `IMGPROXY_USE_GCS` to `true` since it may be required by future versions to enable GCS support;
- Setting `IMGPROXY_REPORT_DOWNLOADING_ERRORS` to `false` disables reporting of downloading errors.
## v2.5.0 ## v2.5.0

View File

@@ -204,6 +204,8 @@ type config struct {
SentryEnvironment string SentryEnvironment string
SentryRelease string SentryRelease string
ReportDownloadingErrors bool
FreeMemoryInterval int FreeMemoryInterval int
DownloadBufferSize int DownloadBufferSize int
GZipBufferSize int GZipBufferSize int
@@ -230,6 +232,7 @@ var conf = config{
HoneybadgerEnv: "production", HoneybadgerEnv: "production",
SentryEnvironment: "production", SentryEnvironment: "production",
SentryRelease: fmt.Sprintf("imgproxy/%s", version), SentryRelease: fmt.Sprintf("imgproxy/%s", version),
ReportDownloadingErrors: true,
FreeMemoryInterval: 10, FreeMemoryInterval: 10,
BufferPoolCalibrationThreshold: 1024, BufferPoolCalibrationThreshold: 1024,
} }
@@ -336,6 +339,7 @@ func configure() {
strEnvConfig(&conf.SentryDSN, "IMGPROXY_SENTRY_DSN") strEnvConfig(&conf.SentryDSN, "IMGPROXY_SENTRY_DSN")
strEnvConfig(&conf.SentryEnvironment, "IMGPROXY_SENTRY_ENVIRONMENT") strEnvConfig(&conf.SentryEnvironment, "IMGPROXY_SENTRY_ENVIRONMENT")
strEnvConfig(&conf.SentryRelease, "IMGPROXY_SENTRY_RELEASE") strEnvConfig(&conf.SentryRelease, "IMGPROXY_SENTRY_RELEASE")
boolEnvConfig(&conf.ReportDownloadingErrors, "IMGPROXY_REPORT_DOWNLOADING_ERRORS")
intEnvConfig(&conf.FreeMemoryInterval, "IMGPROXY_FREE_MEMORY_INTERVAL") intEnvConfig(&conf.FreeMemoryInterval, "IMGPROXY_FREE_MEMORY_INTERVAL")
intEnvConfig(&conf.DownloadBufferSize, "IMGPROXY_DOWNLOAD_BUFFER_SIZE") intEnvConfig(&conf.DownloadBufferSize, "IMGPROXY_DOWNLOAD_BUFFER_SIZE")

View File

@@ -187,10 +187,11 @@ imgproxy can report occurred errors to Bugsnag, Honeybadger and Sentry:
* `IMGPROXY_BUGSNAG_KEY`: Bugsnag API key. When provided, enables error reporting to Bugsnag; * `IMGPROXY_BUGSNAG_KEY`: Bugsnag API key. When provided, enables error reporting to Bugsnag;
* `IMGPROXY_BUGSNAG_STAGE`: Bugsnag stage to report to. Default: `production`; * `IMGPROXY_BUGSNAG_STAGE`: Bugsnag stage to report to. Default: `production`;
* `IMGPROXY_HONEYBADGER_KEY`: Honeybadger API key. When provided, enables error reporting to Honeybadger; * `IMGPROXY_HONEYBADGER_KEY`: Honeybadger API key. When provided, enables error reporting to Honeybadger;
* `IMGPROXY_HONEYBADGER_ENV`: Honeybadger env to report to. Default: `production`. * `IMGPROXY_HONEYBADGER_ENV`: Honeybadger env to report to. Default: `production`;
* `IMGPROXY_SENTRY_DSN`: Sentry project DSN. When provided, enables error reporting to Sentry; * `IMGPROXY_SENTRY_DSN`: Sentry project DSN. When provided, enables error reporting to Sentry;
* `IMGPROXY_SENTRY_ENVIRONMENT`: Sentry environment to report to. Default: `production`. * `IMGPROXY_SENTRY_ENVIRONMENT`: Sentry environment to report to. Default: `production`;
* `IMGPROXY_SENTRY_RELEASE`: Sentry release to report to. Default: `imgproxy/{imgproxy version}`. * `IMGPROXY_SENTRY_RELEASE`: Sentry release to report to. Default: `imgproxy/{imgproxy version}`;
* `IMGPROXY_REPORT_DOWNLOADING_ERRORS`: when `true`, imgproxy will report downloading errors. Default: `true`.
## Log ## Log

View File

@@ -151,20 +151,20 @@ func readAndCheckImage(r io.Reader, contentLength int) (*imageData, error) {
func requestImage(imageURL string) (*http.Response, error) { func requestImage(imageURL string) (*http.Response, error) {
req, err := http.NewRequest("GET", imageURL, nil) req, err := http.NewRequest("GET", imageURL, nil)
if err != nil { if err != nil {
return nil, newError(404, err.Error(), msgSourceImageIsUnreachable).MarkAsUnexpected() return nil, newError(404, err.Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
} }
req.Header.Set("User-Agent", conf.UserAgent) req.Header.Set("User-Agent", conf.UserAgent)
res, err := downloadClient.Do(req) res, err := downloadClient.Do(req)
if err != nil { if err != nil {
return res, newError(404, err.Error(), msgSourceImageIsUnreachable).MarkAsUnexpected() return res, newError(404, err.Error(), msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
} }
if res.StatusCode != 200 { if res.StatusCode != 200 {
body, _ := ioutil.ReadAll(res.Body) body, _ := ioutil.ReadAll(res.Body)
msg := fmt.Sprintf("Can't download image; Status: %d; %s", res.StatusCode, string(body)) msg := fmt.Sprintf("Can't download image; Status: %d; %s", res.StatusCode, string(body))
return res, newError(404, msg, msgSourceImageIsUnreachable).MarkAsUnexpected() return res, newError(404, msg, msgSourceImageIsUnreachable).SetUnexpected(conf.ReportDownloadingErrors)
} }
return res, nil return res, nil

View File

@@ -31,8 +31,8 @@ func (e *imgproxyError) StackTrace() []uintptr {
return e.stack return e.stack
} }
func (e *imgproxyError) MarkAsUnexpected() *imgproxyError { func (e *imgproxyError) SetUnexpected(u bool) *imgproxyError {
e.Unexpected = true e.Unexpected = u
return e return e
} }