Skip to content

Commit

Permalink
perf: solve go dependency problem
Browse files Browse the repository at this point in the history
  • Loading branch information
张启航 committed Nov 20, 2023
1 parent e4fdb95 commit c1327f6
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 50 deletions.
1 change: 1 addition & 0 deletions gateway/cluster/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package cluster
import (
"context"
"fmt"
"github.com/coreos/etcd/clientv3"
"net"
"time"

Expand Down
1 change: 1 addition & 0 deletions gateway/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package controller
import (
"context"
"fmt"
client "github.com/coreos/etcd/clientv3"
"sync"
"time"

Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ require (
)

require (
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand Down Expand Up @@ -311,8 +311,6 @@ replace (
github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane v0.9.5
github.com/godbus/dbus => github.com/godbus/dbus/v5 v5.0.4
github.com/goodrain/rainbond-oam => github.com/goodrain/rainbond-oam v0.0.0-20230823084937-0067a4cf0912
github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.12.1
github.com/prometheus/common => github.com/prometheus/common v0.15.0
github.com/prometheus/procfs => github.com/prometheus/procfs v0.7.3
google.golang.org/grpc => google.golang.org/grpc v1.27.1
helm.sh/helm/v3 => helm.sh/helm/v3 v3.9.0
Expand Down
69 changes: 62 additions & 7 deletions go.sum

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions grctl/cmd/gpushare.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/goodrain/rainbond/grctl/clients"
"github.com/prometheus/common/log"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -18,7 +18,7 @@ import (
"time"
)

//DeviceInfo -
// DeviceInfo -
type DeviceInfo struct {
idx int
pods []v1.Pod
Expand All @@ -27,7 +27,7 @@ type DeviceInfo struct {
node v1.Node
}

//NodeInfo -
// NodeInfo -
type NodeInfo struct {
pods []v1.Pod
node v1.Node
Expand All @@ -42,7 +42,7 @@ var (
memoryUnit = ""
)

//NewCmdGPUShare -
// NewCmdGPUShare -
func NewCmdGPUShare() cli.Command {
c := cli.Command{
Name: "gpushare",
Expand Down Expand Up @@ -493,7 +493,7 @@ func (n *NodeInfo) hasPendingGPUMemory() bool {
return found
}

//GetAllocation -
// GetAllocation -
func GetAllocation(pod *v1.Pod) map[int]int {
podGPUMems := map[int]int{}
allocationString := ""
Expand All @@ -514,7 +514,7 @@ func GetAllocation(pod *v1.Pod) map[int]int {
for id, gpuMem := range containerAllocation {
gpuIndex, err := strconv.Atoi(id)
if err != nil {
log.Errorf("failed to get gpu memory from pod annotation,reason: %v", err)
logrus.Errorf("failed to get gpu memory from pod annotation,reason: %v", err)
return map[int]int{}
}
podGPUMems[gpuIndex] += gpuMem
Expand Down
4 changes: 1 addition & 3 deletions node/monitormessage/udpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
"github.com/goodrain/rainbond/discover/config"
etcdutil "github.com/goodrain/rainbond/util/etcd"
"github.com/sirupsen/logrus"

"github.com/prometheus/common/log"
)

//UDPServer udp server
Expand Down Expand Up @@ -111,7 +109,7 @@ func (u *UDPServer) server() error {
fmt.Println(err)
return err
}
log.Infof("UDP Server Listener: %s", listener.LocalAddr().String())
logrus.Infof("UDP Server Listener: %s", listener.LocalAddr().String())
buf := make([]byte, 65535)
go func() {
defer listener.Close()
Expand Down
47 changes: 23 additions & 24 deletions node/statsd/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"encoding/binary"
"fmt"
"github.com/sirupsen/logrus"
"hash/fnv"
"io"
"net"
Expand All @@ -33,9 +34,7 @@ import (
"unicode/utf8"

"github.com/goodrain/rainbond/node/statsd/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -256,7 +255,7 @@ func (b *Exporter) Listen(e <-chan Events) {
for {
events, ok := <-e
if !ok {
log.Debug("Channel is closed. Break out of Exporter.Listener.")
logrus.Debug("Channel is closed. Break out of Exporter.Listener.")
return
}
for _, event := range events {
Expand Down Expand Up @@ -289,7 +288,7 @@ func (b *Exporter) Listen(e <-chan Events) {
// We don't accept negative values for counters. Incrementing the counter with a negative number
// will cause the exporter to panic. Instead we will warn and continue to the next event.
if event.Value() < 0.0 {
log.Debugf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
logrus.Debugf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
eventStats.WithLabelValues("illegal_negative_counter").Inc()
continue
}
Expand All @@ -304,7 +303,7 @@ func (b *Exporter) Listen(e <-chan Events) {
counter.SetTimestamp(timestamp)
eventStats.WithLabelValues("counter").Inc()
} else {
log.Debugf(regErrF, metricName, err)
logrus.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("counter").Inc()
}

Expand All @@ -325,7 +324,7 @@ func (b *Exporter) Listen(e <-chan Events) {
gauge.SetTimestamp(timestamp)
eventStats.WithLabelValues("gauge").Inc()
} else {
log.Debugf(regErrF, metricName, err)
logrus.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("gauge").Inc()
}

Expand All @@ -351,7 +350,7 @@ func (b *Exporter) Listen(e <-chan Events) {
histogram.SetTimestamp(timestamp)
eventStats.WithLabelValues("timer").Inc()
} else {
log.Debugf(regErrF, metricName, err)
logrus.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("timer").Inc()
}

Expand All @@ -366,7 +365,7 @@ func (b *Exporter) Listen(e <-chan Events) {
summary.SetTimestamp(timestamp)
eventStats.WithLabelValues("timer").Inc()
} else {
log.Debugf(regErrF, metricName, err)
logrus.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("timer").Inc()
}

Expand All @@ -375,14 +374,14 @@ func (b *Exporter) Listen(e <-chan Events) {
}

default:
log.Debugln("Unsupported event type")
logrus.Debugln("Unsupported event type")
eventStats.WithLabelValues("illegal").Inc()
}
}
}
}

//GCollector 循环检查Exporter对象中的性能指标数据是否有过期,有则清除
// GCollector 循环检查Exporter对象中的性能指标数据是否有过期,有则清除
func (b *Exporter) GCollector() {
var HP = b.vitality
timer := time.NewTicker(time.Second * 10)
Expand Down Expand Up @@ -431,7 +430,7 @@ func (b *Exporter) GCollector() {
}
}

//NewExporter new exporter
// NewExporter new exporter
func NewExporter(mapper *MetricMapper, Register prometheus.Registerer) *Exporter {
return &Exporter{
Counters: NewCounterContainer(Register),
Expand Down Expand Up @@ -481,7 +480,7 @@ func parseDogStatsDTagsToLabels(component string) map[string]string {

if len(kv) < 2 || len(kv[1]) == 0 {
tagErrors.Inc()
log.Debugf("Malformed or empty DogStatsD tag %s in component %s", t, component)
logrus.Debugf("Malformed or empty DogStatsD tag %s in component %s", t, component)
continue
}

Expand All @@ -499,7 +498,7 @@ func lineToEvents(line string) Events {
elements := strings.SplitN(line, ":", 2)
if len(elements) < 2 || len(elements[0]) == 0 || !utf8.ValidString(line) {
sampleErrors.WithLabelValues("malformed_line").Inc()
log.Debugln("Bad line from StatsD:", line)
logrus.Debugln("Bad line from StatsD:", line)
return events
}
metric := elements[0]
Expand All @@ -517,7 +516,7 @@ samples:
samplingFactor := 1.0
if len(components) < 2 || len(components) > 4 {
sampleErrors.WithLabelValues("malformed_component").Inc()
log.Debugln("Bad component on line:", line)
logrus.Debugln("Bad component on line:", line)
continue
}
valueStr, statType := components[0], components[1]
Expand All @@ -529,7 +528,7 @@ samples:

value, err := strconv.ParseFloat(valueStr, 64)
if err != nil {
log.Debugf("Bad value %s on line: %s", valueStr, line)
logrus.Debugf("Bad value %s on line: %s", valueStr, line)
sampleErrors.WithLabelValues("malformed_value").Inc()
continue
}
Expand All @@ -539,7 +538,7 @@ samples:
if len(components) >= 3 {
for _, component := range components[2:] {
if len(component) == 0 {
log.Debugln("Empty component on line: ", line)
logrus.Debugln("Empty component on line: ", line)
sampleErrors.WithLabelValues("malformed_component").Inc()
continue samples
}
Expand All @@ -549,13 +548,13 @@ samples:
switch component[0] {
case '@':
if statType != "c" && statType != "ms" {
log.Debugln("Illegal sampling factor for non-counter metric on line", line)
logrus.Debugln("Illegal sampling factor for non-counter metric on line", line)
sampleErrors.WithLabelValues("illegal_sample_factor").Inc()
continue
}
samplingFactor, err = strconv.ParseFloat(component[1:], 64)
if err != nil {
log.Debugf("Invalid sampling factor %s on line %s", component[1:], line)
logrus.Debugf("Invalid sampling factor %s on line %s", component[1:], line)
sampleErrors.WithLabelValues("invalid_sample_factor").Inc()
}
if samplingFactor == 0 {
Expand All @@ -570,7 +569,7 @@ samples:
case '#':
labels = parseDogStatsDTagsToLabels(component)
default:
log.Debugf("Invalid sampling factor or tag section %s on line %s", components[2], line)
logrus.Debugf("Invalid sampling factor or tag section %s on line %s", components[2], line)
sampleErrors.WithLabelValues("invalid_sample_factor").Inc()
continue
}
Expand All @@ -580,7 +579,7 @@ samples:
for i := 0; i < multiplyEvents; i++ {
event, err := buildEvent(statType, metric, value, relative, labels)
if err != nil {
log.Debugf("Error building event on line %s: %s", line, err)
logrus.Debugf("Error building event on line %s: %s", line, err)
sampleErrors.WithLabelValues("illegal_event").Inc()
continue
}
Expand All @@ -599,7 +598,7 @@ func (l *StatsDUDPListener) Listen(e chan<- Events) {
for {
n, _, err := l.Conn.ReadFromUDP(buf)
if err != nil {
log.Fatal(err)
logrus.Fatal(err)
}
l.handlePacket(buf[0:n], e)
}
Expand All @@ -625,7 +624,7 @@ func (l *StatsDTCPListener) Listen(e chan<- Events) {
for {
c, err := l.Conn.AcceptTCP()
if err != nil {
log.Fatalf("AcceptTCP failed: %v", err)
logrus.Fatalf("AcceptTCP failed: %v", err)
}
go l.handleConn(c, e)
}
Expand All @@ -642,13 +641,13 @@ func (l *StatsDTCPListener) handleConn(c *net.TCPConn, e chan<- Events) {
if err != nil {
if err != io.EOF {
tcpErrors.Inc()
log.Debugf("Read %s failed: %v", c.RemoteAddr(), err)
logrus.Debugf("Read %s failed: %v", c.RemoteAddr(), err)
}
break
}
if isPrefix {
tcpLineTooLong.Inc()
log.Debugf("Read %s failed: line too long", c.RemoteAddr())
logrus.Debugf("Read %s failed: line too long", c.RemoteAddr())
break
}
linesReceived.Inc()
Expand Down
13 changes: 6 additions & 7 deletions worker/monitor/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ import (
"github.com/goodrain/rainbond/worker/monitor/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/sirupsen/logrus"
)

//ExporterManager app resource exporter
// ExporterManager app resource exporter
type ExporterManager struct {
ctx context.Context
cancel context.CancelFunc
Expand All @@ -45,7 +44,7 @@ type ExporterManager struct {
controllermanager *controller.Manager
}

//NewManager return *NewManager
// NewManager return *NewManager
func NewManager(c option.Config, masterController *master.Controller, controllermanager *controller.Manager) *ExporterManager {
ctx, cancel := context.WithCancel(context.Background())
return &ExporterManager{
Expand All @@ -70,7 +69,7 @@ func (t *ExporterManager) handler(w http.ResponseWriter, r *http.Request) {
h.ServeHTTP(w, r)
}

//Start 启动
// Start 启动
func (t *ExporterManager) Start() error {
http.HandleFunc(t.config.PrometheusMetricPath, t.handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -90,15 +89,15 @@ func (t *ExporterManager) Start() error {
}
httputil.ReturnSuccess(r, w, healthStatus)
})
log.Infoln("Listening on", t.config.Listen)
logrus.Infoln("Listening on", t.config.Listen)
go func() {
log.Fatal(http.ListenAndServe(t.config.Listen, nil))
logrus.Fatal(http.ListenAndServe(t.config.Listen, nil))
}()
logrus.Info("start app resource exporter success.")
return nil
}

//Stop 停止
// Stop 停止
func (t *ExporterManager) Stop() {
t.cancel()
}

0 comments on commit c1327f6

Please sign in to comment.