-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
50 lines (41 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"net/http"
"os"
v1API "github.com/mattbostock/opentsdb-promql-frontend/api/v1"
"github.com/prometheus/common/log"
"github.com/prometheus/common/route"
"github.com/prometheus/prometheus/promql"
"golang.org/x/net/context"
)
const apiRoute = "/api/v1"
var config = struct {
listenAddr string
openTSDBurl string
}{
"localhost:9080",
"http://localhost:4242",
}
func init() {
if len(os.Getenv("ADDR")) > 0 {
config.listenAddr = os.Getenv("ADDR")
}
if len(os.Getenv("OPENTSDB_URL")) > 0 {
config.openTSDBurl = os.Getenv("OPENTSDB_URL")
}
}
func main() {
var (
ctx, cancelCtx = context.WithCancel(context.Background())
storage = &queryable{}
queryEngine = promql.NewEngine(storage, promql.DefaultEngineOptions)
)
defer cancelCtx()
router := route.New(func(r *http.Request) (context.Context, error) {
return ctx, nil
})
var api = v1API.NewAPI(queryEngine, storage, nil, nil)
api.Register(router.WithPrefix(apiRoute))
log.Infof("Listening on %s, will connect to OpenTSDB at %s", config.listenAddr, config.openTSDBurl)
log.Fatal(http.ListenAndServe(config.listenAddr, router))
}