-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use retriable HTTP client in proxy mode (#883)
* Use retriable HTTP client in proxy mode * Fix CHANGELOG * Fix: mage check
- Loading branch information
Showing
5 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package proxymode | ||
|
||
import ( | ||
"github.com/hashicorp/go-retryablehttp" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type zapLoggerAdapter struct { | ||
target *zap.Logger | ||
} | ||
|
||
var _ retryablehttp.LeveledLogger = new(zapLoggerAdapter) | ||
|
||
func withZapLoggerAdapter(target *zap.Logger) retryablehttp.LeveledLogger { | ||
return &zapLoggerAdapter{ | ||
target: target, | ||
} | ||
} | ||
|
||
func (a zapLoggerAdapter) Error(msg string, keysAndValues ...interface{}) { | ||
a.target.Error(msg, keysAndValuesAsZapFields(keysAndValues...)...) | ||
} | ||
|
||
func (a zapLoggerAdapter) Info(msg string, keysAndValues ...interface{}) { | ||
a.target.Info(msg, keysAndValuesAsZapFields(keysAndValues...)...) | ||
} | ||
|
||
func (a zapLoggerAdapter) Debug(msg string, keysAndValues ...interface{}) { | ||
a.target.Debug(msg, keysAndValuesAsZapFields(keysAndValues...)...) | ||
} | ||
|
||
func (a zapLoggerAdapter) Warn(msg string, keysAndValues ...interface{}) { | ||
a.target.Warn(msg, keysAndValuesAsZapFields(keysAndValues...)...) | ||
} | ||
|
||
// keysAndValuesAsZapFields function transforms the LeveledLogger arguments to the zap.Logger interface. | ||
func keysAndValuesAsZapFields(keysAndValues ...interface{}) []zap.Field { | ||
fields := make([]zap.Field, len(keysAndValues)/2) | ||
var j int | ||
for i := 0; i < len(keysAndValues); i += 2 { | ||
key, ok := keysAndValues[i].(string) | ||
if !ok { | ||
continue // something is wrong with the key, string expected | ||
} | ||
fields[j] = zap.Any(key, keysAndValues[i+1]) | ||
j++ | ||
} | ||
return fields | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters