mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-30 15:22:07 +00:00
Revert "lib/promscrape: do not add a suggestion for enabling TCP6 in error message when the dial address is TCPv4"
It broke CI (lint)
This reverts commit 5464376d16
.
This commit is contained in:
parent
46dd504d81
commit
1e48ad486e
2 changed files with 2 additions and 92 deletions
|
@ -4,8 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
@ -24,7 +22,7 @@ func statStdDial(ctx context.Context, _, addr string) (net.Conn, error) {
|
|||
dialsTotal.Inc()
|
||||
if err != nil {
|
||||
dialErrors.Inc()
|
||||
if !netutil.TCP6Enabled() && !isTCPv4Addr(addr) {
|
||||
if !netutil.TCP6Enabled() {
|
||||
err = fmt.Errorf("%w; try -enableTCP6 command-line flag if you scrape ipv6 addresses", err)
|
||||
}
|
||||
return nil, err
|
||||
|
@ -62,7 +60,7 @@ func newStatDialFunc(proxyURL *proxy.URL, ac *promauth.Config) (fasthttp.DialFun
|
|||
dialsTotal.Inc()
|
||||
if err != nil {
|
||||
dialErrors.Inc()
|
||||
if !netutil.TCP6Enabled() && !isTCPv4Addr(addr) {
|
||||
if !netutil.TCP6Enabled() {
|
||||
err = fmt.Errorf("%w; try -enableTCP6 command-line flag if you scrape ipv6 addresses", err)
|
||||
}
|
||||
return nil, err
|
||||
|
@ -123,40 +121,3 @@ var (
|
|||
connBytesRead = metrics.NewCounter(`vm_promscrape_conn_bytes_read_total`)
|
||||
connBytesWritten = metrics.NewCounter(`vm_promscrape_conn_bytes_written_total`)
|
||||
)
|
||||
|
||||
func isTCPv4Addr(addr string) bool {
|
||||
s := addr
|
||||
for i := 0; i < 3; i++ {
|
||||
n := strings.IndexByte(s, '.')
|
||||
if n < 0 {
|
||||
return false
|
||||
}
|
||||
if !isUint8NumString(s[:n]) {
|
||||
return false
|
||||
}
|
||||
s = s[n+1:]
|
||||
}
|
||||
n := strings.IndexByte(s, ':')
|
||||
if n < 0 {
|
||||
return false
|
||||
}
|
||||
if !isUint8NumString(s[:n]) {
|
||||
return false
|
||||
}
|
||||
s = s[n+1:]
|
||||
|
||||
// Verify TCP port
|
||||
n, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return n >= 0 && n < (1<<16)
|
||||
}
|
||||
|
||||
func isUint8NumString(s string) bool {
|
||||
n, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return n >= 0 && n < (1<<8)
|
||||
}
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
package promscrape
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsTCPv4Addr(t *testing.T) {
|
||||
f := func(addr string, resultExpected bool) {
|
||||
t.Helper()
|
||||
result := isTCPv4Addr(addr)
|
||||
if result != resultExpected {
|
||||
t.Fatalf("unexpected result for isIPv4Addr(%q); got %v; want %v", addr, result, resultExpected)
|
||||
}
|
||||
}
|
||||
|
||||
// empty addr
|
||||
f("", false)
|
||||
|
||||
// too small number of octets
|
||||
f("foobar", false)
|
||||
f("1", false)
|
||||
f("1.2", false)
|
||||
f("1.2.3", false)
|
||||
f("1.2.3.", false)
|
||||
|
||||
// non-numeric octets
|
||||
f("foo.bar.baz.aaa", false)
|
||||
|
||||
// non-numeric last value
|
||||
f("1.2.3.foo", false)
|
||||
|
||||
// negative value
|
||||
f("1.2.3.-4", false)
|
||||
|
||||
// missing port
|
||||
f("1.2.3.4", false)
|
||||
|
||||
// invalid port
|
||||
f("1.2.3.4:foo", false)
|
||||
|
||||
// too big octet
|
||||
f("1.2.3.444:5", false)
|
||||
|
||||
// too big port
|
||||
f("1.2.3.4:152344", false)
|
||||
|
||||
// normal TCPv4 addr
|
||||
f("1.2.3.4:5", true)
|
||||
f("0.0.0.0:80", true)
|
||||
f("1.2.3.4:65535", true)
|
||||
}
|
Loading…
Reference in a new issue