Skip to content

Commit

Permalink
monitor: set default influxdb datasource by endpoint type
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi committed Oct 23, 2020
1 parent 3c1cd88 commit 5d873dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
18 changes: 12 additions & 6 deletions pkg/monitor/models/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"yunion.io/x/pkg/tristate"
"yunion.io/x/pkg/util/wait"

identityapi "yunion.io/x/onecloud/pkg/apis/identity"
"yunion.io/x/onecloud/pkg/apis/monitor"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/httperrors"
Expand Down Expand Up @@ -87,25 +86,32 @@ func (man *SDataSourceManager) Run(ctx context.Context) error {

func (man *SDataSourceManager) initDefaultDataSource(ctx context.Context) error {
region := options.Options.Region
epType := options.Options.SessionEndpointType
initF := func() {
ds, err := man.GetDefaultSource()
if err != nil && err != ErrDataSourceDefaultNotFound {
log.Errorf("Get default datasource: %v", err)
return
}
if ds != nil {
return
}
s := auth.GetAdminSessionWithPublic(ctx, region, "")
s := auth.GetAdminSession(ctx, region, "")
if s == nil {
log.Errorf("get empty public session for region %s", region)
return
}
url, err := s.GetServiceURL("influxdb", identityapi.EndpointInterfacePublic)
url, err := s.GetServiceURL("influxdb", epType)
if err != nil {
log.Errorf("get influxdb public url: %v", err)
return
}
if ds != nil {
if _, err := db.Update(ds, func() error {
ds.Url = url
return nil
}); err != nil {
log.Errorf("update datasource url error: %v", err)
}
return
}
ds = &SDataSource{
Type: monitor.DataSourceTypeInfluxdb,
Url: url,
Expand Down
10 changes: 10 additions & 0 deletions pkg/monitor/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"net"
"net/http"
_ "net/http/pprof"
"strconv"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -112,4 +113,13 @@ func addMiscHandlers(root *mux.Router) {
}
}
root.HandleFunc("/subscriptions/write", adapterF(performHandler))

// ref: pkg/appsrv/appsrv:addDefaultHandlers
root.HandleFunc("/version", adapterF(appsrv.VersionHandler))
root.HandleFunc("/stats", adapterF(appsrv.StatisticHandler))
root.HandleFunc("/ping", adapterF(appsrv.PingHandler))
root.HandleFunc("/worker_stats", adapterF(appsrv.WorkerStatsHandler))

// pprof handler
root.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
}
8 changes: 2 additions & 6 deletions pkg/webconsole/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"net"
"net/http"
"net/http/pprof"
_ "net/http/pprof"
"net/url"
"os"
"strconv"
Expand Down Expand Up @@ -133,9 +133,5 @@ func addMiscHandlers(root *mux.Router) {
root.HandleFunc("/worker_stats", adapterF(appsrv.WorkerStatsHandler))

// pprof handler
root.HandleFunc("/debug/pprof/", pprof.Index)
root.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
root.HandleFunc("/debug/pprof/profile", pprof.Profile)
root.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
root.HandleFunc("/debug/pprof/trace", pprof.Trace)
root.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
}

0 comments on commit 5d873dd

Please sign in to comment.