Unexport tag names, remove unused var

This commit is contained in:
Marco Munizaga 2022-06-27 15:58:42 -07:00
parent 6d5898aa99
commit e70da09acb

View File

@ -14,9 +14,6 @@ import (
var log = logging.Logger("rcmgrObs") var log = logging.Logger("rcmgrObs")
var ( var (
systemOutboundConns = stats.Int64("system/outbound/conn", "Number of outbound Connections", stats.UnitDimensionless)
systemInboundConns = stats.Int64("system/inbound/conn", "Number of inbound Connections", stats.UnitDimensionless)
conns = stats.Int64("connections", "Number of Connections", stats.UnitDimensionless) conns = stats.Int64("connections", "Number of Connections", stats.UnitDimensionless)
peerConns = stats.Int64("peer/connections", "Number of connections this peer has", stats.UnitDimensionless) peerConns = stats.Int64("peer/connections", "Number of connections this peer has", stats.UnitDimensionless)
@ -40,19 +37,15 @@ var (
) )
var ( var (
LessThanEq, _ = tag.NewKey("le") directionTag, _ = tag.NewKey("dir")
Direction, _ = tag.NewKey("dir") scopeTag, _ = tag.NewKey("scope")
Scope, _ = tag.NewKey("scope") serviceTag, _ = tag.NewKey("service")
Service, _ = tag.NewKey("service") protocolTag, _ = tag.NewKey("protocol")
Protocol, _ = tag.NewKey("protocol") resourceTag, _ = tag.NewKey("resource")
Resource, _ = tag.NewKey("resource")
) )
var ( var (
SystemOutboundConnsView = &view.View{Measure: systemOutboundConns, Aggregation: view.Sum()} ConnView = &view.View{Measure: conns, Aggregation: view.Sum(), TagKeys: []tag.Key{directionTag, scopeTag}}
SystemInboundConnsView = &view.View{Measure: systemInboundConns, Aggregation: view.Sum()}
ConnView = &view.View{Measure: conns, Aggregation: view.Sum(), TagKeys: []tag.Key{Direction, Scope}}
oneTenThenExpDistribution = []float64{ oneTenThenExpDistribution = []float64{
1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1, 10.1, 16.1, 32.1, 64.1, 128.1, 256.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1, 10.1, 16.1, 32.1, 64.1, 128.1, 256.1,
@ -61,19 +54,19 @@ var (
PeerConnsView = &view.View{ PeerConnsView = &view.View{
Measure: peerConns, Measure: peerConns,
Aggregation: view.Distribution(oneTenThenExpDistribution...), Aggregation: view.Distribution(oneTenThenExpDistribution...),
TagKeys: []tag.Key{Direction}, TagKeys: []tag.Key{directionTag},
} }
PeerConnsNegativeView = &view.View{ PeerConnsNegativeView = &view.View{
Measure: peerConnsNegative, Measure: peerConnsNegative,
Aggregation: view.Distribution(oneTenThenExpDistribution...), Aggregation: view.Distribution(oneTenThenExpDistribution...),
TagKeys: []tag.Key{Direction}, TagKeys: []tag.Key{directionTag},
} }
StreamView = &view.View{Measure: streams, Aggregation: view.Sum(), TagKeys: []tag.Key{Direction, Scope, Service, Protocol}} StreamView = &view.View{Measure: streams, Aggregation: view.Sum(), TagKeys: []tag.Key{directionTag, scopeTag, serviceTag, protocolTag}}
PeerStreamsView = &view.View{Measure: peerStreams, Aggregation: view.Distribution(oneTenThenExpDistribution...), TagKeys: []tag.Key{Direction}} PeerStreamsView = &view.View{Measure: peerStreams, Aggregation: view.Distribution(oneTenThenExpDistribution...), TagKeys: []tag.Key{directionTag}}
PeerStreamNegativeView = &view.View{Measure: peerStreamsNegative, Aggregation: view.Distribution(oneTenThenExpDistribution...), TagKeys: []tag.Key{Direction}} PeerStreamNegativeView = &view.View{Measure: peerStreamsNegative, Aggregation: view.Distribution(oneTenThenExpDistribution...), TagKeys: []tag.Key{directionTag}}
MemoryView = &view.View{Measure: memory, Aggregation: view.Sum(), TagKeys: []tag.Key{Scope, Service, Protocol}} MemoryView = &view.View{Measure: memory, Aggregation: view.Sum(), TagKeys: []tag.Key{scopeTag, serviceTag, protocolTag}}
memDistribution = []float64{ memDistribution = []float64{
1 << 10, // 1KB 1 << 10, // 1KB
@ -106,12 +99,12 @@ var (
Aggregation: view.Distribution(memDistribution...), Aggregation: view.Distribution(memDistribution...),
} }
FDsView = &view.View{Measure: fds, Aggregation: view.Sum(), TagKeys: []tag.Key{Scope}} FDsView = &view.View{Measure: fds, Aggregation: view.Sum(), TagKeys: []tag.Key{scopeTag}}
BlockedResourcesView = &view.View{ BlockedResourcesView = &view.View{
Measure: blockedResources, Measure: blockedResources,
Aggregation: view.Sum(), Aggregation: view.Sum(),
TagKeys: []tag.Key{Scope, Resource}, TagKeys: []tag.Key{scopeTag, resourceTag},
} }
) )
@ -156,10 +149,10 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
peerStreamsOut := int64(evt.StreamsOut) peerStreamsOut := int64(evt.StreamsOut)
if oldStreamsOut != peerStreamsOut { if oldStreamsOut != peerStreamsOut {
if oldStreamsOut != 0 { if oldStreamsOut != 0 {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(Direction, "outbound")}, peerStreamsNegative.M(oldStreamsOut)) stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(directionTag, "outbound")}, peerStreamsNegative.M(oldStreamsOut))
} }
if peerStreamsOut != 0 { if peerStreamsOut != 0 {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(Direction, "outbound")}, peerStreams.M(peerStreamsOut)) stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(directionTag, "outbound")}, peerStreams.M(peerStreamsOut))
} }
} }
@ -167,20 +160,20 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
peerStreamsIn := int64(evt.StreamsIn) peerStreamsIn := int64(evt.StreamsIn)
if oldStreamsIn != peerStreamsIn { if oldStreamsIn != peerStreamsIn {
if oldStreamsIn != 0 { if oldStreamsIn != 0 {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(Direction, "inbound")}, peerStreamsNegative.M(oldStreamsIn)) stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(directionTag, "inbound")}, peerStreamsNegative.M(oldStreamsIn))
} }
if peerStreamsIn != 0 { if peerStreamsIn != 0 {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(Direction, "inbound")}, peerStreams.M(peerStreamsIn)) stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(directionTag, "inbound")}, peerStreams.M(peerStreamsIn))
} }
} }
} else { } else {
var tags []tag.Mutator var tags []tag.Mutator
if rcmgr.IsSystemScope(evt.Name) || rcmgr.IsTransientScope(evt.Name) { if rcmgr.IsSystemScope(evt.Name) || rcmgr.IsTransientScope(evt.Name) {
tags = append(tags, tag.Upsert(Scope, evt.Name)) tags = append(tags, tag.Upsert(scopeTag, evt.Name))
} else if svc := rcmgr.ParseServiceScopeName(evt.Name); svc != "" { } else if svc := rcmgr.ParseServiceScopeName(evt.Name); svc != "" {
tags = append(tags, tag.Upsert(Scope, "service"), tag.Upsert(Service, svc)) tags = append(tags, tag.Upsert(scopeTag, "service"), tag.Upsert(serviceTag, svc))
} else if proto := rcmgr.ParseProtocolScopeName(evt.Name); proto != "" { } else if proto := rcmgr.ParseProtocolScopeName(evt.Name); proto != "" {
tags = append(tags, tag.Upsert(Scope, "protocol"), tag.Upsert(Protocol, proto)) tags = append(tags, tag.Upsert(scopeTag, "protocol"), tag.Upsert(protocolTag, proto))
} else { } else {
// Not measuring connscope, servicepeer and protocolpeer. Lots of data, and // Not measuring connscope, servicepeer and protocolpeer. Lots of data, and
// you can use aggregated peer stats + service stats to infer // you can use aggregated peer stats + service stats to infer
@ -191,7 +184,7 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
if evt.DeltaOut != 0 { if evt.DeltaOut != 0 {
stats.RecordWithTags( stats.RecordWithTags(
ctx, ctx,
append([]tag.Mutator{tag.Upsert(Direction, "outbound")}, tags...), append([]tag.Mutator{tag.Upsert(directionTag, "outbound")}, tags...),
streams.M(int64(evt.DeltaOut)), streams.M(int64(evt.DeltaOut)),
) )
} }
@ -199,7 +192,7 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
if evt.DeltaIn != 0 { if evt.DeltaIn != 0 {
stats.RecordWithTags( stats.RecordWithTags(
ctx, ctx,
append([]tag.Mutator{tag.Upsert(Direction, "inbound")}, tags...), append([]tag.Mutator{tag.Upsert(directionTag, "inbound")}, tags...),
streams.M(int64(evt.DeltaIn)), streams.M(int64(evt.DeltaIn)),
) )
} }
@ -217,10 +210,10 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
connsOut := int64(evt.ConnsOut) connsOut := int64(evt.ConnsOut)
if oldConnsOut != connsOut { if oldConnsOut != connsOut {
if oldConnsOut != 0 { if oldConnsOut != 0 {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(Direction, "outbound")}, peerConnsNegative.M(oldConnsOut)) stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(directionTag, "outbound")}, peerConnsNegative.M(oldConnsOut))
} }
if connsOut != 0 { if connsOut != 0 {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(Direction, "outbound")}, peerConns.M(connsOut)) stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(directionTag, "outbound")}, peerConns.M(connsOut))
} }
} }
@ -228,16 +221,16 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
connsIn := int64(evt.ConnsIn) connsIn := int64(evt.ConnsIn)
if oldConnsIn != connsIn { if oldConnsIn != connsIn {
if oldConnsIn != 0 { if oldConnsIn != 0 {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(Direction, "inbound")}, peerConnsNegative.M(oldConnsIn)) stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(directionTag, "inbound")}, peerConnsNegative.M(oldConnsIn))
} }
if connsIn != 0 { if connsIn != 0 {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(Direction, "inbound")}, peerConns.M(connsIn)) stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(directionTag, "inbound")}, peerConns.M(connsIn))
} }
} }
} else { } else {
var tags []tag.Mutator var tags []tag.Mutator
if rcmgr.IsSystemScope(evt.Name) || rcmgr.IsTransientScope(evt.Name) { if rcmgr.IsSystemScope(evt.Name) || rcmgr.IsTransientScope(evt.Name) {
tags = append(tags, tag.Upsert(Scope, evt.Name)) tags = append(tags, tag.Upsert(scopeTag, evt.Name))
} else if rcmgr.IsConnScope(evt.Name) { } else if rcmgr.IsConnScope(evt.Name) {
// Not measuring this. I don't think it's useful. // Not measuring this. I don't think it's useful.
break break
@ -249,7 +242,7 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
if evt.DeltaOut != 0 { if evt.DeltaOut != 0 {
stats.RecordWithTags( stats.RecordWithTags(
ctx, ctx,
append([]tag.Mutator{tag.Upsert(Direction, "outbound")}, tags...), append([]tag.Mutator{tag.Upsert(directionTag, "outbound")}, tags...),
conns.M(int64(evt.DeltaOut)), conns.M(int64(evt.DeltaOut)),
) )
} }
@ -257,7 +250,7 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
if evt.DeltaIn != 0 { if evt.DeltaIn != 0 {
stats.RecordWithTags( stats.RecordWithTags(
ctx, ctx,
append([]tag.Mutator{tag.Upsert(Direction, "inbound")}, tags...), append([]tag.Mutator{tag.Upsert(directionTag, "inbound")}, tags...),
conns.M(int64(evt.DeltaIn)), conns.M(int64(evt.DeltaIn)),
) )
} }
@ -295,11 +288,11 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
} else { } else {
var tags []tag.Mutator var tags []tag.Mutator
if rcmgr.IsSystemScope(evt.Name) || rcmgr.IsTransientScope(evt.Name) { if rcmgr.IsSystemScope(evt.Name) || rcmgr.IsTransientScope(evt.Name) {
tags = append(tags, tag.Upsert(Scope, evt.Name)) tags = append(tags, tag.Upsert(scopeTag, evt.Name))
} else if svc := rcmgr.ParseServiceScopeName(evt.Name); svc != "" { } else if svc := rcmgr.ParseServiceScopeName(evt.Name); svc != "" {
tags = append(tags, tag.Upsert(Scope, "service"), tag.Upsert(Service, svc)) tags = append(tags, tag.Upsert(scopeTag, "service"), tag.Upsert(serviceTag, svc))
} else if proto := rcmgr.ParseProtocolScopeName(evt.Name); proto != "" { } else if proto := rcmgr.ParseProtocolScopeName(evt.Name); proto != "" {
tags = append(tags, tag.Upsert(Scope, "protocol"), tag.Upsert(Protocol, proto)) tags = append(tags, tag.Upsert(scopeTag, "protocol"), tag.Upsert(protocolTag, proto))
} else { } else {
// Not measuring connscope, servicepeer and protocolpeer. Lots of data, and // Not measuring connscope, servicepeer and protocolpeer. Lots of data, and
// you can use aggregated peer stats + service stats to infer // you can use aggregated peer stats + service stats to infer
@ -322,12 +315,12 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
resource = "memory" resource = "memory"
} }
// Only the top scope. We don't want to get the peerid here. // Only the top scopeName. We don't want to get the peerid here.
scope := strings.SplitN(evt.Name, ":", 2)[0] scopeName := strings.SplitN(evt.Name, ":", 2)[0]
// Drop the connection or stream id // Drop the connection or stream id
scope = strings.SplitN(scope, "-", 2)[0] scopeName = strings.SplitN(scopeName, "-", 2)[0]
tags := []tag.Mutator{tag.Upsert(Scope, scope), tag.Upsert(Resource, resource)} tags := []tag.Mutator{tag.Upsert(scopeTag, scopeName), tag.Upsert(resourceTag, resource)}
if evt.DeltaIn != 0 { if evt.DeltaIn != 0 {
stats.RecordWithTags(ctx, tags, blockedResources.M(int64(1))) stats.RecordWithTags(ctx, tags, blockedResources.M(int64(1)))