Move web/httputils to pkg/httputil and add DeadlineClient to it

This commit is contained in:
Fabian Reinartz 2015-05-28 21:11:48 +02:00
parent 2317b001d0
commit dfaf31a1da
10 changed files with 21 additions and 21 deletions

View file

@ -28,7 +28,7 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/prometheus/utility"
"github.com/prometheus/prometheus/pkg/httputil"
)
const (
@ -99,7 +99,7 @@ func NewNotificationHandler(alertmanagerURL string, notificationQueueCapacity in
alertmanagerURL: strings.TrimRight(alertmanagerURL, "/"),
pendingNotifications: make(chan NotificationReqs, notificationQueueCapacity),
httpClient: utility.NewDeadlineClient(*deadline),
httpClient: httputil.NewDeadlineClient(*deadline),
notificationLatency: prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: namespace,

View file

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package httputils
package httputil
import (
"compress/gzip"

View file

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package utility
package httputil
import (
"net"

View file

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package httputils
package httputil
import (
"encoding/json"

View file

@ -30,8 +30,8 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/pkg/httputil"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/utility"
)
const (
@ -197,7 +197,7 @@ func (t *Target) Update(cfg *config.ScrapeConfig, baseLabels clientmodel.LabelSe
t.scrapeInterval = time.Duration(cfg.ScrapeInterval)
t.deadline = time.Duration(cfg.ScrapeTimeout)
t.httpClient = utility.NewDeadlineClient(time.Duration(cfg.ScrapeTimeout))
t.httpClient = httputil.NewDeadlineClient(time.Duration(cfg.ScrapeTimeout))
t.baseLabels = clientmodel.LabelSet{}
// All remaining internal labels will not be part of the label set.

View file

@ -26,7 +26,7 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/prometheus/utility"
"github.com/prometheus/prometheus/pkg/httputil"
)
func TestBaseLabels(t *testing.T) {
@ -242,7 +242,7 @@ func newTestTarget(targetURL string, deadline time.Duration, baseLabels clientmo
deadline: deadline,
status: &TargetStatus{},
scrapeInterval: 1 * time.Millisecond,
httpClient: utility.NewDeadlineClient(deadline),
httpClient: httputil.NewDeadlineClient(deadline),
scraperStopping: make(chan struct{}),
scraperStopped: make(chan struct{}),
}

View file

@ -28,7 +28,7 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/prometheus/utility"
"github.com/prometheus/prometheus/pkg/httputil"
)
const (
@ -51,7 +51,7 @@ type Client struct {
func NewClient(url string, timeout time.Duration) *Client {
return &Client{
url: url,
httpClient: utility.NewDeadlineClient(timeout),
httpClient: httputil.NewDeadlineClient(timeout),
}
}

View file

@ -28,7 +28,7 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/prometheus/utility"
"github.com/prometheus/prometheus/pkg/httputil"
)
const (
@ -50,7 +50,7 @@ type Client struct {
func NewClient(url string, timeout time.Duration) *Client {
return &Client{
url: url,
httpClient: utility.NewDeadlineClient(timeout),
httpClient: httputil.NewDeadlineClient(timeout),
}
}

View file

@ -20,9 +20,9 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/prometheus/pkg/httputil"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/web/httputils"
)
// MetricsService manages the /api HTTP endpoint.
@ -35,7 +35,7 @@ type MetricsService struct {
// RegisterHandler registers the handler for the various endpoints below /api.
func (msrv *MetricsService) RegisterHandler(pathPrefix string) {
handler := func(h func(http.ResponseWriter, *http.Request)) http.Handler {
return httputils.CompressionHandler{
return httputil.CompressionHandler{
Handler: http.HandlerFunc(h),
}
}

View file

@ -26,7 +26,7 @@ import (
clientmodel "github.com/prometheus/client_golang/model"
"github.com/prometheus/prometheus/web/httputils"
"github.com/prometheus/prometheus/pkg/httputil"
)
// Enables cross-site script calls.
@ -39,7 +39,7 @@ func setAccessControlHeaders(w http.ResponseWriter) {
func httpJSONError(w http.ResponseWriter, err error, code int) {
w.WriteHeader(code)
httputils.ErrorJSON(w, err)
httputil.ErrorJSON(w, err)
}
func parseTimestampOrNow(t string, now clientmodel.Timestamp) (clientmodel.Timestamp, error) {
@ -67,7 +67,7 @@ func (serv MetricsService) Query(w http.ResponseWriter, r *http.Request) {
setAccessControlHeaders(w)
w.Header().Set("Content-Type", "application/json")
params := httputils.GetQueryParams(r)
params := httputil.GetQueryParams(r)
expr := params.Get("expr")
timestamp, err := parseTimestampOrNow(params.Get("timestamp"), serv.Now())
@ -88,7 +88,7 @@ func (serv MetricsService) Query(w http.ResponseWriter, r *http.Request) {
}
log.Debugf("Instant query: %s\nQuery stats:\n%s\n", expr, query.Stats())
httputils.RespondJSON(w, res.Value)
httputil.RespondJSON(w, res.Value)
}
// QueryRange handles the /api/query_range endpoint.
@ -96,7 +96,7 @@ func (serv MetricsService) QueryRange(w http.ResponseWriter, r *http.Request) {
setAccessControlHeaders(w)
w.Header().Set("Content-Type", "application/json")
params := httputils.GetQueryParams(r)
params := httputil.GetQueryParams(r)
expr := params.Get("expr")
duration, err := parseDuration(params.Get("range"))
@ -148,7 +148,7 @@ func (serv MetricsService) QueryRange(w http.ResponseWriter, r *http.Request) {
}
log.Debugf("Range query: %s\nQuery stats:\n%s\n", expr, query.Stats())
httputils.RespondJSON(w, matrix)
httputil.RespondJSON(w, matrix)
}
// Metrics handles the /api/metrics endpoint.