diff --git a/cli/cdsctl/admin.go b/cli/cdsctl/admin.go index 85ff32e194..d13ea1e037 100644 --- a/cli/cdsctl/admin.go +++ b/cli/cdsctl/admin.go @@ -23,7 +23,6 @@ func adminCommands() []*cobra.Command { adminMigrations(), adminPlugins(), adminBroadcasts(), - adminErrors(), adminCurl(), adminFeatures(), adminWorkflows(), diff --git a/cli/cdsctl/admin_errors.go b/cli/cdsctl/admin_errors.go deleted file mode 100644 index 7a32672008..0000000000 --- a/cli/cdsctl/admin_errors.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/ovh/cds/cli" -) - -var adminErrorsCmd = cli.Command{ - Name: "errors", - Aliases: []string{"error"}, - Short: "Manage CDS errors", -} - -func adminErrors() *cobra.Command { - return cli.NewCommand(adminErrorsCmd, nil, []*cobra.Command{ - cli.NewCommand(adminErrorsGetCmd, adminErrorsGetFunc, nil), - }) -} - -var adminErrorsGetCmd = cli.Command{ - Name: "get", - Short: "Get CDS errors for given request id", - Args: []cli.Arg{ - {Name: "request-id"}, - }, -} - -func adminErrorsGetFunc(v cli.Values) error { - res, err := client.MonErrorsGet(v.GetString("request-id")) - if err != nil { - return err - } - - for i := range res { - fmt.Printf("Message[%d]: %s\n", i, res[i].Message) - if res[i].StackTrace != "" { - fmt.Printf("Stack trace[%d]:\n%s", i, res[i].StackTrace) - } - } - - return nil -} diff --git a/cli/cdsctl/worker_model.go b/cli/cdsctl/worker_model.go index fafd82aa4e..f4b3b6ea6f 100644 --- a/cli/cdsctl/worker_model.go +++ b/cli/cdsctl/worker_model.go @@ -62,8 +62,6 @@ func newWorkerModelDisplay(wm sdk.Model) workerModelDisplay { name := wm.Name if wm.Group != nil { name = fmt.Sprintf("%s/%s", wm.Group.Name, wm.Name) - } else { - name = wm.Name } var image, flavor string diff --git a/engine/api/api.go b/engine/api/api.go index 0fbed2f846..15baa88603 100644 --- a/engine/api/api.go +++ b/engine/api/api.go @@ -197,12 +197,7 @@ type Configuration struct { } `toml:"artifact" comment:"Either filesystem local storage or Openstack Swift Storage are supported" json:"artifact"` DefaultOS string `toml:"defaultOS" default:"linux" comment:"if no model and os/arch is specified in your job's requirements then spawn worker on this operating system (example: darwin, freebsd, linux, windows)" json:"defaultOS"` DefaultArch string `toml:"defaultArch" default:"amd64" comment:"if no model and no os/arch is specified in your job's requirements then spawn worker on this architecture (example: amd64, arm, 386)" json:"defaultArch"` - Graylog struct { - AccessToken string `toml:"accessToken" json:"-"` - Stream string `toml:"stream" json:"-"` - URL string `toml:"url" comment:"Example: http://localhost:9000" json:"url"` - } `toml:"graylog" json:"graylog" comment:"###########################\n Graylog Search. \n When CDS API generates errors, you can fetch them with cdsctl. \n Examples: \n $ cdsctl admin errors get \n $ cdsctl admin errors get 55f6e977-d39b-11e8-8513-0242ac110007 \n##########################"` - Log struct { + Log struct { StepMaxSize int64 `toml:"stepMaxSize" default:"15728640" comment:"Max step logs size in bytes (default: 15MB)" json:"stepMaxSize"` ServiceMaxSize int64 `toml:"serviceMaxSize" default:"15728640" comment:"Max service logs size in bytes (default: 15MB)" json:"serviceMaxSize"` } `toml:"log" json:"log" comment:"###########################\n Log settings.\n##########################"` diff --git a/engine/api/api_routes.go b/engine/api/api_routes.go index af56ce0976..19c2002387 100644 --- a/engine/api/api_routes.go +++ b/engine/api/api_routes.go @@ -141,7 +141,6 @@ func (api *API) InitRouter() { r.Handle("/mon/metrics", ScopeNone(), r.GET(service.GetPrometheustMetricsHandler(api), service.OverrideAuth(service.NoAuthMiddleware))) r.Handle("/mon/metrics/all", ScopeNone(), r.GET(service.GetMetricsHandler, service.OverrideAuth(service.NoAuthMiddleware))) r.HandlePrefix("/mon/metrics/detail/", ScopeNone(), r.GET(service.GetMetricHandler("/mon/metrics/detail/"), service.OverrideAuth(service.NoAuthMiddleware))) - r.Handle("/mon/errors/{uuid}", ScopeNone(), r.GET(api.getErrorHandler, service.OverrideAuth(api.authAdminMiddleware))) r.Handle("/help", ScopeNone(), r.GET(api.getHelpHandler, service.OverrideAuth(service.NoAuthMiddleware))) diff --git a/engine/api/error.go b/engine/api/error.go deleted file mode 100644 index 14b3c3bc7b..0000000000 --- a/engine/api/error.go +++ /dev/null @@ -1,76 +0,0 @@ -package api - -import ( - "context" - "fmt" - "io" - "net/http" - "time" - - "github.com/gorilla/mux" - - "github.com/ovh/cds/engine/service" - "github.com/ovh/cds/sdk" -) - -type graylogResponse struct { - TotalResult int `json:"total_results"` - Messages []struct { - Message map[string]interface{} `json:"message"` - } `json:"messages"` -} - -func (api *API) getErrorHandler() service.Handler { - return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { - vars := mux.Vars(r) - id := vars["request_id"] - - if api.Config.Graylog.URL == "" || api.Config.Graylog.AccessToken == "" { - return sdk.WithStack(sdk.ErrNotFound) - } - - req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/search/universal/absolute", api.Config.Graylog.URL), nil) - if err != nil { - return sdk.WrapError(err, "invalid given Graylog url") - } - - q := req.URL.Query() - q.Add("query", fmt.Sprintf("request_id:%s", id)) - q.Add("from", "1970-01-01 00:00:00.000") - q.Add("to", time.Now().Format("2006-01-02 15:04:05")) - q.Add("filter", fmt.Sprintf("streams:%s", api.Config.Graylog.Stream)) - req.URL.RawQuery = q.Encode() - - req.SetBasicAuth(api.Config.Graylog.AccessToken, "token") - resp, err := http.DefaultClient.Do(req) - if err != nil { - return sdk.WrapError(err, "cannot send query to Graylog") - } - - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - if err != nil { - return sdk.WrapError(err, "cannot read response from Graylog") - } - - var res graylogResponse - if err := sdk.JSONUnmarshal(body, &res); err != nil { - return sdk.WrapError(err, "cannot unmarshal response from Graylog") - } - - if res.TotalResult < 1 { - return sdk.WithStack(sdk.ErrNotFound) - } - - logs := make([]sdk.Error, res.TotalResult) - for i := range res.Messages { - logs[i].RequestID = res.Messages[i].Message["request_id"].(string) - logs[i].Message = res.Messages[i].Message["message"].(string) - if st, ok := res.Messages[i].Message["stack_trace"]; ok { - logs[i].StackTrace = st.(string) - } - } - - return service.WriteJSON(w, logs, http.StatusOK) - } -} diff --git a/sdk/cdsclient/client_mon.go b/sdk/cdsclient/client_mon.go index 22d979e4fa..8375de767e 100644 --- a/sdk/cdsclient/client_mon.go +++ b/sdk/cdsclient/client_mon.go @@ -2,7 +2,6 @@ package cdsclient import ( "context" - "fmt" "github.com/ovh/cds/sdk" ) @@ -30,17 +29,3 @@ func (c *client) MonDBMigrate() ([]sdk.MonDBMigrate, error) { } return monDBMigrate, nil } - -func (c *client) MonErrorsGet(requestID string) ([]sdk.Error, error) { - res, _, _, err := c.Request(context.Background(), "GET", fmt.Sprintf("/mon/errors/%s", requestID), nil) - if err != nil { - return nil, err - } - - var errs []sdk.Error - if err := sdk.JSONUnmarshal(res, &errs); err != nil { - return nil, err - } - - return errs, nil -} diff --git a/sdk/cdsclient/interface.go b/sdk/cdsclient/interface.go index 44c83cc1de..0b4510746c 100644 --- a/sdk/cdsclient/interface.go +++ b/sdk/cdsclient/interface.go @@ -367,7 +367,6 @@ type MonitoringClient interface { MonStatus() (*sdk.MonitoringStatus, error) MonVersion() (*sdk.Version, error) MonDBMigrate() ([]sdk.MonDBMigrate, error) - MonErrorsGet(requestID string) ([]sdk.Error, error) } // IntegrationClient exposes integration functions diff --git a/sdk/cdsclient/mock_cdsclient/interface_mock.go b/sdk/cdsclient/mock_cdsclient/interface_mock.go index 8fdb3f476e..3f938a0ccc 100644 --- a/sdk/cdsclient/mock_cdsclient/interface_mock.go +++ b/sdk/cdsclient/mock_cdsclient/interface_mock.go @@ -4533,21 +4533,6 @@ func (mr *MockMonitoringClientMockRecorder) MonDBMigrate() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MonDBMigrate", reflect.TypeOf((*MockMonitoringClient)(nil).MonDBMigrate)) } -// MonErrorsGet mocks base method. -func (m *MockMonitoringClient) MonErrorsGet(requestID string) ([]sdk.Error, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "MonErrorsGet", requestID) - ret0, _ := ret[0].([]sdk.Error) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// MonErrorsGet indicates an expected call of MonErrorsGet. -func (mr *MockMonitoringClientMockRecorder) MonErrorsGet(requestID interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MonErrorsGet", reflect.TypeOf((*MockMonitoringClient)(nil).MonErrorsGet), requestID) -} - // MonStatus mocks base method. func (m *MockMonitoringClient) MonStatus() (*sdk.MonitoringStatus, error) { m.ctrl.T.Helper() @@ -6275,21 +6260,6 @@ func (mr *MockInterfaceMockRecorder) MonDBMigrate() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MonDBMigrate", reflect.TypeOf((*MockInterface)(nil).MonDBMigrate)) } -// MonErrorsGet mocks base method. -func (m *MockInterface) MonErrorsGet(requestID string) ([]sdk.Error, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "MonErrorsGet", requestID) - ret0, _ := ret[0].([]sdk.Error) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// MonErrorsGet indicates an expected call of MonErrorsGet. -func (mr *MockInterfaceMockRecorder) MonErrorsGet(requestID interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MonErrorsGet", reflect.TypeOf((*MockInterface)(nil).MonErrorsGet), requestID) -} - // MonStatus mocks base method. func (m *MockInterface) MonStatus() (*sdk.MonitoringStatus, error) { m.ctrl.T.Helper()