Skip to content

Commit

Permalink
Merge #472
Browse files Browse the repository at this point in the history
472: feat(http): Distinct app and internal error codes in the handleError function r=48d90782 a=48d90782

This PR introduces distinct error codes for the app and internal RR errors.
Errors: 
```go
roadrunner.ErrNoAssociatedPool
roadrunner.ErrAllocateWorker
roadrunner.ErrWorkerNotReady
roadrunner.ErrEmptyPayload
roadrunner.ErrPoolStopped
roadrunner.ErrWorkerAllocateTimeout
roadrunner.ErrAllWorkersAreDead
```
now associated with the internal error codes. All other errors are application errors.
Some types of errors are impossible to distinguish in the RR1, for example `json.Unmarshall` internal error or similar.
The `.rr.yaml` now contain two more options for the errors.
```yaml
http:
    internalErrorCode: 502,
    appErrorCode: 502
```
Default behavior unchanged (500 error code as before), but now might be overridden.
closes #471 

Co-authored-by: Valery Piashchynski <[email protected]>
  • Loading branch information
bors[bot] and rustatian authored Jan 13, 2021
2 parents 5dc83ef + bbfcd4f commit f18e7f6
Show file tree
Hide file tree
Showing 85 changed files with 349 additions and 203 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,19 @@ jobs:
file: ./coverage-ci/summary.txt
fail_ci_if_error: false

golangci-check:

golangci-lint:
name: Golang-CI (lint)
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: golangci-lint
uses: reviewdog/action-golangci-lint@v1 # action page: <https://github.com/reviewdog/action-golangci-lint>
- name: Run linter
uses: golangci/golangci-lint-action@v2 # Action page: <https://github.com/golangci/golangci-lint-action>
with:
github_token: ${{ secrets.github_token }}
version: v1.35 # without patch version
only-new-issues: false # show only new issues if it's a pull request

image:
name: Build docker image
Expand Down
17 changes: 9 additions & 8 deletions .rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@ metrics:
http:
# http host to listen.
address: 0.0.0.0:8080
# override http error code for the application errors (default 500)
appErrorCode: 505
# override http error code for the internal RR errors (default 500)
internalErrorCode: 505

ssl:
# custom https port (default 443)
port: 443

port: 443
# force redirect to https connection
redirect: true

# ssl cert
cert: server.crt

cert: server.crt
# ssl private key
key: server.key

key: server.key
# rootCA certificate
rootCa: root.crt
rootCa: root.crt


# HTTP service provides FastCGI as frontend
fcgi:
Expand Down
2 changes: 1 addition & 1 deletion bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ status = [
'Build docker image',
]

required_approvals = 1
required_approvals = 0
delete_merged_branches = true
timeout-sec = 1800
9 changes: 5 additions & 4 deletions cmd/rr/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
package cmd

import (
"log"
"net/http"
"net/http/pprof"
"os"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spiral/roadrunner/cmd/util"
"github.com/spiral/roadrunner/service"
"github.com/spiral/roadrunner/service/limit"
"log"
"net/http"
"net/http/pprof"
"os"
)

// Services bus for all the commands.
Expand Down
3 changes: 2 additions & 1 deletion cmd/rr/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
package cmd

import (
"github.com/spf13/cobra"
"os"
"os/signal"
"sync"
"syscall"

"github.com/spf13/cobra"
)

func init() {
Expand Down
9 changes: 5 additions & 4 deletions cmd/rr/http/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package http

import (
"fmt"
"net"
"net/http"
"strings"
"time"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spiral/roadrunner"
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
"github.com/spiral/roadrunner/cmd/util"
rrhttp "github.com/spiral/roadrunner/service/http"
"net"
"net/http"
"strings"
"time"
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions cmd/rr/http/metrics.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package http

import (
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cobra"
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
rrhttp "github.com/spiral/roadrunner/service/http"
"github.com/spiral/roadrunner/service/metrics"
"github.com/spiral/roadrunner/util"
"strconv"
"time"
)

func init() {
Expand Down
11 changes: 6 additions & 5 deletions cmd/rr/http/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
package http

import (
tm "github.com/buger/goterm"
"github.com/spf13/cobra"
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
"github.com/spiral/roadrunner/cmd/util"
"github.com/spiral/roadrunner/service/http"
"net/rpc"
"os"
"os/signal"
"syscall"
"time"

tm "github.com/buger/goterm"
"github.com/spf13/cobra"
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
"github.com/spiral/roadrunner/cmd/util"
"github.com/spiral/roadrunner/service/http"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions cmd/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package util
import (
"bytes"
"fmt"
"github.com/spf13/viper"
"github.com/spiral/roadrunner/service"
"os"
"path/filepath"
"strings"

"github.com/spf13/viper"
"github.com/spiral/roadrunner/service"
)

// ConfigWrapper provides interface bridge between v configs and service.Config.
Expand Down
3 changes: 2 additions & 1 deletion cmd/util/cprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package util

import (
"fmt"
"github.com/mgutz/ansi"
"os"
"regexp"
"strings"

"github.com/mgutz/ansi"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/util/debug.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package util

import (
"strings"

"github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
"strings"
)

// LogEvent outputs rr event into given logger and return false if event was not handled.
Expand Down
3 changes: 2 additions & 1 deletion cmd/util/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package util

import (
"errors"
"net/rpc"

"github.com/spiral/roadrunner/service"
rrpc "github.com/spiral/roadrunner/service/rpc"
"net/rpc"
)

// RPCClient returns RPC client associated with given rr service container.
Expand Down
7 changes: 4 additions & 3 deletions cmd/util/table.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package util

import (
"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"
rrutil "github.com/spiral/roadrunner/util"
"os"
"strconv"
"time"

"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"
rrutil "github.com/spiral/roadrunner/util"
)

// WorkerTable renders table with information about rr server workers.
Expand Down
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (

// Config defines basic behaviour of worker creation and handling process.
type Config struct {
// Error code for pool errors in the http handler (default 500)
PoolErrorCode uint64

// NumWorkers defines how many sub-processes can be run at once. This value
// might be doubled by Swapper while hot-swap.
NumWorkers int64
Expand Down
3 changes: 2 additions & 1 deletion config_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package roadrunner

import (
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func Test_NumWorkers(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ type Controller interface {
type Attacher interface {
// Attach attaches controller to the service.
Attach(c Controller)
}
}
3 changes: 2 additions & 1 deletion controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package roadrunner

import (
"fmt"
"github.com/stretchr/testify/assert"
"runtime"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

type eWatcher struct {
Expand Down
3 changes: 2 additions & 1 deletion error_buffer_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package roadrunner

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestErrBuffer_Write_Len(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package roadrunner

import (
"errors"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_JobError_Error(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion osutil/isolate_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func IsolateProcess(cmd *exec.Cmd) {

func ExecuteFromUser(cmd *exec.Cmd, u string) error {
return nil
}
}
3 changes: 2 additions & 1 deletion pipe_factory_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package roadrunner

import (
"github.com/stretchr/testify/assert"
"os/exec"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func Test_Pipe_Start(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package roadrunner

import (
"fmt"
"os"

json "github.com/json-iterator/go"
"github.com/spiral/goridge/v2"
"os"
)

type stopCommand struct {
Expand Down
3 changes: 2 additions & 1 deletion protocol_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package roadrunner

import (
"testing"

"github.com/pkg/errors"
"github.com/spiral/goridge/v2"
"github.com/stretchr/testify/assert"
"testing"
)

type relayMock struct {
Expand Down
8 changes: 5 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package roadrunner

import (
"fmt"
"github.com/pkg/errors"
"sync"

"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -133,11 +133,13 @@ func (s *Server) Stop() {
s.throw(EventServerStop, s)
}

var ErrNoAssociatedPool = errors.New("no associared pool")

// Exec one task with given payload and context, returns result or error.
func (s *Server) Exec(rqs *Payload) (rsp *Payload, err error) {
pool := s.Pool()
if pool == nil {
return nil, fmt.Errorf("no associared pool")
return nil, ErrNoAssociatedPool
}

return pool.Exec(rqs)
Expand Down
3 changes: 2 additions & 1 deletion server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package roadrunner
import (
"errors"
"fmt"
"github.com/spiral/roadrunner/osutil"
"net"
"os"
"os/exec"
"strings"
"sync"
"syscall"
"time"

"github.com/spiral/roadrunner/osutil"
)

// CommandProducer can produce commands.
Expand Down
3 changes: 2 additions & 1 deletion server_config_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package roadrunner

import (
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func Test_ServerConfig_PipeFactory(t *testing.T) {
Expand Down
Loading

0 comments on commit f18e7f6

Please sign in to comment.