mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2024-12-27 09:19:06 +01:00
Support HTTPS; Add /api/debug
This commit is contained in:
parent
f38353a879
commit
8fb2557f97
24
api.go
24
api.go
@ -307,12 +307,18 @@ func authentication(next http.Handler, publicKey ed25519.PublicKey) http.Handler
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartApiServer(address string, ctx context.Context) error {
|
func StartApiServer(ctx context.Context, address string, httpsConfig *HttpsConfig) error {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
|
|
||||||
r.HandleFunc("/api/free", handleFree)
|
r.HandleFunc("/api/free", handleFree)
|
||||||
r.HandleFunc("/api/write", handleWrite)
|
r.HandleFunc("/api/write", handleWrite)
|
||||||
r.HandleFunc("/api/query", handleQuery)
|
r.HandleFunc("/api/query", handleQuery)
|
||||||
|
r.HandleFunc("/api/debug", func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
bw := bufio.NewWriter(rw)
|
||||||
|
defer bw.Flush()
|
||||||
|
|
||||||
|
memoryStore.DebugDump(bw)
|
||||||
|
})
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Handler: r,
|
Handler: r,
|
||||||
@ -331,10 +337,18 @@ func StartApiServer(address string, ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Printf("API http endpoint listening on '%s'\n", address)
|
if httpsConfig != nil {
|
||||||
err := server.ListenAndServe()
|
log.Printf("API https endpoint listening on '%s'\n", address)
|
||||||
if err != nil && err != http.ErrServerClosed {
|
err := server.ListenAndServeTLS(httpsConfig.CertFile, httpsConfig.KeyFile)
|
||||||
log.Println(err)
|
if err != nil && err != http.ErrServerClosed {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("API http endpoint listening on '%s'\n", address)
|
||||||
|
err := server.ListenAndServe()
|
||||||
|
if err != nil && err != http.ErrServerClosed {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -20,12 +20,18 @@ type MetricConfig struct {
|
|||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HttpsConfig struct {
|
||||||
|
CertFile string `json:"cert"`
|
||||||
|
KeyFile string `json:"key"`
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Metrics map[string]MetricConfig `json:"metrics"`
|
Metrics map[string]MetricConfig `json:"metrics"`
|
||||||
RetentionInMemory string `json:"retention-in-memory"`
|
RetentionInMemory string `json:"retention-in-memory"`
|
||||||
Nats string `json:"nats"`
|
Nats string `json:"nats"`
|
||||||
JwtPublicKey string `json:"jwt-public-key"`
|
JwtPublicKey string `json:"jwt-public-key"`
|
||||||
HttpApiAddress string `json:"http-api-address"`
|
HttpApiAddress string `json:"http-api-address"`
|
||||||
|
HttpsConfig *HttpsConfig `json:"https"`
|
||||||
Checkpoints struct {
|
Checkpoints struct {
|
||||||
Interval string `json:"interval"`
|
Interval string `json:"interval"`
|
||||||
RootDir string `json:"directory"`
|
RootDir string `json:"directory"`
|
||||||
@ -189,7 +195,7 @@ func main() {
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := StartApiServer(conf.HttpApiAddress, ctx)
|
err := StartApiServer(ctx, conf.HttpApiAddress, conf.HttpsConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user