mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-26 21:31:18 +01:00
Update vendor for prometheus deps
This commit is contained in:
156
vendor/github.com/prometheus/client_golang/api/client.go
generated
vendored
Normal file
156
vendor/github.com/prometheus/client_golang/api/client.go
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
// Copyright 2015 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// 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 api provides clients for the HTTP APIs.
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DefaultRoundTripper is used if no RoundTripper is set in Config.
|
||||
var DefaultRoundTripper http.RoundTripper = &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
// Config defines configuration parameters for a new client.
|
||||
type Config struct {
|
||||
// The address of the Prometheus to connect to.
|
||||
Address string
|
||||
|
||||
// Client is used by the Client to drive HTTP requests. If not provided,
|
||||
// a new one based on the provided RoundTripper (or DefaultRoundTripper) will be used.
|
||||
Client *http.Client
|
||||
|
||||
// RoundTripper is used by the Client to drive HTTP requests. If not
|
||||
// provided, DefaultRoundTripper will be used.
|
||||
RoundTripper http.RoundTripper
|
||||
}
|
||||
|
||||
func (cfg *Config) roundTripper() http.RoundTripper {
|
||||
if cfg.RoundTripper == nil {
|
||||
return DefaultRoundTripper
|
||||
}
|
||||
return cfg.RoundTripper
|
||||
}
|
||||
|
||||
func (cfg *Config) client() http.Client {
|
||||
if cfg.Client == nil {
|
||||
return http.Client{
|
||||
Transport: cfg.roundTripper(),
|
||||
}
|
||||
}
|
||||
return *cfg.Client
|
||||
}
|
||||
|
||||
func (cfg *Config) validate() error {
|
||||
if cfg.Client != nil && cfg.RoundTripper != nil {
|
||||
return errors.New("api.Config.RoundTripper and api.Config.Client are mutually exclusive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Client is the interface for an API client.
|
||||
type Client interface {
|
||||
URL(ep string, args map[string]string) *url.URL
|
||||
Do(context.Context, *http.Request) (*http.Response, []byte, error)
|
||||
}
|
||||
|
||||
// NewClient returns a new Client.
|
||||
//
|
||||
// It is safe to use the returned Client from multiple goroutines.
|
||||
func NewClient(cfg Config) (Client, error) {
|
||||
u, err := url.Parse(cfg.Address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u.Path = strings.TrimRight(u.Path, "/")
|
||||
|
||||
if err := cfg.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &httpClient{
|
||||
endpoint: u,
|
||||
client: cfg.client(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type httpClient struct {
|
||||
endpoint *url.URL
|
||||
client http.Client
|
||||
}
|
||||
|
||||
func (c *httpClient) URL(ep string, args map[string]string) *url.URL {
|
||||
p := path.Join(c.endpoint.Path, ep)
|
||||
|
||||
for arg, val := range args {
|
||||
arg = ":" + arg
|
||||
p = strings.ReplaceAll(p, arg, val)
|
||||
}
|
||||
|
||||
u := *c.endpoint
|
||||
u.Path = p
|
||||
|
||||
return &u
|
||||
}
|
||||
|
||||
func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) {
|
||||
if ctx != nil {
|
||||
req = req.WithContext(ctx)
|
||||
}
|
||||
resp, err := c.client.Do(req)
|
||||
defer func() {
|
||||
if resp != nil {
|
||||
resp.Body.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var body []byte
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
_, err = buf.ReadFrom(resp.Body)
|
||||
body = buf.Bytes()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
<-done
|
||||
err = resp.Body.Close()
|
||||
if err == nil {
|
||||
err = ctx.Err()
|
||||
}
|
||||
case <-done:
|
||||
}
|
||||
|
||||
return resp, body, err
|
||||
}
|
||||
1458
vendor/github.com/prometheus/client_golang/api/prometheus/v1/api.go
generated
vendored
Normal file
1458
vendor/github.com/prometheus/client_golang/api/prometheus/v1/api.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
101
vendor/github.com/prometheus/common/config/config.go
generated
vendored
Normal file
101
vendor/github.com/prometheus/common/config/config.go
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
// Copyright 2016 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// 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.
|
||||
|
||||
// This package no longer handles safe yaml parsing. In order to
|
||||
// ensure correct yaml unmarshalling, use "yaml.UnmarshalStrict()".
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const secretToken = "<secret>"
|
||||
|
||||
// Secret special type for storing secrets.
|
||||
type Secret string
|
||||
|
||||
// MarshalSecretValue if set to true will expose Secret type
|
||||
// through the marshal interfaces. Useful for outside projects
|
||||
// that load and marshal the Prometheus config.
|
||||
var MarshalSecretValue bool = false
|
||||
|
||||
// MarshalYAML implements the yaml.Marshaler interface for Secrets.
|
||||
func (s Secret) MarshalYAML() (interface{}, error) {
|
||||
if MarshalSecretValue {
|
||||
return string(s), nil
|
||||
}
|
||||
if s != "" {
|
||||
return secretToken, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the yaml.Unmarshaler interface for Secrets.
|
||||
func (s *Secret) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
type plain Secret
|
||||
return unmarshal((*plain)(s))
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface for Secret.
|
||||
func (s Secret) MarshalJSON() ([]byte, error) {
|
||||
if MarshalSecretValue {
|
||||
return json.Marshal(string(s))
|
||||
}
|
||||
if len(s) == 0 {
|
||||
return json.Marshal("")
|
||||
}
|
||||
return json.Marshal(secretToken)
|
||||
}
|
||||
|
||||
type ProxyHeader map[string][]Secret
|
||||
|
||||
func (h *ProxyHeader) HTTPHeader() http.Header {
|
||||
if h == nil || *h == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
header := make(http.Header)
|
||||
|
||||
for name, values := range *h {
|
||||
var s []string
|
||||
if values != nil {
|
||||
s = make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
s = append(s, string(value))
|
||||
}
|
||||
}
|
||||
header[name] = s
|
||||
}
|
||||
|
||||
return header
|
||||
}
|
||||
|
||||
// DirectorySetter is a config type that contains file paths that may
|
||||
// be relative to the file containing the config.
|
||||
type DirectorySetter interface {
|
||||
// SetDirectory joins any relative file paths with dir.
|
||||
// Any paths that are empty or absolute remain unchanged.
|
||||
SetDirectory(dir string)
|
||||
}
|
||||
|
||||
// JoinDir joins dir and path if path is relative.
|
||||
// If path is empty or absolute, it is returned unchanged.
|
||||
func JoinDir(dir, path string) string {
|
||||
if path == "" || filepath.IsAbs(path) {
|
||||
return path
|
||||
}
|
||||
return filepath.Join(dir, path)
|
||||
}
|
||||
140
vendor/github.com/prometheus/common/config/headers.go
generated
vendored
Normal file
140
vendor/github.com/prometheus/common/config/headers.go
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
// Copyright 2024 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// 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.
|
||||
|
||||
// This package no longer handles safe yaml parsing. In order to
|
||||
// ensure correct yaml unmarshalling, use "yaml.UnmarshalStrict()".
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// reservedHeaders that change the connection, are set by Prometheus, or can
|
||||
// be changed otherwise.
|
||||
var reservedHeaders = map[string]struct{}{
|
||||
"Authorization": {},
|
||||
"Host": {},
|
||||
"Content-Encoding": {},
|
||||
"Content-Length": {},
|
||||
"Content-Type": {},
|
||||
"User-Agent": {},
|
||||
"Connection": {},
|
||||
"Keep-Alive": {},
|
||||
"Proxy-Authenticate": {},
|
||||
"Proxy-Authorization": {},
|
||||
"Www-Authenticate": {},
|
||||
"Accept-Encoding": {},
|
||||
"X-Prometheus-Remote-Write-Version": {},
|
||||
"X-Prometheus-Remote-Read-Version": {},
|
||||
"X-Prometheus-Scrape-Timeout-Seconds": {},
|
||||
|
||||
// Added by SigV4.
|
||||
"X-Amz-Date": {},
|
||||
"X-Amz-Security-Token": {},
|
||||
"X-Amz-Content-Sha256": {},
|
||||
}
|
||||
|
||||
// Headers represents the configuration for HTTP headers.
|
||||
type Headers struct {
|
||||
Headers map[string]Header `yaml:",inline"`
|
||||
dir string
|
||||
}
|
||||
|
||||
// Header represents the configuration for a single HTTP header.
|
||||
type Header struct {
|
||||
Values []string `yaml:"values,omitempty" json:"values,omitempty"`
|
||||
Secrets []Secret `yaml:"secrets,omitempty" json:"secrets,omitempty"`
|
||||
Files []string `yaml:"files,omitempty" json:"files,omitempty"`
|
||||
}
|
||||
|
||||
func (h Headers) MarshalJSON() ([]byte, error) {
|
||||
// Inline the Headers map when serializing JSON because json encoder doesn't support "inline" directive.
|
||||
return json.Marshal(h.Headers)
|
||||
}
|
||||
|
||||
// SetDirectory records the directory to make headers file relative to the
|
||||
// configuration file.
|
||||
func (h *Headers) SetDirectory(dir string) {
|
||||
if h == nil {
|
||||
return
|
||||
}
|
||||
h.dir = dir
|
||||
}
|
||||
|
||||
// Validate validates the Headers config.
|
||||
func (h *Headers) Validate() error {
|
||||
for n, header := range h.Headers {
|
||||
if _, ok := reservedHeaders[http.CanonicalHeaderKey(n)]; ok {
|
||||
return fmt.Errorf("setting header %q is not allowed", http.CanonicalHeaderKey(n))
|
||||
}
|
||||
for _, v := range header.Files {
|
||||
f := JoinDir(h.dir, v)
|
||||
_, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read header %q from file %s: %w", http.CanonicalHeaderKey(n), f, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewHeadersRoundTripper returns a RoundTripper that sets HTTP headers on
|
||||
// requests as configured.
|
||||
func NewHeadersRoundTripper(config *Headers, next http.RoundTripper) http.RoundTripper {
|
||||
if len(config.Headers) == 0 {
|
||||
return next
|
||||
}
|
||||
return &headersRoundTripper{
|
||||
config: config,
|
||||
next: next,
|
||||
}
|
||||
}
|
||||
|
||||
type headersRoundTripper struct {
|
||||
next http.RoundTripper
|
||||
config *Headers
|
||||
}
|
||||
|
||||
// RoundTrip implements http.RoundTripper.
|
||||
func (rt *headersRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
req = cloneRequest(req)
|
||||
for n, h := range rt.config.Headers {
|
||||
for _, v := range h.Values {
|
||||
req.Header.Add(n, v)
|
||||
}
|
||||
for _, v := range h.Secrets {
|
||||
req.Header.Add(n, string(v))
|
||||
}
|
||||
for _, v := range h.Files {
|
||||
f := JoinDir(rt.config.dir, v)
|
||||
b, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read headers file %s: %w", f, err)
|
||||
}
|
||||
req.Header.Add(n, strings.TrimSpace(string(b)))
|
||||
}
|
||||
}
|
||||
return rt.next.RoundTrip(req)
|
||||
}
|
||||
|
||||
// CloseIdleConnections implements closeIdler.
|
||||
func (rt *headersRoundTripper) CloseIdleConnections() {
|
||||
if ci, ok := rt.next.(closeIdler); ok {
|
||||
ci.CloseIdleConnections()
|
||||
}
|
||||
}
|
||||
1512
vendor/github.com/prometheus/common/config/http_config.go
generated
vendored
Normal file
1512
vendor/github.com/prometheus/common/config/http_config.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user