From 9876f682e9ec865a2ce9634c2b38d645f2087734 Mon Sep 17 00:00:00 2001 From: Feng_Qi Date: Thu, 9 Apr 2020 13:28:41 +0800 Subject: [PATCH] VERSION 4.1.1 n9e mode support debug --- g/const.go | 3 ++- g/push.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/g/const.go b/g/const.go index 992cd15..a566f1b 100644 --- a/g/const.go +++ b/g/const.go @@ -22,7 +22,8 @@ import ( // 4.0.6.2 fix Vendor bug;add remote config api // 4.0.6.3 fix bugs // 4.1.0 support n9e transfer mode +// 4.1.1 n9e mode support debug const ( - VERSION = "4.1.0" + VERSION = "4.1.1" COLLECT_INTERVAL = time.Second ) diff --git a/g/push.go b/g/push.go index 7718b98..428920d 100644 --- a/g/push.go +++ b/g/push.go @@ -7,6 +7,7 @@ import ( "net" "net/rpc" "reflect" + "strings" "time" "github.com/didi/nightingale/src/dataobj" @@ -37,6 +38,36 @@ func N9ePush(items []*model.MetricValue) { rpcCodec := codec.MsgpackSpecRpc.ClientCodec(bufconn, &mh) client := rpc.NewClientWithCodec(rpcCodec) + debug := Config().Debug + debug_endpoints := Config().Debugmetric.Endpoints + debug_items := Config().Debugmetric.Metrics + debug_tags := Config().Debugmetric.Tags + debug_Tags := strings.Split(debug_tags, ",") + + if Config().SwitchHosts.Enabled { + hosts := HostConfig().Hosts + for i, metric := range items { + if hostname, ok := hosts[metric.Endpoint]; ok { + items[i].Endpoint = hostname + } + } + } + + if debug { + for _, metric := range items { + metric_tags := strings.Split(metric.Tags, ",") + if in_array(metric.Endpoint, debug_endpoints) && in_array(metric.Metric, debug_items) { + if debug_tags == "" { + log.Printf("=> %v\n", len(items), metric) + continue + } + if array_include(debug_Tags, metric_tags) { + log.Printf("=> %v\n", len(items), metric) + } + } + } + } + var reply dataobj.TransferResp err = client.Call("Transfer.Push", items, &reply) client.Close()