Merge branch 'main' into repo_sync

This commit is contained in:
Arthur Silva Sens 2024-07-17 15:01:18 -03:00 committed by GitHub
commit a46cfa7f0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 53 additions and 17 deletions

View File

@ -63,6 +63,7 @@ func withAllMetrics() []string {
"go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxheaders_events_total",
"go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total",
"go_godebug_non_default_behavior_multipathtcp_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total",
"go_godebug_non_default_behavior_netedns0_events_total",
"go_godebug_non_default_behavior_panicnil_events_total", "go_godebug_non_default_behavior_panicnil_events_total",
"go_godebug_non_default_behavior_randautoseed_events_total", "go_godebug_non_default_behavior_randautoseed_events_total",
"go_godebug_non_default_behavior_tarinsecurepath_events_total", "go_godebug_non_default_behavior_tarinsecurepath_events_total",
@ -158,6 +159,7 @@ func withDebugMetrics() []string {
"go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxheaders_events_total",
"go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total",
"go_godebug_non_default_behavior_multipathtcp_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total",
"go_godebug_non_default_behavior_netedns0_events_total",
"go_godebug_non_default_behavior_panicnil_events_total", "go_godebug_non_default_behavior_panicnil_events_total",
"go_godebug_non_default_behavior_randautoseed_events_total", "go_godebug_non_default_behavior_randautoseed_events_total",
"go_godebug_non_default_behavior_tarinsecurepath_events_total", "go_godebug_non_default_behavior_tarinsecurepath_events_total",

View File

@ -66,6 +66,7 @@ func withAllMetrics() []string {
"go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxheaders_events_total",
"go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total",
"go_godebug_non_default_behavior_multipathtcp_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total",
"go_godebug_non_default_behavior_netedns0_events_total",
"go_godebug_non_default_behavior_panicnil_events_total", "go_godebug_non_default_behavior_panicnil_events_total",
"go_godebug_non_default_behavior_randautoseed_events_total", "go_godebug_non_default_behavior_randautoseed_events_total",
"go_godebug_non_default_behavior_tarinsecurepath_events_total", "go_godebug_non_default_behavior_tarinsecurepath_events_total",
@ -176,6 +177,7 @@ func withDebugMetrics() []string {
"go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxheaders_events_total",
"go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total",
"go_godebug_non_default_behavior_multipathtcp_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total",
"go_godebug_non_default_behavior_netedns0_events_total",
"go_godebug_non_default_behavior_panicnil_events_total", "go_godebug_non_default_behavior_panicnil_events_total",
"go_godebug_non_default_behavior_randautoseed_events_total", "go_godebug_non_default_behavior_randautoseed_events_total",
"go_godebug_non_default_behavior_tarinsecurepath_events_total", "go_godebug_non_default_behavior_tarinsecurepath_events_total",

View File

@ -20,11 +20,12 @@ import (
"encoding/json" "encoding/json"
"log" "log"
"net/http" "net/http"
"reflect"
"regexp" "regexp"
"sort" "sort"
"testing" "testing"
"github.com/google/go-cmp/cmp"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
@ -69,8 +70,8 @@ func TestWithGoCollectorMemStatsMetricsDisabled(t *testing.T) {
got = append(got, r.GetName()) got = append(got, r.GetName())
} }
if !reflect.DeepEqual(got, baseMetrics) { if diff := cmp.Diff(got, baseMetrics); diff != "" {
t.Errorf("got %v, want %v", got, baseMetrics) t.Errorf("missmatch (-want +got):\n%s", diff)
} }
} }
@ -127,8 +128,8 @@ func TestGoCollectorAllowList(t *testing.T) {
got = append(got, r.GetName()) got = append(got, r.GetName())
} }
if !reflect.DeepEqual(got, test.expected) { if diff := cmp.Diff(got, test.expected); diff != "" {
t.Errorf("got %v, want %v", got, test.expected) t.Errorf("missmatch (-want +got):\n%s", diff)
} }
}) })
} }
@ -181,8 +182,8 @@ func TestGoCollectorDenyList(t *testing.T) {
got = append(got, r.GetName()) got = append(got, r.GetName())
} }
if !reflect.DeepEqual(got, test.expected) { if diff := cmp.Diff(got, test.expected); diff != "" {
t.Errorf("got %v, want %v", got, test.expected) t.Errorf("missmatch (-want +got):\n%s", diff)
} }
}) })
} }

