diff --git a/Gopkg.toml b/Gopkg.toml index e7082076bf..9eb6414438 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -4,6 +4,7 @@ required = [ "github.com/mwitkow/go-proto-validators/protoc-gen-govalidators", "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway", "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger", + "github.com/go-openapi/runtime/client", "github.com/go-openapi/spec", "github.com/go-swagger/go-swagger/cmd/swagger", "github.com/BurntSushi/go-sumtype", diff --git a/api/serverpb/json/client/server/logs_parameters.go b/api/serverpb/json/client/server/logs_parameters.go new file mode 100644 index 0000000000..8ea4cd432f --- /dev/null +++ b/api/serverpb/json/client/server/logs_parameters.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package server + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewLogsParams creates a new LogsParams object +// with the default values initialized. +func NewLogsParams() *LogsParams { + + return &LogsParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewLogsParamsWithTimeout creates a new LogsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewLogsParamsWithTimeout(timeout time.Duration) *LogsParams { + + return &LogsParams{ + + timeout: timeout, + } +} + +// NewLogsParamsWithContext creates a new LogsParams object +// with the default values initialized, and the ability to set a context for a request +func NewLogsParamsWithContext(ctx context.Context) *LogsParams { + + return &LogsParams{ + + Context: ctx, + } +} + +// NewLogsParamsWithHTTPClient creates a new LogsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewLogsParamsWithHTTPClient(client *http.Client) *LogsParams { + + return &LogsParams{ + HTTPClient: client, + } +} + +/*LogsParams contains all the parameters to send to the API endpoint +for the logs operation typically these are written to a http.Request +*/ +type LogsParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the logs params +func (o *LogsParams) WithTimeout(timeout time.Duration) *LogsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the logs params +func (o *LogsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the logs params +func (o *LogsParams) WithContext(ctx context.Context) *LogsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the logs params +func (o *LogsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the logs params +func (o *LogsParams) WithHTTPClient(client *http.Client) *LogsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the logs params +func (o *LogsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *LogsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/serverpb/json/client/server/logs_responses.go b/api/serverpb/json/client/server/logs_responses.go new file mode 100644 index 0000000000..cc15652a7f --- /dev/null +++ b/api/serverpb/json/client/server/logs_responses.go @@ -0,0 +1,156 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package server + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/swag" + + strfmt "github.com/go-openapi/strfmt" +) + +// LogsReader is a Reader for the Logs structure. +type LogsReader struct { + formats strfmt.Registry + writer io.Writer +} + +// ReadResponse reads a server response into the received o. +func (o *LogsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewLogsOK(o.writer) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewLogsDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewLogsOK creates a LogsOK with default headers values +func NewLogsOK(writer io.Writer) *LogsOK { + return &LogsOK{ + Payload: writer, + } +} + +/*LogsOK handles this case with default header values. + +A successful response. +*/ +type LogsOK struct { + Payload io.Writer +} + +func (o *LogsOK) Error() string { + return fmt.Sprintf("[GET /logs.zip][%d] logsOk %+v", 200, o.Payload) +} + +func (o *LogsOK) GetPayload() io.Writer { + return o.Payload +} + +func (o *LogsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewLogsDefault creates a LogsDefault with default headers values +func NewLogsDefault(code int) *LogsDefault { + return &LogsDefault{ + _statusCode: code, + } +} + +/*LogsDefault handles this case with default header values. + +An error response. +*/ +type LogsDefault struct { + _statusCode int + + Payload *LogsDefaultBody +} + +// Code gets the status code for the logs default response +func (o *LogsDefault) Code() int { + return o._statusCode +} + +func (o *LogsDefault) Error() string { + return fmt.Sprintf("[GET /logs.zip][%d] Logs default %+v", o._statusCode, o.Payload) +} + +func (o *LogsDefault) GetPayload() *LogsDefaultBody { + return o.Payload +} + +func (o *LogsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(LogsDefaultBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +/*LogsDefaultBody ErrorResponse is a message returned on HTTP error. +swagger:model LogsDefaultBody +*/ +type LogsDefaultBody struct { + + // code + Code int32 `json:"code,omitempty"` + + // error + Error string `json:"error,omitempty"` + + // message + Message string `json:"message,omitempty"` +} + +// Validate validates this logs default body +func (o *LogsDefaultBody) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (o *LogsDefaultBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *LogsDefaultBody) UnmarshalBinary(b []byte) error { + var res LogsDefaultBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/api/serverpb/json/client/server/server_client.go b/api/serverpb/json/client/server/server_client.go index b7d583cff5..a3b7b538ff 100644 --- a/api/serverpb/json/client/server/server_client.go +++ b/api/serverpb/json/client/server/server_client.go @@ -6,6 +6,8 @@ package server // Editing this file might prove futile when you re-run the swagger generate command import ( + "io" + "github.com/go-openapi/runtime" strfmt "github.com/go-openapi/strfmt" @@ -156,6 +158,39 @@ func (a *Client) GetSettings(params *GetSettingsParams) (*GetSettingsOK, error) return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +Logs logs returns logs of the PMM server +*/ +func (a *Client) Logs(params *LogsParams, writer io.Writer) (*LogsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewLogsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "Logs", + Method: "GET", + PathPattern: "/logs.zip", + ProducesMediaTypes: []string{"application/zip"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http", "https"}, + Params: params, + Reader: &LogsReader{formats: a.formats, writer: writer}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*LogsOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*LogsDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* Readiness readinesses returns an error when some PMM server component is not ready yet or is being restarted it can be used as for docker health check or kubernetes readiness probe */ diff --git a/api/serverpb/json/header.json b/api/serverpb/json/header.json index 913d2b4271..713763f73f 100644 --- a/api/serverpb/json/header.json +++ b/api/serverpb/json/header.json @@ -8,6 +8,45 @@ "https", "http" ], + "paths": { + "/logs.zip": { + "get": { + "tags": [ + "Server" + ], + "summary": "Logs returns logs of the PMM-Server.", + "operationId": "Logs", + "produces": ["application/zip"], + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "type": "file" + } + }, + "default": { + "description": "An error response.", + "schema": { + "description": "ErrorResponse is a message returned on HTTP error.", + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "error": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } + } + } + } + } + }, "definitions": { "serverpbErrorResponse": { "description": "ErrorResponse is a message returned on HTTP error.", diff --git a/api/serverpb/json/serverpb.json b/api/serverpb/json/serverpb.json index 5a93ba7f9a..77c1e644f7 100644 --- a/api/serverpb/json/serverpb.json +++ b/api/serverpb/json/serverpb.json @@ -15,6 +15,45 @@ "version": "v1" }, "paths": { + "/logs.zip": { + "get": { + "produces": [ + "application/zip" + ], + "tags": [ + "Server" + ], + "summary": "Logs returns logs of the PMM-Server.", + "operationId": "Logs", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "type": "file" + } + }, + "default": { + "description": "An error response.", + "schema": { + "description": "ErrorResponse is a message returned on HTTP error.", + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "error": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } + } + } + } + }, "/v1/AWSInstanceCheck": { "post": { "tags": [ diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index ec37cca3b0..463bfd6ee3 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -15,6 +15,45 @@ "version": "public" }, "paths": { + "/logs.zip": { + "get": { + "produces": [ + "application/zip" + ], + "tags": [ + "Server" + ], + "summary": "Logs returns logs of the PMM-Server.", + "operationId": "Logs", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "type": "file" + } + }, + "default": { + "description": "An error response.", + "schema": { + "description": "ErrorResponse is a message returned on HTTP error.", + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "error": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } + } + } + } + }, "/v1/AWSInstanceCheck": { "post": { "tags": [