mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-24 12:13:13 -08:00
Guard reload and quit endpoints by flag
This commit is contained in:
parent
45ac064669
commit
32226e30f5
|
@ -124,8 +124,8 @@ func main() {
|
|||
a.Flag("web.user-assets", "Path to static asset directory, available at /user.").
|
||||
PlaceHolder("<path>").StringVar(&cfg.web.UserAssetsPath)
|
||||
|
||||
a.Flag("web.enable-remote-shutdown", "Enable shutdown via HTTP request.").
|
||||
Default("false").BoolVar(&cfg.web.EnableQuit)
|
||||
a.Flag("web.enable-lifecycle", "Enable shutdown and reload via HTTP request.").
|
||||
Default("false").BoolVar(&cfg.web.EnableLifecycle)
|
||||
|
||||
a.Flag("web.enable-admin-api", "Enables API endpoints for admin control actions").
|
||||
Default("false").BoolVar(&cfg.web.EnableAdminAPI)
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/admin/v1/tsdb/delete_series": {
|
||||
"/v2/admin/tsdb/delete_series": {
|
||||
"post": {
|
||||
"summary": "DeleteSeries deletes data for a selection of series in a time range.",
|
||||
"operationId": "DeleteSeries",
|
||||
|
@ -42,9 +42,9 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/admin/v1/tsdb/snapshot": {
|
||||
"/v2/admin/tsdb/snapshot": {
|
||||
"post": {
|
||||
"summary": "Snapshot creates a snapshot of all current data into 'snapshots/\u003cdatetime\u003e-\u003crand\u003e' under\nthe TSDB's date directory.",
|
||||
"summary": "Snapshot creates a snapshot of all current data into 'snapshots/\u003cdatetime\u003e-\u003crand\u003e' under\nthe TSDB's data directory.",
|
||||
"operationId": "TSDBSnapshot",
|
||||
"responses": {
|
||||
"200": {
|
||||
|
|
|
@ -106,7 +106,7 @@ const _ = grpc.SupportPackageIsVersion4
|
|||
|
||||
type AdminClient interface {
|
||||
// Snapshot creates a snapshot of all current data into 'snapshots/<datetime>-<rand>' under
|
||||
// the TSDB's date directory.
|
||||
// the TSDB's data directory.
|
||||
TSDBSnapshot(ctx context.Context, in *TSDBSnapshotRequest, opts ...grpc.CallOption) (*TSDBSnapshotResponse, error)
|
||||
// DeleteSeries deletes data for a selection of series in a time range.
|
||||
DeleteSeries(ctx context.Context, in *SeriesDeleteRequest, opts ...grpc.CallOption) (*SeriesDeleteResponse, error)
|
||||
|
@ -142,7 +142,7 @@ func (c *adminClient) DeleteSeries(ctx context.Context, in *SeriesDeleteRequest,
|
|||
|
||||
type AdminServer interface {
|
||||
// Snapshot creates a snapshot of all current data into 'snapshots/<datetime>-<rand>' under
|
||||
// the TSDB's date directory.
|
||||
// the TSDB's data directory.
|
||||
TSDBSnapshot(context.Context, *TSDBSnapshotRequest) (*TSDBSnapshotResponse, error)
|
||||
// DeleteSeries deletes data for a selection of series in a time range.
|
||||
DeleteSeries(context.Context, *SeriesDeleteRequest) (*SeriesDeleteResponse, error)
|
||||
|
@ -833,28 +833,28 @@ func init() { proto.RegisterFile("rpc.proto", fileDescriptorRpc) }
|
|||
var fileDescriptorRpc = []byte{
|
||||
// 393 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x51, 0xcd, 0xae, 0xd2, 0x40,
|
||||
0x14, 0xbe, 0x73, 0x41, 0x94, 0x81, 0x55, 0x41, 0xad, 0x0d, 0x69, 0x71, 0x36, 0x12, 0x16, 0x9d,
|
||||
0x88, 0x3b, 0x5c, 0xd9, 0xb0, 0xd4, 0x4d, 0x61, 0xe5, 0x86, 0x4c, 0xe1, 0x58, 0x9a, 0xd0, 0x99,
|
||||
0xb1, 0x33, 0x18, 0x74, 0xe9, 0x13, 0x98, 0xf8, 0x52, 0x24, 0x6e, 0x4c, 0xdc, 0xfb, 0x43, 0x7c,
|
||||
0x07, 0xb7, 0xa6, 0x33, 0x54, 0xa9, 0xc1, 0xe4, 0xee, 0x4e, 0x4f, 0xbf, 0xef, 0x7c, 0x3f, 0x83,
|
||||
0xdb, 0x85, 0x5c, 0x85, 0xb2, 0x10, 0x5a, 0x38, 0x58, 0x16, 0x22, 0x07, 0xbd, 0x81, 0x9d, 0xf2,
|
||||
0x3a, 0xfa, 0xad, 0x04, 0x65, 0x7f, 0x78, 0x41, 0x2a, 0x44, 0xba, 0x05, 0x6a, 0xbe, 0x92, 0xdd,
|
||||
0x2b, 0xaa, 0xb3, 0x1c, 0x94, 0x66, 0xb9, 0x3c, 0x01, 0x06, 0x27, 0x00, 0x93, 0x19, 0x65, 0x9c,
|
||||
0x0b, 0xcd, 0x74, 0x26, 0x78, 0x45, 0xef, 0xa7, 0x22, 0x15, 0x66, 0xa4, 0xe5, 0x64, 0xb7, 0xe4,
|
||||
0x2e, 0xee, 0x2d, 0xe6, 0xb3, 0x68, 0xce, 0x99, 0x54, 0x1b, 0xa1, 0x63, 0x78, 0xbd, 0x03, 0xa5,
|
||||
0xc9, 0x18, 0xf7, 0xeb, 0x6b, 0x25, 0x05, 0x57, 0xe0, 0x38, 0xb8, 0xc9, 0x59, 0x0e, 0x2e, 0x1a,
|
||||
0xa2, 0x51, 0x3b, 0x36, 0x33, 0xf9, 0x84, 0x70, 0x6f, 0x0e, 0x45, 0x06, 0x6a, 0x06, 0x5b, 0xd0,
|
||||
0x70, 0xba, 0xe1, 0x3c, 0xc5, 0x77, 0xf2, 0x8c, 0x2f, 0x4b, 0x97, 0x06, 0xdf, 0x99, 0x78, 0xa1,
|
||||
0x75, 0x18, 0x56, 0x11, 0xc2, 0x45, 0x15, 0x21, 0x6a, 0x7e, 0xf8, 0x16, 0xa0, 0xf8, 0x76, 0x9e,
|
||||
0xf1, 0x72, 0x67, 0xc8, 0x6c, 0x6f, 0xc9, 0xd7, 0x37, 0x26, 0xb3, 0xbd, 0x21, 0x4f, 0x4b, 0xb2,
|
||||
0x5e, 0x6d, 0xa0, 0x50, 0x6e, 0x63, 0xd8, 0x18, 0x75, 0x26, 0x6e, 0xf8, 0xb7, 0xd5, 0xf0, 0x39,
|
||||
0x4b, 0x60, 0xfb, 0xc2, 0x02, 0xa2, 0xe6, 0xe1, 0x6b, 0x70, 0x15, 0xff, 0xc1, 0x93, 0x7b, 0xb8,
|
||||
0x5f, 0x0f, 0x63, 0x93, 0x4f, 0x7e, 0x21, 0x7c, 0xeb, 0xd9, 0x3a, 0xcf, 0xb8, 0x53, 0xe0, 0xee,
|
||||
0x79, 0x37, 0x4e, 0x70, 0x7e, 0xfb, 0x42, 0x99, 0xde, 0xf0, 0xff, 0x00, 0x7b, 0x9c, 0x04, 0xef,
|
||||
0xbf, 0xfc, 0xfc, 0x78, 0xfd, 0x80, 0xdc, 0xa7, 0xac, 0x94, 0xa0, 0x6f, 0x1e, 0x53, 0xad, 0xd6,
|
||||
0x09, 0x55, 0x95, 0xc6, 0x3b, 0xdc, 0xb5, 0x7e, 0xac, 0xb7, 0xba, 0xe6, 0x85, 0xf2, 0xeb, 0x9a,
|
||||
0x97, 0x02, 0x91, 0x47, 0x46, 0xf3, 0x21, 0x19, 0xfc, 0xa3, 0xb9, 0x36, 0xb0, 0xa5, 0x32, 0x9c,
|
||||
0x29, 0x1a, 0x47, 0xee, 0xe1, 0x87, 0x7f, 0x75, 0x38, 0xfa, 0xe8, 0xf3, 0xd1, 0x47, 0xdf, 0x8f,
|
||||
0x3e, 0x7a, 0xd9, 0x2a, 0x6f, 0xcb, 0x24, 0x69, 0x99, 0xa7, 0x78, 0xf2, 0x3b, 0x00, 0x00, 0xff,
|
||||
0xff, 0xb9, 0xfc, 0xf3, 0x68, 0xbe, 0x02, 0x00, 0x00,
|
||||
0x14, 0xbe, 0x73, 0x2f, 0xa2, 0x0c, 0xac, 0x0a, 0x6a, 0x6d, 0x48, 0x8b, 0xb3, 0x91, 0xb0, 0xe8,
|
||||
0x24, 0x75, 0x87, 0x2b, 0x1b, 0x96, 0xba, 0x29, 0xac, 0xdc, 0x90, 0x29, 0x1c, 0x4b, 0x13, 0x3a,
|
||||
0x33, 0x76, 0x06, 0x83, 0x2e, 0x7d, 0x02, 0x13, 0x5f, 0x8a, 0xc4, 0x8d, 0x89, 0x7b, 0x7f, 0x88,
|
||||
0xef, 0xe0, 0xd6, 0x74, 0x86, 0x2a, 0x35, 0x98, 0xb8, 0x3b, 0x3d, 0xfd, 0xbe, 0xf3, 0xfd, 0x0c,
|
||||
0xee, 0x94, 0x72, 0x15, 0xca, 0x52, 0x68, 0xe1, 0x60, 0x59, 0x8a, 0x02, 0xf4, 0x06, 0x76, 0xca,
|
||||
0xeb, 0xea, 0x37, 0x12, 0x94, 0xfd, 0xe1, 0x05, 0x99, 0x10, 0xd9, 0x16, 0xa8, 0xf9, 0x4a, 0x77,
|
||||
0x2f, 0xa9, 0xce, 0x0b, 0x50, 0x9a, 0x15, 0xf2, 0x04, 0x18, 0x9e, 0x00, 0x4c, 0xe6, 0x94, 0x71,
|
||||
0x2e, 0x34, 0xd3, 0xb9, 0xe0, 0x35, 0x7d, 0x90, 0x89, 0x4c, 0x98, 0x91, 0x56, 0x93, 0xdd, 0x92,
|
||||
0xbb, 0xb8, 0xbf, 0x98, 0xcf, 0xe2, 0x39, 0x67, 0x52, 0x6d, 0x84, 0x4e, 0xe0, 0xd5, 0x0e, 0x94,
|
||||
0x26, 0x13, 0x3c, 0x68, 0xae, 0x95, 0x14, 0x5c, 0x81, 0xe3, 0xe0, 0x16, 0x67, 0x05, 0xb8, 0x68,
|
||||
0x84, 0xc6, 0x9d, 0xc4, 0xcc, 0xe4, 0x23, 0xc2, 0xfd, 0x39, 0x94, 0x39, 0xa8, 0x19, 0x6c, 0x41,
|
||||
0xc3, 0xe9, 0x86, 0xf3, 0x04, 0xdf, 0x29, 0x72, 0xbe, 0xac, 0x5c, 0x1a, 0x7c, 0x37, 0xf2, 0x42,
|
||||
0xeb, 0x30, 0xac, 0x23, 0x84, 0x8b, 0x3a, 0x42, 0xdc, 0x7a, 0xff, 0x35, 0x40, 0xc9, 0xed, 0x22,
|
||||
0xe7, 0xd5, 0xce, 0x90, 0xd9, 0xde, 0x92, 0xaf, 0xff, 0x9b, 0xcc, 0xf6, 0x86, 0x3c, 0xad, 0xc8,
|
||||
0x7a, 0xb5, 0x81, 0x52, 0xb9, 0x37, 0xa3, 0x9b, 0x71, 0x37, 0x72, 0xc3, 0x3f, 0xad, 0x86, 0xcf,
|
||||
0x58, 0x0a, 0xdb, 0xe7, 0x16, 0x10, 0xb7, 0x0e, 0x5f, 0x82, 0xab, 0xe4, 0x37, 0x9e, 0xdc, 0xc3,
|
||||
0x83, 0x66, 0x18, 0x9b, 0x3c, 0xfa, 0x89, 0xf0, 0xad, 0xa7, 0xeb, 0x22, 0xe7, 0x4e, 0x89, 0x7b,
|
||||
0xe7, 0xdd, 0x38, 0xc1, 0xf9, 0xed, 0x0b, 0x65, 0x7a, 0xa3, 0x7f, 0x03, 0xec, 0x71, 0x12, 0xbc,
|
||||
0xfb, 0xfc, 0xe3, 0xc3, 0xf5, 0x03, 0x72, 0x9f, 0xbe, 0x8e, 0x28, 0xab, 0x54, 0xa8, 0x56, 0xeb,
|
||||
0x94, 0xaa, 0x5a, 0xe3, 0x2d, 0xee, 0x59, 0x3f, 0xd6, 0x5b, 0x53, 0xf3, 0x42, 0xf9, 0x4d, 0xcd,
|
||||
0x4b, 0x81, 0xc8, 0x23, 0xa3, 0xf9, 0x90, 0x0c, 0xff, 0xd2, 0x5c, 0x1b, 0xd8, 0x52, 0x19, 0xce,
|
||||
0x14, 0x4d, 0x62, 0xf7, 0xf0, 0xdd, 0xbf, 0x3a, 0x1c, 0x7d, 0xf4, 0xe9, 0xe8, 0xa3, 0x6f, 0x47,
|
||||
0x1f, 0xbd, 0x68, 0x57, 0xb7, 0x65, 0x9a, 0xb6, 0xcd, 0x53, 0x3c, 0xfe, 0x15, 0x00, 0x00, 0xff,
|
||||
0xff, 0xeb, 0x59, 0x61, 0x63, 0xbe, 0x02, 0x00, 0x00,
|
||||
}
|
||||
|
|
|
@ -139,9 +139,9 @@ func RegisterAdminHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc
|
|||
}
|
||||
|
||||
var (
|
||||
pattern_Admin_TSDBSnapshot_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"admin", "v1", "tsdb", "snapshot"}, ""))
|
||||
pattern_Admin_TSDBSnapshot_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v2", "admin", "tsdb", "snapshot"}, ""))
|
||||
|
||||
pattern_Admin_DeleteSeries_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"admin", "v1", "tsdb", "delete_series"}, ""))
|
||||
pattern_Admin_DeleteSeries_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v2", "admin", "tsdb", "delete_series"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -29,17 +29,17 @@ option (gogoproto.goproto_getters_all) = false;
|
|||
|
||||
service Admin {
|
||||
// Snapshot creates a snapshot of all current data into 'snapshots/<datetime>-<rand>' under
|
||||
// the TSDB's date directory.
|
||||
// the TSDB's data directory.
|
||||
rpc TSDBSnapshot(TSDBSnapshotRequest) returns (TSDBSnapshotResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/admin/v1/tsdb/snapshot"
|
||||
post: "/v2/admin/tsdb/snapshot"
|
||||
};
|
||||
}
|
||||
|
||||
// DeleteSeries deletes data for a selection of series in a time range.
|
||||
rpc DeleteSeries(SeriesDeleteRequest) returns (SeriesDeleteResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/admin/v1/tsdb/delete_series"
|
||||
post: "/v2/admin/tsdb/delete_series"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package apiv2
|
||||
package api_v2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
28
web/web.go
28
web/web.go
|
@ -57,7 +57,7 @@ import (
|
|||
"github.com/prometheus/prometheus/template"
|
||||
"github.com/prometheus/prometheus/util/httputil"
|
||||
api_v1 "github.com/prometheus/prometheus/web/api/v1"
|
||||
apiv2 "github.com/prometheus/prometheus/web/api/v2"
|
||||
api_v2 "github.com/prometheus/prometheus/web/api/v2"
|
||||
"github.com/prometheus/prometheus/web/ui"
|
||||
)
|
||||
|
||||
|
@ -132,7 +132,7 @@ type Options struct {
|
|||
UserAssetsPath string
|
||||
ConsoleTemplatesPath string
|
||||
ConsoleLibrariesPath string
|
||||
EnableQuit bool
|
||||
EnableLifecycle bool
|
||||
EnableAdminAPI bool
|
||||
}
|
||||
|
||||
|
@ -207,14 +207,26 @@ func New(o *Options) *Handler {
|
|||
router.Get("/user/*filepath", instrf("user", route.FileServe(o.UserAssetsPath)))
|
||||
}
|
||||
|
||||
if o.EnableQuit {
|
||||
if o.EnableLifecycle {
|
||||
router.Post("/-/quit", h.quit)
|
||||
router.Post("/-/reload", h.reload)
|
||||
} else {
|
||||
router.Post("/-/quit", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
w.Write([]byte("Lifecycle APIs are not enabled"))
|
||||
})
|
||||
router.Post("/-/reload", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
w.Write([]byte("Lifecycle APIs are not enabled"))
|
||||
})
|
||||
}
|
||||
|
||||
router.Post("/-/reload", h.reload)
|
||||
router.Get("/-/reload", func(w http.ResponseWriter, r *http.Request) {
|
||||
router.Get("/-/quit", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
fmt.Fprintf(w, "This endpoint requires a POST request.\n")
|
||||
w.Write([]byte("Only POST requests allowed"))
|
||||
})
|
||||
router.Get("/-/reload", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
w.Write([]byte("Only POST requests allowed"))
|
||||
})
|
||||
|
||||
router.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
|
||||
|
@ -285,7 +297,7 @@ func (h *Handler) Run(ctx context.Context) error {
|
|||
httpl = m.Match(cmux.HTTP1Fast())
|
||||
grpcSrv = grpc.NewServer()
|
||||
)
|
||||
av2 := apiv2.New(
|
||||
av2 := api_v2.New(
|
||||
time.Now,
|
||||
h.options.Storage,
|
||||
h.options.QueryEngine,
|
||||
|
|
Loading…
Reference in a new issue