Fix golint warnings (#4241)
Include: 1. plugin/forward/type.go:8:2: const typeUdp should be typeUDP 2. plugin/forward/type.go:9:2: const typeTcp should be typeTCP 3. plugin/forward/type.go:10:2: const typeTls should be typeTLS 4. plugin/kubernetes/metrics.go:24:2: var DnsProgrammingLatency should be DNSProgrammingLatency 5. plugin/kubernetes/metrics_test.go:124:102: func parameter clusterIp should be clusterIP Signed-off-by: zouyu <zouy.fnst@cn.fujitsu.com>
This commit is contained in:
parent
d6660f369e
commit
c58e4b09fc
4 changed files with 21 additions and 21 deletions
|
@ -96,14 +96,14 @@ func TestCleanupAll(t *testing.T) {
|
||||||
c2, _ := dns.DialTimeout("udp", tr.addr, maxDialTimeout)
|
c2, _ := dns.DialTimeout("udp", tr.addr, maxDialTimeout)
|
||||||
c3, _ := dns.DialTimeout("udp", tr.addr, maxDialTimeout)
|
c3, _ := dns.DialTimeout("udp", tr.addr, maxDialTimeout)
|
||||||
|
|
||||||
tr.conns[typeUdp] = []*persistConn{{c1, time.Now()}, {c2, time.Now()}, {c3, time.Now()}}
|
tr.conns[typeUDP] = []*persistConn{{c1, time.Now()}, {c2, time.Now()}, {c3, time.Now()}}
|
||||||
|
|
||||||
if len(tr.conns[typeUdp]) != 3 {
|
if len(tr.conns[typeUDP]) != 3 {
|
||||||
t.Error("Expected 3 connections")
|
t.Error("Expected 3 connections")
|
||||||
}
|
}
|
||||||
tr.cleanup(true)
|
tr.cleanup(true)
|
||||||
|
|
||||||
if len(tr.conns[typeUdp]) > 0 {
|
if len(tr.conns[typeUDP]) > 0 {
|
||||||
t.Error("Expected no cached connections")
|
t.Error("Expected no cached connections")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,33 +5,33 @@ import "net"
|
||||||
type transportType int
|
type transportType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
typeUdp transportType = iota
|
typeUDP transportType = iota
|
||||||
typeTcp
|
typeTCP
|
||||||
typeTls
|
typeTLS
|
||||||
typeTotalCount // keep this last
|
typeTotalCount // keep this last
|
||||||
)
|
)
|
||||||
|
|
||||||
func stringToTransportType(s string) transportType {
|
func stringToTransportType(s string) transportType {
|
||||||
switch s {
|
switch s {
|
||||||
case "udp":
|
case "udp":
|
||||||
return typeUdp
|
return typeUDP
|
||||||
case "tcp":
|
case "tcp":
|
||||||
return typeTcp
|
return typeTCP
|
||||||
case "tcp-tls":
|
case "tcp-tls":
|
||||||
return typeTls
|
return typeTLS
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeUdp
|
return typeUDP
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Transport) transportTypeFromConn(pc *persistConn) transportType {
|
func (t *Transport) transportTypeFromConn(pc *persistConn) transportType {
|
||||||
if _, ok := pc.c.Conn.(*net.UDPConn); ok {
|
if _, ok := pc.c.Conn.(*net.UDPConn); ok {
|
||||||
return typeUdp
|
return typeUDP
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.tlsConfig == nil {
|
if t.tlsConfig == nil {
|
||||||
return typeTcp
|
return typeTCP
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeTls
|
return typeTLS
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DnsProgrammingLatency is defined as the time it took to program a DNS instance - from the time
|
// DNSProgrammingLatency is defined as the time it took to program a DNS instance - from the time
|
||||||
// a service or pod has changed to the time the change was propagated and was available to be
|
// a service or pod has changed to the time the change was propagated and was available to be
|
||||||
// served by a DNS server.
|
// served by a DNS server.
|
||||||
// The definition of this SLI can be found at https://github.com/kubernetes/community/blob/master/sig-scalability/slos/dns_programming_latency.md
|
// The definition of this SLI can be found at https://github.com/kubernetes/community/blob/master/sig-scalability/slos/dns_programming_latency.md
|
||||||
|
@ -23,7 +23,7 @@ var (
|
||||||
// * cluster_ip
|
// * cluster_ip
|
||||||
// * headless_with_selector
|
// * headless_with_selector
|
||||||
// * headless_without_selector
|
// * headless_without_selector
|
||||||
DnsProgrammingLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
DNSProgrammingLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||||
Namespace: plugin.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: pluginName,
|
Subsystem: pluginName,
|
||||||
Name: "dns_programming_duration_seconds",
|
Name: "dns_programming_duration_seconds",
|
||||||
|
@ -68,6 +68,6 @@ func recordDNSProgrammingLatency(svcs []*object.Service, endpoints *api.Endpoint
|
||||||
// the Endpoints object was created by the endpoints-controller (because the
|
// the Endpoints object was created by the endpoints-controller (because the
|
||||||
// LastChangeTriggerTime annotation is set). It means that the corresponding service is a
|
// LastChangeTriggerTime annotation is set). It means that the corresponding service is a
|
||||||
// "headless service with selector".
|
// "headless service with selector".
|
||||||
DnsProgrammingLatency.WithLabelValues("headless_with_selector").
|
DNSProgrammingLatency.WithLabelValues("headless_with_selector").
|
||||||
Observe(durationSinceFunc(lastChangeTriggerTime).Seconds())
|
Observe(durationSinceFunc(lastChangeTriggerTime).Seconds())
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ const (
|
||||||
namespace = "testns"
|
namespace = "testns"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDnsProgrammingLatency(t *testing.T) {
|
func TestDNSProgrammingLatency(t *testing.T) {
|
||||||
client := fake.NewSimpleClientset()
|
client := fake.NewSimpleClientset()
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
|
@ -32,7 +32,7 @@ func TestDnsProgrammingLatency(t *testing.T) {
|
||||||
durationSinceFunc = func(t time.Time) time.Duration {
|
durationSinceFunc = func(t time.Time) time.Duration {
|
||||||
return now.Sub(t)
|
return now.Sub(t)
|
||||||
}
|
}
|
||||||
DnsProgrammingLatency.Reset()
|
DNSProgrammingLatency.Reset()
|
||||||
go controller.Run()
|
go controller.Run()
|
||||||
|
|
||||||
subset1 := []api.EndpointSubset{{
|
subset1 := []api.EndpointSubset{{
|
||||||
|
@ -86,7 +86,7 @@ func TestDnsProgrammingLatency(t *testing.T) {
|
||||||
coredns_kubernetes_dns_programming_duration_seconds_sum{service_kind="headless_with_selector"} 3
|
coredns_kubernetes_dns_programming_duration_seconds_sum{service_kind="headless_with_selector"} 3
|
||||||
coredns_kubernetes_dns_programming_duration_seconds_count{service_kind="headless_with_selector"} 2
|
coredns_kubernetes_dns_programming_duration_seconds_count{service_kind="headless_with_selector"} 2
|
||||||
`
|
`
|
||||||
if err := testutil.CollectAndCompare(DnsProgrammingLatency, strings.NewReader(expected)); err != nil {
|
if err := testutil.CollectAndCompare(DNSProgrammingLatency, strings.NewReader(expected)); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,11 +121,11 @@ func updateEndpoints(t *testing.T, client kubernetes.Interface, name string, tri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createService(t *testing.T, client kubernetes.Interface, controller dnsController, name string, clusterIp string) {
|
func createService(t *testing.T, client kubernetes.Interface, controller dnsController, name string, clusterIP string) {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
if _, err := client.CoreV1().Services(namespace).Create(ctx, &api.Service{
|
if _, err := client.CoreV1().Services(namespace).Create(ctx, &api.Service{
|
||||||
ObjectMeta: meta.ObjectMeta{Namespace: namespace, Name: name},
|
ObjectMeta: meta.ObjectMeta{Namespace: namespace, Name: name},
|
||||||
Spec: api.ServiceSpec{ClusterIP: clusterIp},
|
Spec: api.ServiceSpec{ClusterIP: clusterIP},
|
||||||
}, meta.CreateOptions{}); err != nil {
|
}, meta.CreateOptions{}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue