+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea/
/static/
/data*
/tmp
34 changes: 14 additions & 20 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ type Api struct {

authSecret string
authAnonymousRole rbac.RoleName

deploymentUuid string
instanceUuid string
}

func NewApi(cache *cache.Cache, db *db.DB, collector *collector.Collector, pricing *pricing.Manager, roles rbac.RoleManager,
globalClickHouse *db.IntegrationClickhouse, globalPrometheus *db.IntegrationPrometheus) *Api {
globalClickHouse *db.IntegrationClickhouse, globalPrometheus *db.IntegrationPrometheus,
deploymentUuid, instanceUuid string) *Api {
return &Api{
cache: cache,
db: db,
Expand All @@ -54,6 +58,8 @@ func NewApi(cache *cache.Cache, db *db.DB, collector *collector.Collector, prici
roles: roles,
globalClickHouse: globalClickHouse,
globalPrometheus: globalPrometheus,
deploymentUuid: deploymentUuid,
instanceUuid: instanceUuid,
}
}

Expand Down Expand Up @@ -371,7 +377,7 @@ func (api *Api) Overview(w http.ResponseWriter, r *http.Request, u *db.User) {
}
defer ch.Close()
auditor.Audit(world, project, nil, project.ClickHouseConfig(api.globalClickHouse) != nil, nil)
utils.WriteJson(w, api.WithContext(project, cacheStatus, world, views.Overview(r.Context(), ch, world, view, r.URL.Query().Get("query"))))
utils.WriteJson(w, api.WithContext(project, cacheStatus, world, views.Overview(r.Context(), ch, project, world, view, r.URL.Query().Get("query"))))
}

func (api *Api) Dashboards(w http.ResponseWriter, r *http.Request, u *db.User) {
Expand Down Expand Up @@ -488,7 +494,7 @@ func (api *Api) PanelData(w http.ResponseWriter, r *http.Request, u *db.User) {
http.Error(w, "", http.StatusInternalServerError)
return
}
from, to := api.getTimeContext(r)
from, to, _ := api.getTimeContext(r)
step := increaseStepForBigDurations(from, to, promConfig.RefreshInterval)
data, err := views.Dashboards.PanelData(r.Context(), promClient, config, from, to, step)
if err != nil {
Expand Down Expand Up @@ -936,21 +942,8 @@ func (api *Api) Application(w http.ResponseWriter, r *http.Request, u *db.User)
app.AddReport(model.AuditReportProfiling, &model.Widget{Profiling: &model.Profiling{ApplicationId: app.Id}, Width: "100%"})
app.AddReport(model.AuditReportTracing, &model.Widget{Tracing: &model.Tracing{ApplicationId: app.Id}, Width: "100%"})
}
utils.WriteJson(w, api.WithContext(project, cacheStatus, world, views.Application(world, app)))
}

func (api *Api) RCA(w http.ResponseWriter, r *http.Request, u *db.User) {
world, project, cacheStatus, err := api.LoadWorldByRequest(r)
if err != nil {
klog.Errorln(err)
http.Error(w, "", http.StatusInternalServerError)
return
}
if project == nil || world == nil {
utils.WriteJson(w, api.WithContext(project, cacheStatus, world, nil))
return
}
utils.WriteJson(w, api.WithContext(project, cacheStatus, world, "not implemented"))
utils.WriteJson(w, api.WithContext(project, cacheStatus, world, views.Application(project, world, app)))
}

func (api *Api) Incidents(w http.ResponseWriter, r *http.Request, u *db.User) {
Expand Down Expand Up @@ -1583,7 +1576,7 @@ func (api *Api) LoadWorldByRequest(r *http.Request) (*model.World, *db.Project,
return nil, nil, nil, err
}

from, to := api.getTimeContext(r)
from, to, _ := api.getTimeContext(r)
world, cacheStatus, err := api.LoadWorld(r.Context(), project, from, to)
if world == nil {
step := increaseStepForBigDurations(from, to, 15*timeseries.Second)
Expand All @@ -1592,7 +1585,7 @@ func (api *Api) LoadWorldByRequest(r *http.Request) (*model.World, *db.Project,
return world, project, cacheStatus, err
}

func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timeseries.Time) {
func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timeseries.Time, incident *model.ApplicationIncident) {
now := timeseries.Now()
q := r.URL.Query()
from = utils.ParseTime(now, q.Get("from"), now.Add(-timeseries.Hour))
Expand All @@ -1603,7 +1596,8 @@ func (api *Api) getTimeContext(r *http.Request) (from timeseries.Time, to timese
incidentKey := q.Get("incident")
if incidentKey != "" {
projectId := db.ProjectId(mux.Vars(r)["project"])
if incident, err := api.db.GetIncidentByKey(projectId, incidentKey); err != nil {
var err error
if incident, err = api.db.GetIncidentByKey(projectId, incidentKey); err != nil {
klog.Warningln("failed to get incident:", err)
} else {
from = incident.OpenedAt.Add(-model.IncidentTimeOffset)
Expand Down
79 changes: 79 additions & 0 deletions api/cloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package api

import (
"net/http"

"github.com/coroot/coroot/api/forms"
"github.com/coroot/coroot/cloud"
"github.com/coroot/coroot/db"
"github.com/coroot/coroot/rbac"
"github.com/coroot/coroot/utils"
"k8s.io/klog"
)

type CloudIntegrationForm struct {
ApiKey string `json:"api_key"`
IncidentsAutoInvestigation bool `json:"incidents_auto_investigation"`
}

func (f *CloudIntegrationForm) Valid() bool {
return true
}

func (api *Api) Cloud(w http.ResponseWriter, r *http.Request, u *db.User) {
if !api.IsAllowed(u, rbac.Actions.Settings().Edit()) {
http.Error(w, "You are not allowed to edit global settings.", http.StatusForbidden)
return
}

cloudAPI := cloud.API(api.db, api.deploymentUuid, api.instanceUuid, r.Referer())
settings, err := cloudAPI.GetSettings()
if err != nil {
klog.Errorln(err)
http.Error(w, "", http.StatusInternalServerError)
return
}

if query := r.URL.Query().Get("query"); query == "status" {
status := "unconfigured"
if settings.ApiKey != "" {
status = "configured"
}
utils.WriteJson(w, map[string]string{"status": status})
return
}

if r.Method == http.MethodPost {
var form CloudIntegrationForm
if err = forms.ReadAndValidate(r, &form); err != nil {
klog.Warningln("bad request:", err)
http.Error(w, "", http.StatusBadRequest)
return
}
settings.ApiKey = form.ApiKey
settings.RCA.DisableIncidentsAutoInvestigation = !form.IncidentsAutoInvestigation
if err = cloudAPI.SaveSettings(settings); err != nil {
klog.Errorln(err)
http.Error(w, "", http.StatusInternalServerError)
return
}
return
}

info, err := cloudAPI.IntegrationInfo(r.Context())
if err != nil {
klog.Errorln(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

res := struct {
Form CloudIntegrationForm `json:"form"`
Info cloud.IntegrationInfo `json:"info"`
}{
Info: *info,
}
res.Form.ApiKey = settings.ApiKey
res.Form.IncidentsAutoInvestigation = !settings.RCA.DisableIncidentsAutoInvestigation
utils.WriteJson(w, res)
}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载