View File

@ -52,6 +52,7 @@ var expectedRuntimeMetrics = map[string]string{
"/godebug/non-default-behavior/multipartmaxheaders:events": "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "/godebug/non-default-behavior/multipartmaxheaders:events": "go_godebug_non_default_behavior_multipartmaxheaders_events_total",
"/godebug/non-default-behavior/multipartmaxparts:events": "go_godebug_non_default_behavior_multipartmaxparts_events_total", "/godebug/non-default-behavior/multipartmaxparts:events": "go_godebug_non_default_behavior_multipartmaxparts_events_total",
"/godebug/non-default-behavior/multipathtcp:events": "go_godebug_non_default_behavior_multipathtcp_events_total", "/godebug/non-default-behavior/multipathtcp:events": "go_godebug_non_default_behavior_multipathtcp_events_total",
"/godebug/non-default-behavior/netedns0:events": "go_godebug_non_default_behavior_netedns0_events_total",
"/godebug/non-default-behavior/panicnil:events": "go_godebug_non_default_behavior_panicnil_events_total", "/godebug/non-default-behavior/panicnil:events": "go_godebug_non_default_behavior_panicnil_events_total",
"/godebug/non-default-behavior/randautoseed:events": "go_godebug_non_default_behavior_randautoseed_events_total", "/godebug/non-default-behavior/randautoseed:events": "go_godebug_non_default_behavior_randautoseed_events_total",
"/godebug/non-default-behavior/tarinsecurepath:events": "go_godebug_non_default_behavior_tarinsecurepath_events_total", "/godebug/non-default-behavior/tarinsecurepath:events": "go_godebug_non_default_behavior_tarinsecurepath_events_total",
@ -79,4 +80,4 @@ var expectedRuntimeMetrics = map[string]string{
"/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total",
} }
const expectedRuntimeMetricsCardinality = 114 const expectedRuntimeMetricsCardinality = 115

View File

@ -55,6 +55,7 @@ var expectedRuntimeMetrics = map[string]string{
"/godebug/non-default-behavior/multipartmaxheaders:events": "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "/godebug/non-default-behavior/multipartmaxheaders:events": "go_godebug_non_default_behavior_multipartmaxheaders_events_total",
"/godebug/non-default-behavior/multipartmaxparts:events": "go_godebug_non_default_behavior_multipartmaxparts_events_total", "/godebug/non-default-behavior/multipartmaxparts:events": "go_godebug_non_default_behavior_multipartmaxparts_events_total",
"/godebug/non-default-behavior/multipathtcp:events": "go_godebug_non_default_behavior_multipathtcp_events_total", "/godebug/non-default-behavior/multipathtcp:events": "go_godebug_non_default_behavior_multipathtcp_events_total",
"/godebug/non-default-behavior/netedns0:events": "go_godebug_non_default_behavior_netedns0_events_total",
"/godebug/non-default-behavior/panicnil:events": "go_godebug_non_default_behavior_panicnil_events_total", "/godebug/non-default-behavior/panicnil:events": "go_godebug_non_default_behavior_panicnil_events_total",
"/godebug/non-default-behavior/randautoseed:events": "go_godebug_non_default_behavior_randautoseed_events_total", "/godebug/non-default-behavior/randautoseed:events": "go_godebug_non_default_behavior_randautoseed_events_total",
"/godebug/non-default-behavior/tarinsecurepath:events": "go_godebug_non_default_behavior_tarinsecurepath_events_total", "/godebug/non-default-behavior/tarinsecurepath:events": "go_godebug_non_default_behavior_tarinsecurepath_events_total",
@ -90,4 +91,4 @@ var expectedRuntimeMetrics = map[string]string{
"/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total",
} }
const expectedRuntimeMetricsCardinality = 161 const expectedRuntimeMetricsCardinality = 162

View File

