2015-01-21 11:07:45 -08:00
|
|
|
// Copyright 2013 The Prometheus Authors
|
2013-02-22 12:07:35 -08:00
|
|
|
// 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.
|
|
|
|
|
2015-06-04 09:24:04 -07:00
|
|
|
package legacy
|
2013-01-10 17:27:03 -08:00
|
|
|
|
|
|
|
import (
|
2013-10-22 11:31:52 -07:00
|
|
|
"net/http"
|
2014-06-30 04:19:07 -07:00
|
|
|
|
2014-06-18 10:43:15 -07:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2015-08-20 08:18:46 -07:00
|
|
|
"github.com/prometheus/common/model"
|
2015-09-24 08:07:11 -07:00
|
|
|
"github.com/prometheus/common/route"
|
2015-03-27 15:43:47 -07:00
|
|
|
|
2015-03-30 10:43:19 -07:00
|
|
|
"github.com/prometheus/prometheus/promql"
|
2014-06-06 02:55:53 -07:00
|
|
|
"github.com/prometheus/prometheus/storage/local"
|
2015-05-29 04:30:30 -07:00
|
|
|
"github.com/prometheus/prometheus/util/httputil"
|
2013-01-10 17:27:03 -08:00
|
|
|
)
|
|
|
|
|
2015-06-04 09:24:04 -07:00
|
|
|
// API manages the /api HTTP endpoint.
|
|
|
|
type API struct {
|
2015-08-20 08:18:46 -07:00
|
|
|
Now func() model.Time
|
2015-03-30 10:43:19 -07:00
|
|
|
Storage local.Storage
|
|
|
|
QueryEngine *promql.Engine
|
2013-01-10 17:27:03 -08:00
|
|
|
}
|
2013-10-22 11:31:52 -07:00
|
|
|
|
2015-08-24 06:07:27 -07:00
|
|
|
// Register registers the handler for the various endpoints below /api.
|
2015-06-04 09:24:04 -07:00
|
|
|
func (api *API) Register(router *route.Router) {
|
2016-01-25 16:32:46 -08:00
|
|
|
// List all the endpoints here instead of using a wildcard route because we
|
|
|
|
// would otherwise handle /api/v1 as well.
|
|
|
|
router.Options("/query", handle("options", api.Options))
|
|
|
|
router.Options("/query_range", handle("options", api.Options))
|
|
|
|
router.Options("/metrics", handle("options", api.Options))
|
|
|
|
|
2015-06-04 09:24:04 -07:00
|
|
|
router.Get("/query", handle("query", api.Query))
|
|
|
|
router.Get("/query_range", handle("query_range", api.QueryRange))
|
|
|
|
router.Get("/metrics", handle("metrics", api.Metrics))
|
2015-06-02 23:38:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func handle(name string, f http.HandlerFunc) http.HandlerFunc {
|
|
|
|
h := httputil.CompressionHandler{
|
|
|
|
Handler: f,
|
2013-10-22 11:31:52 -07:00
|
|
|
}
|
2015-06-02 23:38:50 -07:00
|
|
|
return prometheus.InstrumentHandler(name, h)
|
2013-10-22 11:31:52 -07:00
|
|
|
}
|