mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-05 17:27:51 +00:00
Use Golangci-lint
This commit is contained in:
parent
fdfecc8d7f
commit
0ea1c1b8d3
23 changed files with 177 additions and 174 deletions
|
|
@ -21,7 +21,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
|
@ -61,11 +60,10 @@ func (c *httpAPIClient) Do(ctx context.Context, verb, endpoint string, query url
|
|||
reqBody = strings.NewReader(query.Encode())
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(verb, u.String(), reqBody)
|
||||
req, err := http.NewRequestWithContext(ctx, verb, u.String(), reqBody)
|
||||
if err != nil {
|
||||
return APIResponse{}, fmt.Errorf("error constructing HTTP request to Prometheus: %v", err)
|
||||
}
|
||||
req.WithContext(ctx)
|
||||
for key, values := range c.headers {
|
||||
for _, value := range values {
|
||||
req.Header.Add(key, value)
|
||||
|
|
@ -102,7 +100,7 @@ func (c *httpAPIClient) Do(ctx context.Context, verb, endpoint string, query url
|
|||
|
||||
var body io.Reader = resp.Body
|
||||
if klog.V(8).Enabled() {
|
||||
data, err := ioutil.ReadAll(body)
|
||||
data, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
return APIResponse{}, fmt.Errorf("unable to log response body: %v", err)
|
||||
}
|
||||
|
|
@ -237,7 +235,7 @@ func (h *queryClient) QueryRange(ctx context.Context, r Range, query Selector) (
|
|||
// when present
|
||||
func timeoutFromContext(ctx context.Context) (time.Duration, bool) {
|
||||
if deadline, hasDeadline := ctx.Deadline(); hasDeadline {
|
||||
return time.Now().Sub(deadline), true
|
||||
return time.Since(deadline), true
|
||||
}
|
||||
|
||||
return time.Duration(0), false
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ type ErrorType string
|
|||
|
||||
const (
|
||||
ErrBadData ErrorType = "bad_data"
|
||||
ErrTimeout = "timeout"
|
||||
ErrCanceled = "canceled"
|
||||
ErrExec = "execution"
|
||||
ErrBadResponse = "bad_response"
|
||||
ErrTimeout ErrorType = "timeout"
|
||||
ErrCanceled ErrorType = "canceled"
|
||||
ErrExec ErrorType = "execution"
|
||||
ErrBadResponse ErrorType = "bad_response"
|
||||
)
|
||||
|
||||
// Error is an error returned by the API.
|
||||
|
|
@ -46,7 +46,7 @@ type ResponseStatus string
|
|||
|
||||
const (
|
||||
ResponseSucceeded ResponseStatus = "succeeded"
|
||||
ResponseError = "error"
|
||||
ResponseError ResponseStatus = "error"
|
||||
)
|
||||
|
||||
// APIResponse represents the raw response returned by the API.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue