Compare commits

...

5 Commits

Author SHA1 Message Date
cuinix
a9e64d078c
Merge 0f0a4dcf20f8db20ebbc79b12c75fb865032222d into b36f3834eb5cefbd25c85777df9b362ddc6c2820 2024-03-20 16:33:33 +08:00
fatedier
b36f3834eb
use math/rand/v2 (#4020) 2024-03-20 15:48:31 +08:00
fatedier
c08be0fd92
update release notes (#4086) 2024-03-20 15:16:01 +08:00
Kaive Young
bc5fb91c05
add header for http healthcheck (#4085) 2024-03-20 14:58:03 +08:00
cuinix
0f0a4dcf20 fix function name in comment
Signed-off-by: cuinix <915115094@qq.com>
2024-03-06 15:49:06 +08:00
11 changed files with 41 additions and 28 deletions

View File

@ -23,7 +23,7 @@ jobs:
uses: golangci/golangci-lint-action@v4
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.56
version: v1.57
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

View File

@ -1,5 +1,5 @@
service:
golangci-lint-version: 1.56.x # use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: 1.57.x # use the fixed version to not introduce new linters unexpectedly
run:
concurrency: 4
@ -8,23 +8,6 @@ run:
build-tags:
- integ
- integfuzz
# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- genfiles$
- vendor$
- bin$
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- ".*\\.pb\\.go"
- ".*\\.gen\\.go"
linters:
disable-all: true
@ -136,6 +119,14 @@ issues:
- unparam
text: "is always false"
exclude-dirs:
- genfiles$
- vendor$
- bin$
exclude-files:
- ".*\\.pb\\.go"
- ".*\\.gen\\.go"
# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.

View File

@ -16,6 +16,8 @@
This will create 8 proxies such as `tcp-6000, tcp-6001, ... tcp-6007`.
* Health check supports custom request headers.
### Fixes
* Fix the issue of incorrect interval time for rotating the log by day.

View File

@ -232,7 +232,7 @@ func (ctl *Control) registerMsgHandlers() {
ctl.msgDispatcher.RegisterHandler(&msg.Pong{}, ctl.handlePong)
}
// headerWorker sends heartbeat to server and check heartbeat timeout.
// heartbeatWorker sends heartbeat to server and check heartbeat timeout.
func (ctl *Control) heartbeatWorker() {
xl := ctl.xl

View File

@ -41,7 +41,7 @@ type Monitor struct {
// For http
url string
header http.Header
failedTimes uint64
statusOK bool
statusNormalFn func()
@ -73,6 +73,11 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
}
url = s + cfg.Path
}
header := make(http.Header)
for _, h := range cfg.HTTPHeaders {
header.Set(h.Name, h.Value)
}
return &Monitor{
checkType: cfg.Type,
interval: time.Duration(cfg.IntervalSeconds) * time.Second,
@ -80,6 +85,7 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
maxFailedTimes: cfg.MaxFailed,
addr: addr,
url: url,
header: header,
statusOK: false,
statusNormalFn: statusNormalFn,
statusFailedFn: statusFailedFn,
@ -163,6 +169,8 @@ func (monitor *Monitor) doHTTPCheck(ctx context.Context) error {
if err != nil {
return err
}
req.Header = monitor.header
req.Host = monitor.header.Get("Host")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err

View File

@ -216,6 +216,10 @@ healthCheck.path = "/status"
healthCheck.intervalSeconds = 10
healthCheck.maxFailed = 3
healthCheck.timeoutSeconds = 3
# set health check headers
healthCheck.httpHeaders=[
{ name = "x-from-where", value = "frp" }
]
[[proxies]]
name = "web02"

View File

@ -129,3 +129,8 @@ type HTTPPluginOptions struct {
type HeaderOperations struct {
Set map[string]string `json:"set,omitempty"`
}
type HTTPHeader struct {
Name string `json:"name"`
Value string `json:"value"`
}

View File

@ -97,6 +97,9 @@ type HealthCheckConfig struct {
// Path specifies the path to send health checks to if the
// health check type is "http".
Path string `json:"path,omitempty"`
// HTTPHeaders specifies the headers to send with the health request, if
// the health check type is "http".
HTTPHeaders []HTTPHeader `json:"httpHeaders,omitempty"`
}
type DomainConfig struct {

View File

@ -17,7 +17,7 @@ package nathole
import (
"context"
"fmt"
"math/rand"
"math/rand/v2"
"net"
"slices"
"strconv"
@ -341,7 +341,7 @@ func sendSidMessage(
TransactionID: transactionID,
Sid: sid,
Response: false,
Nonce: strings.Repeat("0", rand.Intn(20)),
Nonce: strings.Repeat("0", rand.IntN(20)),
}
buf, err := EncodeMessage(m, key)
if err != nil {
@ -398,7 +398,7 @@ func sendSidMessageToRandomPorts(
used := sets.New[int]()
getUnusedPort := func() int {
for i := 0; i < 10; i++ {
port := rand.Intn(65535-1024) + 1024
port := rand.IntN(65535-1024) + 1024
if !used.Has(port) {
used.Insert(port)
return port

View File

@ -20,7 +20,7 @@ import (
"crypto/subtle"
"encoding/hex"
"fmt"
mathrand "math/rand"
mathrand "math/rand/v2"
"net"
"strconv"
"strings"
@ -124,7 +124,7 @@ func RandomSleep(duration time.Duration, minRatio, maxRatio float64) time.Durati
if max <= min {
n = min
} else {
n = mathrand.Int63n(max-min) + min
n = mathrand.Int64N(max-min) + min
}
d := duration * time.Duration(n) / time.Duration(1000)
time.Sleep(d)

View File

@ -15,7 +15,7 @@
package wait
import (
"math/rand"
"math/rand/v2"
"time"
"github.com/fatedier/frp/pkg/util/util"