@ -22,14 +22,15 @@ import (
) )
type processCollector struct { type processCollector struct {
collectFn func(chan<- Metric) collectFn func(chan<- Metric)
pidFn func() (int, error) pidFn func() (int, error)
reportErrors bool reportErrors bool
cpuTotal *Desc cpuTotal *Desc
openFDs, maxFDs *Desc openFDs, maxFDs *Desc
vsize, maxVsize *Desc vsize, maxVsize *Desc
rss *Desc rss *Desc
startTime *Desc startTime *Desc
inBytes, outBytes *Desc
} }
// ProcessCollectorOpts defines the behavior of a process metrics collector // ProcessCollectorOpts defines the behavior of a process metrics collector
@ -100,6 +101,16 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector {
"Start time of the process since unix epoch in seconds.", "Start time of the process since unix epoch in seconds.",
nil, nil, nil, nil,
), ),
inBytes: NewDesc(
ns+"process_network_receive_bytes_total",
"Number of bytes received by the process over the network.",
nil, nil,
),
outBytes: NewDesc(
ns+"process_network_transmit_bytes_total",
"Number of bytes sent by the process over the network.",
nil, nil,
),
} }
if opts.PidFn == nil { if opts.PidFn == nil {

View File

@ -63,4 +63,18 @@ func (c *processCollector) processCollect(ch chan<- Metric) {
} else { } else {
c.reportError(ch, nil, err) c.reportError(ch, nil, err)
} }
if netstat, err := p.Netstat(); err == nil {
var inOctets, outOctets float64
if netstat.IpExt.InOctets != nil {
inOctets = *netstat.IpExt.InOctets
}
if netstat.IpExt.OutOctets != nil {
outOctets = *netstat.IpExt.OutOctets
}
ch <- MustNewConstMetric(c.inBytes, CounterValue, inOctets)
ch <- MustNewConstMetric(c.outBytes, CounterValue, outOctets)
} else {
c.reportError(ch, nil, err)
}
} }

View File

@ -69,6 +69,8 @@ func TestProcessCollector(t *testing.T) {
regexp.MustCompile("\nprocess_virtual_memory_bytes [1-9]"), regexp.MustCompile("\nprocess_virtual_memory_bytes [1-9]"),
regexp.MustCompile("\nprocess_resident_memory_bytes [1-9]"), regexp.MustCompile("\nprocess_resident_memory_bytes [1-9]"),
regexp.MustCompile("\nprocess_start_time_seconds [0-9.]{10,}"), regexp.MustCompile("\nprocess_start_time_seconds [0-9.]{10,}"),
regexp.MustCompile("\nprocess_network_receive_bytes_total [0-9]+"),
regexp.MustCompile("\nprocess_network_transmit_bytes_total [0-9]+"),
regexp.MustCompile("\nfoobar_process_cpu_seconds_total [0-9]"), regexp.MustCompile("\nfoobar_process_cpu_seconds_total [0-9]"),
regexp.MustCompile("\nfoobar_process_max_fds [1-9]"), regexp.MustCompile("\nfoobar_process_max_fds [1-9]"),
regexp.MustCompile("\nfoobar_process_open_fds [1-9]"), regexp.MustCompile("\nfoobar_process_open_fds [1-9]"),
@ -76,6 +78,8 @@ func TestProcessCollector(t *testing.T) {
regexp.MustCompile("\nfoobar_process_virtual_memory_bytes [1-9]"), regexp.MustCompile("\nfoobar_process_virtual_memory_bytes [1-9]"),
regexp.MustCompile("\nfoobar_process_resident_memory_bytes [1-9]"), regexp.MustCompile("\nfoobar_process_resident_memory_bytes [1-9]"),
regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9.]{10,}"), regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9.]{10,}"),
regexp.MustCompile("\nfoobar_process_network_receive_bytes_total [0-9]+"),
regexp.MustCompile("\nfoobar_process_network_transmit_bytes_total [0-9]+"),
} { } {
if !re.Match(buf.Bytes()) { if !re.Match(buf.Bytes()) {
t.Errorf("want body to match %s\n%s", re, buf.String()) t.Errorf("want body to match %s\n%s", re, buf.String())