From 099413bdd70ed27eacdbaabf91a5415d059a8406 Mon Sep 17 00:00:00 2001 From: Karl Sassenberg Date: Thu, 23 Feb 2023 17:08:10 +0000 Subject: [PATCH] feat: fixed tests and rebased with nginx/agent main --- docs/proto/proto.md | 46 +--- sdk/proto/metrics.pb.go | 70 ++---- src/core/metrics/collectors/container_test.go | 8 +- src/core/metrics/collectors/nginx_test.go | 2 +- .../metrics/collectors/source_mocks_test.go | 5 +- src/core/metrics/collectors/system_test.go | 8 +- src/core/metrics/sources/common_test.go | 7 +- .../metrics/sources/container_cpu_test.go | 9 +- .../metrics/sources/container_mem_test.go | 9 +- src/core/metrics/sources/cpu_test.go | 14 +- src/core/metrics/sources/disk_io_test.go | 6 +- src/core/metrics/sources/disk_test.go | 6 +- src/core/metrics/sources/load_test.go | 6 +- src/core/metrics/sources/mem_test.go | 6 +- src/core/metrics/sources/net_io_test.go | 6 +- .../metrics/sources/nginx_access_log_test.go | 6 +- .../metrics/sources/nginx_error_log_test.go | 6 +- src/core/metrics/sources/nginx_oss_test.go | 10 +- src/core/metrics/sources/nginx_plus_test.go | 222 +++++++++--------- .../metrics/sources/nginx_process_test.go | 12 +- src/core/metrics/sources/nginx_static_test.go | 8 +- src/core/metrics/sources/nginx_worker_test.go | 6 +- src/core/metrics/sources/swap_test.go | 9 +- src/plugins/metrics_throlling.go | 26 +- .../agent/sdk/v2/client/metric_reporter.go | 2 +- .../nginx/agent/sdk/v2/proto/metrics.pb.go | 128 +++++----- .../nginx/agent/sdk/v2/proto/metrics.proto | 45 ++-- .../nginx/agent/sdk/v2/proto/metrics.pb.go | 70 ++---- .../nginx/agent/sdk/v2/proto/metrics.proto | 75 ------ .../nginx/agent/v2/src/plugins/metrics.go | 4 - .../agent/v2/src/plugins/metrics_throlling.go | 44 ++-- .../nginx/agent/sdk/v2/proto/metrics.pb.go | 70 ++---- .../nginx/agent/sdk/v2/proto/metrics.proto | 75 ------ 33 files changed, 347 insertions(+), 679 deletions(-) diff --git a/docs/proto/proto.md b/docs/proto/proto.md index b8123f15dd..8829aa7b22 100644 --- a/docs/proto/proto.md +++ b/docs/proto/proto.md @@ -1095,8 +1095,8 @@ Dimension defines a dimensional attribute used when classifying and categorizing | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| name | [string](#string) | | Dimension name | -| value | [string](#string) | | Dimension value | +| name | [string](#string) | | | +| value | [string](#string) | | | @@ -1106,14 +1106,14 @@ Dimension defines a dimensional attribute used when classifying and categorizing ### MetricsReport -Represents a metric report + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| meta | [Metadata](#f5-nginx-agent-sdk-Metadata) | | Provides meta information about the metrics | -| type | [MetricsReport.Type](#f5-nginx-agent-sdk-MetricsReport-Type) | | Type of metrics | -| data | [StatsEntity](#f5-nginx-agent-sdk-StatsEntity) | repeated | List of stats entities | +| meta | [Metadata](#f5-nginx-agent-sdk-Metadata) | | | +| type | [MetricsReport.Type](#f5-nginx-agent-sdk-MetricsReport-Type) | | | +| data | [StatsEntity](#f5-nginx-agent-sdk-StatsEntity) | repeated | | @@ -1128,8 +1128,8 @@ Represents a metric report | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| name | [string](#string) | | Metric name | -| value | [double](#double) | | Metric value | +| name | [string](#string) | | | +| value | [double](#double) | | | @@ -1139,22 +1139,14 @@ Represents a metric report ### StatsEntity -<<<<<<< HEAD -<<<<<<< HEAD -StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics -======= StatsEntity a timestamped entry for Dimensions and Metrics ->>>>>>> Create dedicated cache and upstream metrics reports -======= -StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics ->>>>>>> adds updated generated files from protobuf | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| timestamp | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | Timestamp defines the time of stats entity creation | -| dimensions | [Dimension](#f5-nginx-agent-sdk-Dimension) | repeated | List of dimensions | -| simplemetrics | [SimpleMetric](#f5-nginx-agent-sdk-SimpleMetric) | repeated | List of metrics | +| timestamp | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | | +| dimensions | [Dimension](#f5-nginx-agent-sdk-Dimension) | repeated | | +| simplemetrics | [SimpleMetric](#f5-nginx-agent-sdk-SimpleMetric) | repeated | | @@ -1166,29 +1158,15 @@ StatsEntity defines a stats entity which is a timestamped entry for dimensions a ### MetricsReport.Type -Metric type enum + | Name | Number | Description | | ---- | ------ | ----------- | -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> adds updated generated files from protobuf -| SYSTEM | 0 | System metric type | -| INSTANCE | 1 | NGINX instance metric type | -| AGENT | 2 | Agent metric type | -| CACHE_ZONE | 3 | Cache zone metric type | -| UPSTREAMS | 4 | Upstreams metric type | -<<<<<<< HEAD -======= | SYSTEM | 0 | | | INSTANCE | 1 | | | AGENT | 2 | | | CACHE_ZONE | 3 | | | UPSTREAMS | 4 | | ->>>>>>> Create dedicated cache and upstream metrics reports -======= ->>>>>>> adds updated generated files from protobuf diff --git a/sdk/proto/metrics.pb.go b/sdk/proto/metrics.pb.go index 3143605e9c..77fefe5c51 100644 --- a/sdk/proto/metrics.pb.go +++ b/sdk/proto/metrics.pb.go @@ -25,37 +25,14 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// Metric type enum type MetricsReport_Type int32 const ( -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> adds updated generated files from protobuf - // System metric type - MetricsReport_SYSTEM MetricsReport_Type = 0 - // NGINX instance metric type - MetricsReport_INSTANCE MetricsReport_Type = 1 - // Agent metric type - MetricsReport_AGENT MetricsReport_Type = 2 - // Cache zone metric type -<<<<<<< HEAD - MetricsReport_CACHE_ZONE MetricsReport_Type = 3 - // Upstreams metric type - MetricsReport_UPSTREAMS MetricsReport_Type = 4 -======= MetricsReport_SYSTEM MetricsReport_Type = 0 MetricsReport_INSTANCE MetricsReport_Type = 1 MetricsReport_AGENT MetricsReport_Type = 2 MetricsReport_CACHE_ZONE MetricsReport_Type = 3 MetricsReport_UPSTREAMS MetricsReport_Type = 4 ->>>>>>> Create dedicated cache and upstream metrics reports -======= - MetricsReport_CACHE_ZONE MetricsReport_Type = 3 - // Upstreams metric type - MetricsReport_UPSTREAMS MetricsReport_Type = 4 ->>>>>>> adds updated generated files from protobuf ) var MetricsReport_Type_name = map[int32]string{ @@ -82,17 +59,13 @@ func (MetricsReport_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor_6039342a2ba47b72, []int{0, 0} } -// Represents a metric report type MetricsReport struct { - // Provides meta information about the metrics - Meta *Metadata `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta"` - // Type of metrics - Type MetricsReport_Type `protobuf:"varint,2,opt,name=type,proto3,enum=f5.nginx.agent.sdk.MetricsReport_Type" json:"type"` - // List of stats entities - Data []*StatsEntity `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Meta *Metadata `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta"` + Type MetricsReport_Type `protobuf:"varint,2,opt,name=type,proto3,enum=f5.nginx.agent.sdk.MetricsReport_Type" json:"type"` + Data []*StatsEntity `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *MetricsReport) Reset() { *m = MetricsReport{} } @@ -150,9 +123,7 @@ func (m *MetricsReport) GetData() []*StatsEntity { } type SimpleMetric struct { - // Metric name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` - // Metric value + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` Value float64 `protobuf:"fixed64,2,opt,name=value,proto3" json:"value"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -208,9 +179,7 @@ func (m *SimpleMetric) GetValue() float64 { // Dimension defines a dimensional attribute used when classifying and categorizing data type Dimension struct { - // Dimension name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` - // Dimension value + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -264,25 +233,14 @@ func (m *Dimension) GetValue() string { return "" } -<<<<<<< HEAD -<<<<<<< HEAD -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics -======= // StatsEntity a timestamped entry for Dimensions and Metrics ->>>>>>> Create dedicated cache and upstream metrics reports -======= -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics ->>>>>>> adds updated generated files from protobuf type StatsEntity struct { - // Timestamp defines the time of stats entity creation - Timestamp *types.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - // List of dimensions - Dimensions []*Dimension `protobuf:"bytes,3,rep,name=dimensions,proto3" json:"dimensions"` - // List of metrics - Simplemetrics []*SimpleMetric `protobuf:"bytes,4,rep,name=simplemetrics,proto3" json:"simplemetrics"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Timestamp *types.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Dimensions []*Dimension `protobuf:"bytes,3,rep,name=dimensions,proto3" json:"dimensions"` + Simplemetrics []*SimpleMetric `protobuf:"bytes,4,rep,name=simplemetrics,proto3" json:"simplemetrics"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *StatsEntity) Reset() { *m = StatsEntity{} } diff --git a/src/core/metrics/collectors/container_test.go b/src/core/metrics/collectors/container_test.go index 7951be8443..bb8cc95974 100644 --- a/src/core/metrics/collectors/container_test.go +++ b/src/core/metrics/collectors/container_test.go @@ -57,7 +57,7 @@ func TestContainerCollector_Collect(t *testing.T) { mockSource1, mockSource2, }, - buf: make(chan *proto.StatsEntity), + buf: make(chan *metrics.StatsEntityWrapper), dim: &metrics.CommonDim{}, } @@ -65,10 +65,10 @@ func TestContainerCollector_Collect(t *testing.T) { wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity) + channel := make(chan *metrics.StatsEntityWrapper) go containerCollector.Collect(ctx, wg, channel) - containerCollector.buf <- &proto.StatsEntity{Dimensions: []*proto.Dimension{{Name: "new_dim", Value: "123"}}} + containerCollector.buf <- &metrics.StatsEntityWrapper{Type: proto.MetricsReport_SYSTEM, Data: &proto.StatsEntity{Dimensions: []*proto.Dimension{{Name: "new_dim", Value: "123"}}}} actual := <-channel mockSource1.AssertExpectations(t) @@ -83,7 +83,7 @@ func TestContainerCollector_Collect(t *testing.T) { {Name: "nginx_id", Value: ""}, {Name: "new_dim", Value: "123"}, } - assert.Equal(t, expectedDimensions, actual.Dimensions) + assert.Equal(t, expectedDimensions, actual.Data.Dimensions) } func TestContainerCollector_UpdateConfig(t *testing.T) { diff --git a/src/core/metrics/collectors/nginx_test.go b/src/core/metrics/collectors/nginx_test.go index 552adf7789..72372fc313 100644 --- a/src/core/metrics/collectors/nginx_test.go +++ b/src/core/metrics/collectors/nginx_test.go @@ -169,7 +169,7 @@ func TestNginxCollector_Collect(t *testing.T) { ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) - go nginxCollector.Collect(ctx, wg, make(chan<- *proto.StatsEntity)) + go nginxCollector.Collect(ctx, wg, make(chan<- *metrics.StatsEntityWrapper)) time.Sleep(10 * time.Millisecond) mockNginxSource1.AssertExpectations(t) diff --git a/src/core/metrics/collectors/source_mocks_test.go b/src/core/metrics/collectors/source_mocks_test.go index d61fe2da36..b6fa5a5ad2 100644 --- a/src/core/metrics/collectors/source_mocks_test.go +++ b/src/core/metrics/collectors/source_mocks_test.go @@ -11,7 +11,6 @@ import ( "context" "sync" - "github.com/nginx/agent/sdk/v2/proto" "github.com/nginx/agent/v2/src/core/metrics" "github.com/stretchr/testify/mock" ) @@ -26,7 +25,7 @@ type NginxSourceMock struct { mock.Mock } -func (m *NginxSourceMock) Collect(ctx context.Context, wg *sync.WaitGroup, statsChannel chan<- *proto.StatsEntity) { +func (m *NginxSourceMock) Collect(ctx context.Context, wg *sync.WaitGroup, statsChannel chan<- *metrics.StatsEntityWrapper) { m.Called(ctx, wg, statsChannel) wg.Done() } @@ -43,7 +42,7 @@ type SourceMock struct { mock.Mock } -func (m *SourceMock) Collect(ctx context.Context, wg *sync.WaitGroup, statsChannel chan<- *proto.StatsEntity) { +func (m *SourceMock) Collect(ctx context.Context, wg *sync.WaitGroup, statsChannel chan<- *metrics.StatsEntityWrapper) { m.Called(ctx, wg, statsChannel) wg.Done() } diff --git a/src/core/metrics/collectors/system_test.go b/src/core/metrics/collectors/system_test.go index 9462d9439e..a7cd9bdebc 100644 --- a/src/core/metrics/collectors/system_test.go +++ b/src/core/metrics/collectors/system_test.go @@ -89,7 +89,7 @@ func TestSystemCollector_Collect(t *testing.T) { mockSource1, mockSource2, }, - buf: make(chan *proto.StatsEntity), + buf: make(chan *metrics.StatsEntityWrapper), dim: &metrics.CommonDim{}, } @@ -97,10 +97,10 @@ func TestSystemCollector_Collect(t *testing.T) { wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity) + channel := make(chan *metrics.StatsEntityWrapper) go systemCollector.Collect(ctx, wg, channel) - systemCollector.buf <- &proto.StatsEntity{Dimensions: []*proto.Dimension{{Name: "new_dim", Value: "123"}}} + systemCollector.buf <- &metrics.StatsEntityWrapper{Type: proto.MetricsReport_SYSTEM, Data: &proto.StatsEntity{Dimensions: []*proto.Dimension{{Name: "new_dim", Value: "123"}}}} actual := <-channel mockSource1.AssertExpectations(t) @@ -115,7 +115,7 @@ func TestSystemCollector_Collect(t *testing.T) { {Name: "nginx_id", Value: ""}, {Name: "new_dim", Value: "123"}, } - assert.Equal(t, expectedDimensions, actual.Dimensions) + assert.Equal(t, expectedDimensions, actual.Data.Dimensions) } func TestSystemCollector_UpdateConfig(t *testing.T) { diff --git a/src/core/metrics/sources/common_test.go b/src/core/metrics/sources/common_test.go index fa63717a45..5d55917b51 100644 --- a/src/core/metrics/sources/common_test.go +++ b/src/core/metrics/sources/common_test.go @@ -9,6 +9,7 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "sort" "testing" @@ -180,10 +181,10 @@ func TestCommonDelta(t *testing.T) { } func TestCommonSendNginxDownStatus(t *testing.T) { - m := make(chan *proto.StatsEntity, 1) + m := make(chan *metrics.StatsEntityWrapper, 1) expected := &proto.SimpleMetric{Name: "nginx.status", Value: 0.0} SendNginxDownStatus(context.TODO(), []*proto.Dimension{}, m) actual := <-m - assert.Equal(t, 1, len(actual.Simplemetrics)) - assert.Equal(t, expected, actual.Simplemetrics[0]) + assert.Equal(t, 1, len(actual.Data.Simplemetrics)) + assert.Equal(t, expected, actual.Data.Simplemetrics[0]) } diff --git a/src/core/metrics/sources/container_cpu_test.go b/src/core/metrics/sources/container_cpu_test.go index cd8c302609..9487543903 100644 --- a/src/core/metrics/sources/container_cpu_test.go +++ b/src/core/metrics/sources/container_cpu_test.go @@ -9,6 +9,7 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "path" "runtime" "sort" @@ -116,7 +117,7 @@ func TestContainerCPUSource(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - actual := make(chan *proto.StatsEntity, 1) + actual := make(chan *metrics.StatsEntityWrapper, 1) ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) @@ -130,10 +131,10 @@ func TestContainerCPUSource(t *testing.T) { sort.SliceStable(test.stats.Simplemetrics, func(i, j int) bool { return test.stats.Simplemetrics[i].Name < test.stats.Simplemetrics[j].Name }) - sort.SliceStable(result.Simplemetrics, func(i, j int) bool { - return result.Simplemetrics[i].Name < result.Simplemetrics[j].Name + sort.SliceStable(result.Data.Simplemetrics, func(i, j int) bool { + return result.Data.Simplemetrics[i].Name < result.Data.Simplemetrics[j].Name }) - assert.Equal(tt, test.stats.Simplemetrics, result.Simplemetrics) + assert.Equal(tt, test.stats.Simplemetrics, result.Data.Simplemetrics) case <-time.After(10 * time.Millisecond): assert.Nil(tt, test.stats) } diff --git a/src/core/metrics/sources/container_mem_test.go b/src/core/metrics/sources/container_mem_test.go index 5ba1f5202a..d7ca4eb76f 100644 --- a/src/core/metrics/sources/container_mem_test.go +++ b/src/core/metrics/sources/container_mem_test.go @@ -9,6 +9,7 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "path" "runtime" "sort" @@ -60,7 +61,7 @@ func TestContainerMemorySource(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - actual := make(chan *proto.StatsEntity, 1) + actual := make(chan *metrics.StatsEntityWrapper, 1) ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) @@ -74,10 +75,10 @@ func TestContainerMemorySource(t *testing.T) { sort.SliceStable(test.stats.Simplemetrics, func(i, j int) bool { return test.stats.Simplemetrics[i].Name < test.stats.Simplemetrics[j].Name }) - sort.SliceStable(result.Simplemetrics, func(i, j int) bool { - return result.Simplemetrics[i].Name < result.Simplemetrics[j].Name + sort.SliceStable(result.Data.Simplemetrics, func(i, j int) bool { + return result.Data.Simplemetrics[i].Name < result.Data.Simplemetrics[j].Name }) - assert.Equal(tt, test.stats.Simplemetrics, result.Simplemetrics) + assert.Equal(tt, test.stats.Simplemetrics, result.Data.Simplemetrics) case <-time.After(10 * time.Millisecond): assert.Nil(tt, test.stats) } diff --git a/src/core/metrics/sources/cpu_test.go b/src/core/metrics/sources/cpu_test.go index 2ab0330b9e..dcf6d97659 100644 --- a/src/core/metrics/sources/cpu_test.go +++ b/src/core/metrics/sources/cpu_test.go @@ -9,13 +9,13 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "path" "runtime" "sort" "sync" "testing" - "github.com/nginx/agent/sdk/v2/proto" cgroup "github.com/nginx/agent/v2/src/core/metrics/sources/cgroup" tutils "github.com/nginx/agent/v2/test/utils" @@ -108,14 +108,14 @@ func TestCPUTimesCollect_VM(t *testing.T) { ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity, 1) + channel := make(chan *metrics.StatsEntityWrapper, 1) cpuTimes.Collect(ctx, wg, channel) wg.Wait() actual := <-channel actualMetricNames := []string{} - for _, simpleMetric := range actual.Simplemetrics { + for _, simpleMetric := range actual.Data.Simplemetrics { actualMetricNames = append(actualMetricNames, simpleMetric.Name) switch simpleMetric.Name { case "test.cpu.idle": @@ -151,14 +151,14 @@ func TestCPUTimesCollect_VM(t *testing.T) { ctx = context.TODO() wg = &sync.WaitGroup{} wg.Add(1) - channel = make(chan *proto.StatsEntity, 1) + channel = make(chan *metrics.StatsEntityWrapper, 1) cpuTimes.Collect(ctx, wg, channel) wg.Wait() actual = <-channel actualMetricNames = []string{} - for _, simpleMetric := range actual.Simplemetrics { + for _, simpleMetric := range actual.Data.Simplemetrics { actualMetricNames = append(actualMetricNames, simpleMetric.Name) switch simpleMetric.Name { case "test.cpu.idle": @@ -194,13 +194,13 @@ func TestCPUTimesCollect_Container(t *testing.T) { ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity, 1) + channel := make(chan *metrics.StatsEntityWrapper, 1) cpuTimes.Collect(ctx, wg, channel) wg.Wait() actual := <-channel actualMetricNames := []string{} - for _, simpleMetric := range actual.Simplemetrics { + for _, simpleMetric := range actual.Data.Simplemetrics { actualMetricNames = append(actualMetricNames, simpleMetric.Name) } sort.Strings(actualMetricNames) diff --git a/src/core/metrics/sources/disk_io_test.go b/src/core/metrics/sources/disk_io_test.go index 37452c5e85..d6a3fa9678 100644 --- a/src/core/metrics/sources/disk_io_test.go +++ b/src/core/metrics/sources/disk_io_test.go @@ -9,11 +9,11 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "sort" "sync" "testing" - "github.com/nginx/agent/sdk/v2/proto" tutils "github.com/nginx/agent/v2/test/utils" "github.com/shirou/gopsutil/v3/disk" "github.com/stretchr/testify/assert" @@ -40,14 +40,14 @@ func TestDiskIOCollect(t *testing.T) { ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity, 100) + channel := make(chan *metrics.StatsEntityWrapper, 100) diskio.Collect(ctx, wg, channel) wg.Wait() actual := <-channel actualMetricNames := []string{} - for _, simpleMetric := range actual.Simplemetrics { + for _, simpleMetric := range actual.Data.Simplemetrics { actualMetricNames = append(actualMetricNames, simpleMetric.Name) } sort.Strings(actualMetricNames) diff --git a/src/core/metrics/sources/disk_test.go b/src/core/metrics/sources/disk_test.go index dbc0d0fbe5..ac5f552b38 100644 --- a/src/core/metrics/sources/disk_test.go +++ b/src/core/metrics/sources/disk_test.go @@ -9,11 +9,11 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "sort" "sync" "testing" - "github.com/nginx/agent/sdk/v2/proto" "github.com/stretchr/testify/assert" ) @@ -33,14 +33,14 @@ func TestDiskCollect(t *testing.T) { ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity, 100) + channel := make(chan *metrics.StatsEntityWrapper, 100) disk.Collect(ctx, wg, channel) wg.Wait() actual := <-channel actualMetricNames := []string{} - for _, simpleMetric := range actual.Simplemetrics { + for _, simpleMetric := range actual.Data.Simplemetrics { actualMetricNames = append(actualMetricNames, simpleMetric.Name) } sort.Strings(actualMetricNames) diff --git a/src/core/metrics/sources/load_test.go b/src/core/metrics/sources/load_test.go index 5c76280d6c..756b704f21 100644 --- a/src/core/metrics/sources/load_test.go +++ b/src/core/metrics/sources/load_test.go @@ -9,11 +9,11 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "sort" "sync" "testing" - "github.com/nginx/agent/sdk/v2/proto" "github.com/shirou/gopsutil/v3/load" "github.com/stretchr/testify/assert" ) @@ -37,14 +37,14 @@ func TestLoadCollect(t *testing.T) { ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity, 100) + channel := make(chan *metrics.StatsEntityWrapper, 100) loadSource.Collect(ctx, wg, channel) wg.Wait() actual := <-channel actualMetricNames := []string{} - for _, simpleMetric := range actual.Simplemetrics { + for _, simpleMetric := range actual.Data.Simplemetrics { actualMetricNames = append(actualMetricNames, simpleMetric.Name) } sort.Strings(actualMetricNames) diff --git a/src/core/metrics/sources/mem_test.go b/src/core/metrics/sources/mem_test.go index ff78c04c75..b0fced9f63 100644 --- a/src/core/metrics/sources/mem_test.go +++ b/src/core/metrics/sources/mem_test.go @@ -9,11 +9,11 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "sort" "sync" "testing" - "github.com/nginx/agent/sdk/v2/proto" cgroup "github.com/nginx/agent/v2/src/core/metrics/sources/cgroup" tutils "github.com/nginx/agent/v2/test/utils" "github.com/shirou/gopsutil/v3/mem" @@ -58,14 +58,14 @@ func TestVirtualMemoryCollect(t *testing.T) { ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity, 1) + channel := make(chan *metrics.StatsEntityWrapper, 1) go virtualMemorySource.Collect(ctx, wg, channel) wg.Wait() actual := <-channel actualMetricNames := []string{} - for _, simpleMetric := range actual.Simplemetrics { + for _, simpleMetric := range actual.Data.Simplemetrics { actualMetricNames = append(actualMetricNames, simpleMetric.Name) } sort.Strings(actualMetricNames) diff --git a/src/core/metrics/sources/net_io_test.go b/src/core/metrics/sources/net_io_test.go index 1f04949be3..fa388fda19 100644 --- a/src/core/metrics/sources/net_io_test.go +++ b/src/core/metrics/sources/net_io_test.go @@ -9,11 +9,11 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "sort" "sync" "testing" - "github.com/nginx/agent/sdk/v2/proto" tutils "github.com/nginx/agent/v2/test/utils" "github.com/shirou/gopsutil/v3/net" "github.com/stretchr/testify/assert" @@ -48,14 +48,14 @@ func TestNetIOCollect(t *testing.T) { ctx := context.TODO() wg := &sync.WaitGroup{} wg.Add(1) - channel := make(chan *proto.StatsEntity, 100) + channel := make(chan *metrics.StatsEntityWrapper, 100) nioSource.Collect(ctx, wg, channel) wg.Wait() actual := <-channel actualMetricNames := []string{} - for _, simpleMetric := range actual.Simplemetrics { + for _, simpleMetric := range actual.Data.Simplemetrics { actualMetricNames = append(actualMetricNames, simpleMetric.Name) } sort.Strings(actualMetricNames) diff --git a/src/core/metrics/sources/nginx_access_log_test.go b/src/core/metrics/sources/nginx_access_log_test.go index a4e13b85c1..441bc036d0 100644 --- a/src/core/metrics/sources/nginx_access_log_test.go +++ b/src/core/metrics/sources/nginx_access_log_test.go @@ -740,11 +740,11 @@ func TestAccessLogStats(t *testing.T) { sort.SliceStable(test.expectedStats.GetSimplemetrics(), func(i, j int) bool { return test.expectedStats.GetSimplemetrics()[i].Name < test.expectedStats.GetSimplemetrics()[j].Name }) - sort.SliceStable(nginxAccessLog.buf[0].GetSimplemetrics(), func(i, j int) bool { - return nginxAccessLog.buf[0].GetSimplemetrics()[i].Name < nginxAccessLog.buf[0].GetSimplemetrics()[j].Name + sort.SliceStable(nginxAccessLog.buf[0].Data.GetSimplemetrics(), func(i, j int) bool { + return nginxAccessLog.buf[0].Data.GetSimplemetrics()[i].Name < nginxAccessLog.buf[0].Data.GetSimplemetrics()[j].Name }) - assert.Equal(tt, test.expectedStats.GetSimplemetrics(), nginxAccessLog.buf[0].GetSimplemetrics()) + assert.Equal(tt, test.expectedStats.GetSimplemetrics(), nginxAccessLog.buf[0].Data.GetSimplemetrics()) }) } } diff --git a/src/core/metrics/sources/nginx_error_log_test.go b/src/core/metrics/sources/nginx_error_log_test.go index 8e5e4bdb9d..0141c30a80 100644 --- a/src/core/metrics/sources/nginx_error_log_test.go +++ b/src/core/metrics/sources/nginx_error_log_test.go @@ -133,11 +133,11 @@ func TestErrorLogStats(t *testing.T) { sort.SliceStable(test.expectedStats.GetSimplemetrics(), func(i, j int) bool { return test.expectedStats.GetSimplemetrics()[i].Name < test.expectedStats.GetSimplemetrics()[j].Name }) - sort.SliceStable(nginxErrorLog.buf[0].GetSimplemetrics(), func(i, j int) bool { - return nginxErrorLog.buf[0].GetSimplemetrics()[i].Name < nginxErrorLog.buf[0].GetSimplemetrics()[j].Name + sort.SliceStable(nginxErrorLog.buf[0].Data.GetSimplemetrics(), func(i, j int) bool { + return nginxErrorLog.buf[0].Data.GetSimplemetrics()[i].Name < nginxErrorLog.buf[0].Data.GetSimplemetrics()[j].Name }) - assert.Equal(tt, test.expectedStats.GetSimplemetrics(), nginxErrorLog.buf[0].GetSimplemetrics()) + assert.Equal(tt, test.expectedStats.GetSimplemetrics(), nginxErrorLog.buf[0].Data.GetSimplemetrics()) }) } } diff --git a/src/core/metrics/sources/nginx_oss_test.go b/src/core/metrics/sources/nginx_oss_test.go index aa636273cd..857e8bdf77 100644 --- a/src/core/metrics/sources/nginx_oss_test.go +++ b/src/core/metrics/sources/nginx_oss_test.go @@ -66,14 +66,14 @@ Reading: 0 Writing: 1 Waiting: 0 name string namedMetric *namedMetric stubAPI string - m chan *proto.StatsEntity + m chan *metrics.StatsEntityWrapper expectedMetrics map[string]float64 }{ { "valid stub API", &namedMetric{namespace: "nginx", group: "http"}, server.URL + "/basic_status", - make(chan *proto.StatsEntity, 1), + make(chan *metrics.StatsEntityWrapper, 1), map[string]float64{ "nginx.status": float64(1), "nginx.http.conn.active": float64(1), @@ -90,7 +90,7 @@ Reading: 0 Writing: 1 Waiting: 0 "unknown stub API", &namedMetric{namespace: "nginx", group: "http"}, server.URL + "/unknown", - make(chan *proto.StatsEntity, 1), + make(chan *metrics.StatsEntityWrapper, 1), map[string]float64{ "nginx.status": float64(0), }, @@ -113,8 +113,8 @@ Reading: 0 Writing: 1 Waiting: 0 go c.Collect(ctx, wg, test.m) wg.Wait() statEntity := <-test.m - assert.Len(tt, statEntity.Simplemetrics, len(test.expectedMetrics)) - for _, metric := range statEntity.Simplemetrics { + assert.Len(tt, statEntity.Data.Simplemetrics, len(test.expectedMetrics)) + for _, metric := range statEntity.Data.Simplemetrics { assert.Contains(t, test.expectedMetrics, metric.Name) assert.Equal(t, test.expectedMetrics[metric.Name], metric.Value) } diff --git a/src/core/metrics/sources/nginx_plus_test.go b/src/core/metrics/sources/nginx_plus_test.go index b211371afc..d40e8a2c23 100644 --- a/src/core/metrics/sources/nginx_plus_test.go +++ b/src/core/metrics/sources/nginx_plus_test.go @@ -70,7 +70,7 @@ type FakeNginxPlus struct { } // Collect is fake collector that hard codes a stats struct response to avoid dependency on external NGINX Plus api -func (f *FakeNginxPlus) Collect(ctx context.Context, wg *sync.WaitGroup, m chan<- *proto.StatsEntity) { +func (f *FakeNginxPlus) Collect(ctx context.Context, wg *sync.WaitGroup, m chan<- *metrics.StatsEntityWrapper) { defer wg.Done() stats := plusclient.Stats{ HTTPRequests: plusclient.HTTPRequests{ @@ -639,11 +639,11 @@ func TestNginxPlus_Collect(t *testing.T) { } tests := []struct { baseDimensions *metrics.CommonDim - m chan *proto.StatsEntity + m chan *metrics.StatsEntityWrapper }{ { baseDimensions: metrics.NewCommonDim(hostInfo, &config.Config{}, ""), - m: make(chan *proto.StatsEntity, 127), + m: make(chan *metrics.StatsEntityWrapper, 127), }, } @@ -657,8 +657,8 @@ func TestNginxPlus_Collect(t *testing.T) { wg.Wait() instanceMetrics := <-test.m - assert.Len(t, instanceMetrics.Simplemetrics, len(expectedInstanceMetrics)) - for _, metric := range instanceMetrics.Simplemetrics { + assert.Len(t, instanceMetrics.Data.Simplemetrics, len(expectedInstanceMetrics)) + for _, metric := range instanceMetrics.Data.Simplemetrics { assert.Contains(t, expectedInstanceMetrics, metric.Name) switch metric.Name { case "nginx.status": @@ -669,8 +669,8 @@ func TestNginxPlus_Collect(t *testing.T) { } commonMetrics := <-test.m - assert.Len(t, commonMetrics.Simplemetrics, len(expectedCommonMetrics)) - for _, metric := range commonMetrics.Simplemetrics { + assert.Len(t, commonMetrics.Data.Simplemetrics, len(expectedCommonMetrics)) + for _, metric := range commonMetrics.Data.Simplemetrics { assert.Contains(t, expectedCommonMetrics, metric.Name) switch metric.Name { case "nginx.http.request.count": // delta of sum @@ -681,20 +681,20 @@ func TestNginxPlus_Collect(t *testing.T) { } sslMetrics := <-test.m - assert.Len(t, sslMetrics.Simplemetrics, len(expectedSSLMetrics)) - for _, metric := range sslMetrics.Simplemetrics { + assert.Len(t, sslMetrics.Data.Simplemetrics, len(expectedSSLMetrics)) + for _, metric := range sslMetrics.Data.Simplemetrics { assert.Contains(t, expectedSSLMetrics, metric.Name) } serverZoneMetrics := <-test.m - assert.Len(t, serverZoneMetrics.Simplemetrics, len(expectedServerZoneMetrics)) - for _, dimension := range serverZoneMetrics.Dimensions { + assert.Len(t, serverZoneMetrics.Data.Simplemetrics, len(expectedServerZoneMetrics)) + for _, dimension := range serverZoneMetrics.Data.Dimensions { switch dimension.Name { case "server_zone": assert.Equal(t, serverZoneName, dimension.Value) } } - for _, metric := range serverZoneMetrics.Simplemetrics { + for _, metric := range serverZoneMetrics.Data.Simplemetrics { assert.Contains(t, expectedServerZoneMetrics, metric.Name) switch metric.Name { case "plus.http.request.count": @@ -711,14 +711,14 @@ func TestNginxPlus_Collect(t *testing.T) { } streamServerZoneMetrics := <-test.m - assert.Len(t, streamServerZoneMetrics.Simplemetrics, len(expectedStreamServerZoneMetrics)) - for _, dimension := range streamServerZoneMetrics.Dimensions { + assert.Len(t, streamServerZoneMetrics.Data.Simplemetrics, len(expectedStreamServerZoneMetrics)) + for _, dimension := range streamServerZoneMetrics.Data.Dimensions { switch dimension.Name { case "server_zone": assert.Equal(t, streamServerZoneName, dimension.Value) } } - for _, metric := range streamServerZoneMetrics.Simplemetrics { + for _, metric := range streamServerZoneMetrics.Data.Simplemetrics { assert.Contains(t, expectedStreamServerZoneMetrics, metric.Name) switch metric.Name { case "plus.stream.connections": @@ -735,14 +735,14 @@ func TestNginxPlus_Collect(t *testing.T) { } locationZoneMetrics := <-test.m - assert.Len(t, locationZoneMetrics.Simplemetrics, len(expectedLocationZoneMetrics)) - for _, dimension := range locationZoneMetrics.Dimensions { + assert.Len(t, locationZoneMetrics.Data.Simplemetrics, len(expectedLocationZoneMetrics)) + for _, dimension := range locationZoneMetrics.Data.Dimensions { switch dimension.Name { case "location_zone": assert.Equal(t, locationZoneName, dimension.Value) } } - for _, metric := range locationZoneMetrics.Simplemetrics { + for _, metric := range locationZoneMetrics.Data.Simplemetrics { assert.Contains(t, expectedLocationZoneMetrics, metric.Name) switch metric.Name { case "plus.http.request.count": @@ -758,15 +758,89 @@ func TestNginxPlus_Collect(t *testing.T) { } } + slabMetrics := <-test.m + assert.Len(t, slabMetrics.Data.Simplemetrics, len(expectedSlabMetrics)) + for _, dimension := range slabMetrics.Data.Dimensions { + switch dimension.Name { + case "zone": + assert.Equal(t, serverZoneName, dimension.Value) + } + } + for _, metric := range slabMetrics.Data.Simplemetrics { + assert.Contains(t, expectedSlabMetrics, metric.Name) + switch metric.Name { + case "plus.slab.pages.used": + assert.Equal(t, expectedSlabMetrics["plus.slab.pages.used"], metric.Value) + case "plus.slab.pages.free": + assert.Equal(t, expectedSlabMetrics["plus.slab.pages.free"], metric.Value) + case "plus.slab.pages.total": + assert.Equal(t, expectedSlabMetrics["plus.slab.pages.total"], metric.Value) + case "plus.slab.pages.pct_used": + assert.Equal(t, expectedSlabMetrics["plus.slab.pages.pct_used"], metric.Value) + } + } + + slabSlotsMetrics := <-test.m + assert.Len(t, slabSlotsMetrics.Data.Simplemetrics, len(expectedSlabSlotMetrics)) + for _, metric := range slabSlotsMetrics.Data.Simplemetrics { + assert.Contains(t, expectedSlabSlotMetrics, metric.Name) + assert.Equal(t, expectedSlabSlotMetrics[metric.Name], metric.Value) + } + + limitConnectionsMetrics := <-test.m + assert.Len(t, limitConnectionsMetrics.Data.Simplemetrics, len(expectedHTTPLimitConnsMetrics)) + for _, dimension := range limitConnectionsMetrics.Data.Dimensions { + switch dimension.Name { + case "limit_conn_zone": + assert.Equal(t, limitConnectionsName, dimension.Value) + } + } + for _, metric := range limitConnectionsMetrics.Data.Simplemetrics { + assert.Contains(t, expectedHTTPLimitConnsMetrics, metric.Name) + switch metric.Name { + case "plus.http.limit_conns.passed": + assert.Equal(t, expectedHTTPLimitConnsMetrics["plus.http.limit_conns.passed"], metric.Value) + case "plus.http.limit_conns.rejected": + assert.Equal(t, expectedHTTPLimitConnsMetrics["plus.http.limit_conns.rejected"], metric.Value) + case "plus.http.limit_conns.rejected_dry_run": + assert.Equal(t, expectedHTTPLimitConnsMetrics["plus.http.limit_conns.rejected_dry_run"], metric.Value) + } + } + + limitRequestsMetrics := <-test.m + assert.Len(t, limitRequestsMetrics.Data.Simplemetrics, len(expectedHTTPLimitReqsMetrics)) + for _, dimension := range limitRequestsMetrics.Data.Dimensions { + switch dimension.Name { + case "limit_req_zone": + assert.Equal(t, limitRequestName, dimension.Value) + + } + } + for _, metric := range limitRequestsMetrics.Data.Simplemetrics { + assert.Contains(t, expectedHTTPLimitReqsMetrics, metric.Name) + switch metric.Name { + case "plus.http.limit_reqs.passed": + assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.passed"], metric.Value) + case "plus.http.limit_reqs.delayed": + assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.delayed"], metric.Value) + case "plus.http.limit_reqs.rejected": + assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.rejected"], metric.Value) + case "plus.http.limit_reqs.delayed_dry_run": + assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.delayed_dry_run"], metric.Value) + case "plus.http.limit_reqs.rejected_dry_run": + assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.rejected_dry_run"], metric.Value) + } + } + cacheZoneMetrics := <-test.m - assert.Len(t, cacheZoneMetrics.Simplemetrics, len(expectedCacheZoneMetrics)) - for _, dimension := range cacheZoneMetrics.Dimensions { + assert.Len(t, cacheZoneMetrics.Data.Simplemetrics, len(expectedCacheZoneMetrics)) + for _, dimension := range cacheZoneMetrics.Data.Dimensions { switch dimension.Name { case "cache_zone": assert.Equal(t, cacheZoneName, dimension.Value) } } - for _, metric := range cacheZoneMetrics.Simplemetrics { + for _, metric := range cacheZoneMetrics.Data.Simplemetrics { assert.Contains(t, expectedCacheZoneMetrics, metric.Name) switch metric.Name { case "plus.cache.size": @@ -785,8 +859,8 @@ func TestNginxPlus_Collect(t *testing.T) { } httpPeer1upstreamMetrics := <-test.m - assert.Len(t, httpPeer1upstreamMetrics.Simplemetrics, len(expectedHttpPeer1UpstreamMetrics)) - for _, dimension := range httpPeer1upstreamMetrics.Dimensions { + assert.Len(t, httpPeer1upstreamMetrics.Data.Simplemetrics, len(expectedHttpPeer1UpstreamMetrics)) + for _, dimension := range httpPeer1upstreamMetrics.Data.Dimensions { switch dimension.Name { case "upstream": assert.Equal(t, upstreamName, dimension.Value) @@ -798,7 +872,7 @@ func TestNginxPlus_Collect(t *testing.T) { assert.Equal(t, upstreamPeer1ServerAddress, dimension.Value) } } - for _, metric := range httpPeer1upstreamMetrics.Simplemetrics { + for _, metric := range httpPeer1upstreamMetrics.Data.Simplemetrics { assert.Contains(t, expectedHttpPeer1UpstreamMetrics, metric.Name) switch metric.Name { case "plus.http.upstream.peers.header_time": @@ -821,8 +895,8 @@ func TestNginxPlus_Collect(t *testing.T) { } httpPeer2upstreamMetrics := <-test.m - assert.Len(t, httpPeer2upstreamMetrics.Simplemetrics, len(expectedHttpPeer2UpstreamMetrics)) - for _, dimension := range httpPeer2upstreamMetrics.Dimensions { + assert.Len(t, httpPeer2upstreamMetrics.Data.Simplemetrics, len(expectedHttpPeer2UpstreamMetrics)) + for _, dimension := range httpPeer2upstreamMetrics.Data.Dimensions { switch dimension.Name { case "upstream": assert.Equal(t, upstreamName, dimension.Value) @@ -834,7 +908,7 @@ func TestNginxPlus_Collect(t *testing.T) { assert.Equal(t, upstreamPeer2ServerAddress, dimension.Value) } } - for _, metric := range httpPeer2upstreamMetrics.Simplemetrics { + for _, metric := range httpPeer2upstreamMetrics.Data.Simplemetrics { assert.Contains(t, expectedHttpPeer2UpstreamMetrics, metric.Name) switch metric.Name { case "plus.http.upstream.peers.header_time": @@ -857,8 +931,8 @@ func TestNginxPlus_Collect(t *testing.T) { } httpUpstreamMetrics := <-test.m - assert.Len(t, httpUpstreamMetrics.Simplemetrics, len(expectedHttpUpstreamMetrics)) - for _, dimension := range httpUpstreamMetrics.Dimensions { + assert.Len(t, httpUpstreamMetrics.Data.Simplemetrics, len(expectedHttpUpstreamMetrics)) + for _, dimension := range httpUpstreamMetrics.Data.Dimensions { switch dimension.Name { case "upstream": assert.Equal(t, upstreamName, dimension.Value) @@ -866,7 +940,7 @@ func TestNginxPlus_Collect(t *testing.T) { assert.Equal(t, upstreamZoneName, dimension.Value) } } - for _, metric := range httpUpstreamMetrics.Simplemetrics { + for _, metric := range httpUpstreamMetrics.Data.Simplemetrics { assert.Contains(t, expectedHttpUpstreamMetrics, metric.Name) switch metric.Name { case "plus.http.upstream.queue.maxsize": @@ -881,8 +955,8 @@ func TestNginxPlus_Collect(t *testing.T) { } streamPeer1upstreamMetrics := <-test.m - assert.Len(t, streamPeer1upstreamMetrics.Simplemetrics, len(expectedStreamPeer1UpstreamMetrics)) - for _, dimension := range streamPeer1upstreamMetrics.Dimensions { + assert.Len(t, streamPeer1upstreamMetrics.Data.Simplemetrics, len(expectedStreamPeer1UpstreamMetrics)) + for _, dimension := range streamPeer1upstreamMetrics.Data.Dimensions { switch dimension.Name { case "upstream": assert.Equal(t, upstreamName, dimension.Value) @@ -894,7 +968,7 @@ func TestNginxPlus_Collect(t *testing.T) { assert.Equal(t, streamUpstreamPeer1ServerAddress, dimension.Value) } } - for _, metric := range streamPeer1upstreamMetrics.Simplemetrics { + for _, metric := range streamPeer1upstreamMetrics.Data.Simplemetrics { assert.Contains(t, expectedStreamPeer1UpstreamMetrics, metric.Name) switch metric.Name { case "plus.stream.upstream.peers.conn.active": @@ -917,8 +991,8 @@ func TestNginxPlus_Collect(t *testing.T) { } streamUpstreamMetrics := <-test.m - assert.Len(t, streamUpstreamMetrics.Simplemetrics, len(expectedStreamUpstreamMetrics)) - for _, dimension := range streamUpstreamMetrics.Dimensions { + assert.Len(t, streamUpstreamMetrics.Data.Simplemetrics, len(expectedStreamUpstreamMetrics)) + for _, dimension := range streamUpstreamMetrics.Data.Dimensions { switch dimension.Name { case "upstream": assert.Equal(t, upstreamName, dimension.Value) @@ -926,7 +1000,7 @@ func TestNginxPlus_Collect(t *testing.T) { assert.Equal(t, upstreamZoneName, dimension.Value) } } - for _, metric := range streamUpstreamMetrics.Simplemetrics { + for _, metric := range streamUpstreamMetrics.Data.Simplemetrics { assert.Contains(t, expectedStreamUpstreamMetrics, metric.Name) switch metric.Name { case "plus.stream.upstream.zombies": @@ -938,81 +1012,7 @@ func TestNginxPlus_Collect(t *testing.T) { } } - slabMetrics := <-test.m - assert.Len(t, slabMetrics.Simplemetrics, len(expectedSlabMetrics)) - for _, dimension := range slabMetrics.Dimensions { - switch dimension.Name { - case "zone": - assert.Equal(t, serverZoneName, dimension.Value) - } - } - for _, metric := range slabMetrics.Simplemetrics { - assert.Contains(t, expectedSlabMetrics, metric.Name) - switch metric.Name { - case "plus.slab.pages.used": - assert.Equal(t, expectedSlabMetrics["plus.slab.pages.used"], metric.Value) - case "plus.slab.pages.free": - assert.Equal(t, expectedSlabMetrics["plus.slab.pages.free"], metric.Value) - case "plus.slab.pages.total": - assert.Equal(t, expectedSlabMetrics["plus.slab.pages.total"], metric.Value) - case "plus.slab.pages.pct_used": - assert.Equal(t, expectedSlabMetrics["plus.slab.pages.pct_used"], metric.Value) - } - } - - slabSlotsMetrics := <-test.m - assert.Len(t, slabSlotsMetrics.Simplemetrics, len(expectedSlabSlotMetrics)) - for _, metric := range slabSlotsMetrics.Simplemetrics { - assert.Contains(t, expectedSlabSlotMetrics, metric.Name) - assert.Equal(t, expectedSlabSlotMetrics[metric.Name], metric.Value) - } - - limitConnectionsMetrics := <-test.m - assert.Len(t, limitConnectionsMetrics.Simplemetrics, len(expectedHTTPLimitConnsMetrics)) - for _, dimension := range limitConnectionsMetrics.Dimensions { - switch dimension.Name { - case "limit_conn_zone": - assert.Equal(t, limitConnectionsName, dimension.Value) - } - } - for _, metric := range limitConnectionsMetrics.Simplemetrics { - assert.Contains(t, expectedHTTPLimitConnsMetrics, metric.Name) - switch metric.Name { - case "plus.http.limit_conns.passed": - assert.Equal(t, expectedHTTPLimitConnsMetrics["plus.http.limit_conns.passed"], metric.Value) - case "plus.http.limit_conns.rejected": - assert.Equal(t, expectedHTTPLimitConnsMetrics["plus.http.limit_conns.rejected"], metric.Value) - case "plus.http.limit_conns.rejected_dry_run": - assert.Equal(t, expectedHTTPLimitConnsMetrics["plus.http.limit_conns.rejected_dry_run"], metric.Value) - } - } - - limitRequestsMetrics := <-test.m - assert.Len(t, limitRequestsMetrics.Simplemetrics, len(expectedHTTPLimitReqsMetrics)) - for _, dimension := range limitRequestsMetrics.Dimensions { - switch dimension.Name { - case "limit_req_zone": - assert.Equal(t, limitRequestName, dimension.Value) - - } - } - for _, metric := range limitRequestsMetrics.Simplemetrics { - assert.Contains(t, expectedHTTPLimitReqsMetrics, metric.Name) - switch metric.Name { - case "plus.http.limit_reqs.passed": - assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.passed"], metric.Value) - case "plus.http.limit_reqs.delayed": - assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.delayed"], metric.Value) - case "plus.http.limit_reqs.rejected": - assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.rejected"], metric.Value) - case "plus.http.limit_reqs.delayed_dry_run": - assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.delayed_dry_run"], metric.Value) - case "plus.http.limit_reqs.rejected_dry_run": - assert.Equal(t, expectedHTTPLimitReqsMetrics["plus.http.limit_reqs.rejected_dry_run"], metric.Value) - } - } - - var extraMetrics []*proto.StatsEntity + var extraMetrics []*metrics.StatsEntityWrapper EMWAIT: for { select { diff --git a/src/core/metrics/sources/nginx_process_test.go b/src/core/metrics/sources/nginx_process_test.go index 9d50014151..f8c8b45438 100644 --- a/src/core/metrics/sources/nginx_process_test.go +++ b/src/core/metrics/sources/nginx_process_test.go @@ -60,7 +60,7 @@ func TestNginxProcessCollector_Collect_Process(t *testing.T) { wg := sync.WaitGroup{} wg.Add(1) - m := make(chan *proto.StatsEntity) + m := make(chan *metrics.StatsEntityWrapper) go n.Collect(ctx, &wg, m) time.Sleep(100 * time.Millisecond) @@ -70,7 +70,7 @@ func TestNginxProcessCollector_Collect_Process(t *testing.T) { // the prev stats as equal to the initial stats collected // that's ok, but we should test the counter gauge computations again later metricReport := <-m - for _, metric := range metricReport.Simplemetrics { + for _, metric := range metricReport.Data.Simplemetrics { switch metric.Name { case "plus.instance.count": assert.Equal(t, float64(1), metric.Value) @@ -104,7 +104,7 @@ func TestNginxProcessCollector_Collect_NoProcess(t *testing.T) { wg := sync.WaitGroup{} wg.Add(1) - m := make(chan *proto.StatsEntity) + m := make(chan *metrics.StatsEntityWrapper) go n.Collect(ctx, &wg, m) time.Sleep(100 * time.Millisecond) @@ -114,7 +114,7 @@ func TestNginxProcessCollector_Collect_NoProcess(t *testing.T) { // the prev stats as equal to the initial stats collected // that's ok, but we should test the counter gauge computations again later metricReport := <-m - for _, metric := range metricReport.Simplemetrics { + for _, metric := range metricReport.Data.Simplemetrics { switch metric.Name { case "plus.instance.count": assert.Equal(t, float64(0), metric.Value) @@ -151,7 +151,7 @@ func TestNginxProcessCollector_Collect_NotPlus(t *testing.T) { wg := sync.WaitGroup{} wg.Add(1) - m := make(chan *proto.StatsEntity) + m := make(chan *metrics.StatsEntityWrapper) go n.Collect(ctx, &wg, m) time.Sleep(100 * time.Millisecond) @@ -161,7 +161,7 @@ func TestNginxProcessCollector_Collect_NotPlus(t *testing.T) { // the prev stats as equal to the initial stats collected // that's ok, but we should test the counter gauge computations again later metricReport := <-m - for _, metric := range metricReport.Simplemetrics { + for _, metric := range metricReport.Data.Simplemetrics { switch metric.Name { case "plus.instance.count": assert.Equal(t, float64(0), metric.Value) diff --git a/src/core/metrics/sources/nginx_static_test.go b/src/core/metrics/sources/nginx_static_test.go index 69254984a4..02e3b7048f 100644 --- a/src/core/metrics/sources/nginx_static_test.go +++ b/src/core/metrics/sources/nginx_static_test.go @@ -46,12 +46,12 @@ func TestNginxStatic_Collect(t *testing.T) { tests := []struct { name string namedMetric *namedMetric - m chan *proto.StatsEntity + m chan *metrics.StatsEntityWrapper }{ { "nginx static test", &namedMetric{namespace: "nginx"}, - make(chan *proto.StatsEntity, 1), + make(chan *metrics.StatsEntityWrapper, 1), }, } @@ -70,8 +70,8 @@ func TestNginxStatic_Collect(t *testing.T) { go c.Collect(ctx, wg, test.m) wg.Wait() statEntity := <-test.m - assert.Len(tt, statEntity.Simplemetrics, len(expectedMetrics)) - for _, metric := range statEntity.Simplemetrics { + assert.Len(tt, statEntity.Data.Simplemetrics, len(expectedMetrics)) + for _, metric := range statEntity.Data.Simplemetrics { assert.Contains(t, expectedMetrics, metric.Name) assert.Equal(t, expectedMetricsValues[metric.Name], metric.Value) } diff --git a/src/core/metrics/sources/nginx_worker_test.go b/src/core/metrics/sources/nginx_worker_test.go index e166e56719..681e6e4bb7 100644 --- a/src/core/metrics/sources/nginx_worker_test.go +++ b/src/core/metrics/sources/nginx_worker_test.go @@ -86,7 +86,7 @@ func TestNginxWorkerCollector(t *testing.T) { wg := sync.WaitGroup{} wg.Add(1) - m := make(chan *proto.StatsEntity) + m := make(chan *metrics.StatsEntityWrapper) go n.Collect(ctx, &wg, m) time.Sleep(100 * time.Millisecond) @@ -97,7 +97,7 @@ func TestNginxWorkerCollector(t *testing.T) { // the prev stats as equal to the initial stats collected // that's ok, but we should test the counter gauge computations again later metricReport := <-m - for _, metric := range metricReport.Simplemetrics { + for _, metric := range metricReport.Data.Simplemetrics { switch metric.Name { case "nginx.workers.cpu.system": assert.Equal(t, float64(0), metric.Value) @@ -137,7 +137,7 @@ func TestNginxWorkerCollector(t *testing.T) { mockBinary.AssertNumberOfCalls(t, "GetChildProcesses", 2) metricReport = <-m - for _, metric := range metricReport.Simplemetrics { + for _, metric := range metricReport.Data.Simplemetrics { switch metric.Name { case "nginx.workers.cpu.system": assert.Equal(t, float64(0), metric.Value) diff --git a/src/core/metrics/sources/swap_test.go b/src/core/metrics/sources/swap_test.go index 7bd138f5d2..473f029244 100644 --- a/src/core/metrics/sources/swap_test.go +++ b/src/core/metrics/sources/swap_test.go @@ -9,6 +9,7 @@ package sources import ( "context" + "github.com/nginx/agent/v2/src/core/metrics" "sync" "testing" @@ -65,11 +66,11 @@ func TestSwapSource_Collect(t *testing.T) { tests := []struct { name string - m chan *proto.StatsEntity + m chan *metrics.StatsEntityWrapper }{ { "basic swap test", - make(chan *proto.StatsEntity, 1), + make(chan *metrics.StatsEntityWrapper, 1), }, } @@ -95,8 +96,8 @@ func TestSwapSource_Collect(t *testing.T) { wg.Wait() statsEntity := <-test.m - assert.Len(tt, statsEntity.Simplemetrics, len(expectedMetrics)) - for _, metric := range statsEntity.Simplemetrics { + assert.Len(tt, statsEntity.Data.Simplemetrics, len(expectedMetrics)) + for _, metric := range statsEntity.Data.Simplemetrics { assert.Contains(tt, expectedMetrics, metric.Name) assert.Equal(t, expectedMetrics[metric.Name], metric.Value) } diff --git a/src/plugins/metrics_throlling.go b/src/plugins/metrics_throlling.go index 2eb7f59b67..2c94f7909e 100644 --- a/src/plugins/metrics_throlling.go +++ b/src/plugins/metrics_throlling.go @@ -91,23 +91,27 @@ func (r *MetricsThrottle) Process(msg *core.Message) { if r.metricsAggregation { switch report := msg.Data().(type) { case *proto.MetricsReport: - r.mu.Lock() - if _, ok := r.metricsCollections[report.Type]; !ok { - r.metricsCollections[report.Type] = &metrics.Collections{ - Count: 0, - Data: make(map[string]metrics.PerDimension), + if len(report.Data) > 0 { + r.mu.Lock() + if _, ok := r.metricsCollections[report.Type]; !ok { + r.metricsCollections[report.Type] = &metrics.Collections{ + Count: 0, + Data: make(map[string]metrics.PerDimension), + } } + collection := metrics.SaveCollections(*r.metricsCollections[report.Type], report) + r.metricsCollections[report.Type] = &collection + r.mu.Unlock() + log.Debugf("MetricsThrottle: Metrics collection saved [Type: %d]", report.Type) + r.reportsReady.Store(true) } - collection := metrics.SaveCollections(*r.metricsCollections[report.Type], report) - r.metricsCollections[report.Type] = &collection - r.mu.Unlock() - log.Debugf("MetricsThrottle: Metrics collection saved [Type: %d]", report.Type) - r.reportsReady.Store(true) } } else { switch report := msg.Data().(type) { case *proto.MetricsReport: - r.metricBuffer = append(r.metricBuffer, report) + if len(report.Data) > 0 { + r.metricBuffer = append(r.metricBuffer, report) + } } log.Tracef("MetricsThrottle buffer size: %d of %d", len(r.metricBuffer), r.BulkSize) if len(r.metricBuffer) >= r.BulkSize { diff --git a/test/integration/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go b/test/integration/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go index 06fe5c3285..46e46326b8 100644 --- a/test/integration/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go +++ b/test/integration/vendor/github.com/nginx/agent/sdk/v2/client/metric_reporter.go @@ -157,7 +157,7 @@ func (r *metricReporter) Send(ctx context.Context, message Message) error { return r.handleGrpcError("Metric Reporter Channel Send", err) } - log.Tracef("MetricReporter sent metrics report %v", report) + log.Tracef("MetricReporter sent metrics report [Type: %d] %+v", report.Type, report) return nil }) diff --git a/test/integration/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go b/test/integration/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go index ee8c827948..77fefe5c51 100644 --- a/test/integration/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go +++ b/test/integration/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go @@ -25,28 +25,30 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// Metric type enum type MetricsReport_Type int32 const ( - // System metric type - MetricsReport_SYSTEM MetricsReport_Type = 0 - // NGINX instance metric type - MetricsReport_INSTANCE MetricsReport_Type = 1 - // Agent metric type - MetricsReport_AGENT MetricsReport_Type = 2 + MetricsReport_SYSTEM MetricsReport_Type = 0 + MetricsReport_INSTANCE MetricsReport_Type = 1 + MetricsReport_AGENT MetricsReport_Type = 2 + MetricsReport_CACHE_ZONE MetricsReport_Type = 3 + MetricsReport_UPSTREAMS MetricsReport_Type = 4 ) var MetricsReport_Type_name = map[int32]string{ 0: "SYSTEM", 1: "INSTANCE", 2: "AGENT", + 3: "CACHE_ZONE", + 4: "UPSTREAMS", } var MetricsReport_Type_value = map[string]int32{ - "SYSTEM": 0, - "INSTANCE": 1, - "AGENT": 2, + "SYSTEM": 0, + "INSTANCE": 1, + "AGENT": 2, + "CACHE_ZONE": 3, + "UPSTREAMS": 4, } func (x MetricsReport_Type) String() string { @@ -57,17 +59,13 @@ func (MetricsReport_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor_6039342a2ba47b72, []int{0, 0} } -// Represents a metric report type MetricsReport struct { - // Provides meta information about the metrics - Meta *Metadata `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta"` - // Type of metrics - Type MetricsReport_Type `protobuf:"varint,2,opt,name=type,proto3,enum=f5.nginx.agent.sdk.MetricsReport_Type" json:"type"` - // List of stats entities - Data []*StatsEntity `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Meta *Metadata `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta"` + Type MetricsReport_Type `protobuf:"varint,2,opt,name=type,proto3,enum=f5.nginx.agent.sdk.MetricsReport_Type" json:"type"` + Data []*StatsEntity `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *MetricsReport) Reset() { *m = MetricsReport{} } @@ -124,11 +122,8 @@ func (m *MetricsReport) GetData() []*StatsEntity { return nil } -// Represents a simple metric type SimpleMetric struct { - // Metric name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` - // Metric value + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` Value float64 `protobuf:"fixed64,2,opt,name=value,proto3" json:"value"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -182,11 +177,9 @@ func (m *SimpleMetric) GetValue() float64 { return 0 } -// Represents a dimension which is a dimensional attribute used when classifying and categorizing data +// Dimension defines a dimensional attribute used when classifying and categorizing data type Dimension struct { - // Dimension name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` - // Dimension value + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -240,17 +233,14 @@ func (m *Dimension) GetValue() string { return "" } -// Represents a stats entity which is a timestamped entry for dimensions and metrics +// StatsEntity a timestamped entry for Dimensions and Metrics type StatsEntity struct { - // Timestamp defines the time of stats entity creation - Timestamp *types.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - // List of dimensions - Dimensions []*Dimension `protobuf:"bytes,3,rep,name=dimensions,proto3" json:"dimensions"` - // List of metrics - Simplemetrics []*SimpleMetric `protobuf:"bytes,4,rep,name=simplemetrics,proto3" json:"simplemetrics"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Timestamp *types.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Dimensions []*Dimension `protobuf:"bytes,3,rep,name=dimensions,proto3" json:"dimensions"` + Simplemetrics []*SimpleMetric `protobuf:"bytes,4,rep,name=simplemetrics,proto3" json:"simplemetrics"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *StatsEntity) Reset() { *m = StatsEntity{} } @@ -318,36 +308,38 @@ func init() { func init() { proto.RegisterFile("metrics.proto", fileDescriptor_6039342a2ba47b72) } var fileDescriptor_6039342a2ba47b72 = []byte{ - // 460 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc6, 0x6d, 0x36, 0x9a, 0xd7, 0x76, 0x2a, 0x3e, 0x55, 0xd5, 0x68, 0xaa, 0x1e, 0x50, 0x11, - 0x92, 0x23, 0x15, 0x21, 0x10, 0x88, 0xc3, 0xc2, 0x2a, 0xc4, 0xa4, 0xf4, 0xe0, 0xe4, 0x32, 0x6e, - 0x5e, 0xeb, 0x85, 0x68, 0x75, 0x1c, 0xd5, 0xee, 0x44, 0x6f, 0xfc, 0x3c, 0x8e, 0xfc, 0x82, 0x0a, - 0xf5, 0xd8, 0xff, 0x80, 0x84, 0x62, 0xa7, 0x5b, 0x27, 0xc2, 0x61, 0x97, 0x67, 0x3f, 0xeb, 0x7d, - 0xdf, 0x7b, 0xef, 0xfb, 0x0c, 0x6d, 0xc1, 0xf5, 0x32, 0x9d, 0x29, 0x92, 0x2f, 0xa5, 0x96, 0x18, - 0x5f, 0xbf, 0x21, 0x59, 0x92, 0x66, 0xdf, 0x09, 0x4b, 0x78, 0xa6, 0x89, 0x9a, 0xdf, 0xf4, 0x5a, - 0x33, 0x29, 0x84, 0xcc, 0x6c, 0x45, 0x0f, 0x12, 0x99, 0xc8, 0xf2, 0xee, 0x25, 0x52, 0x26, 0x0b, - 0xee, 0x9b, 0xec, 0x6a, 0x75, 0xed, 0xeb, 0x54, 0x70, 0xa5, 0x99, 0xc8, 0x6d, 0xc1, 0xf0, 0x0f, - 0x82, 0x76, 0x68, 0x1b, 0x50, 0x9e, 0xcb, 0xa5, 0xc6, 0xef, 0xc1, 0x11, 0x5c, 0xb3, 0x2e, 0x1a, - 0xa0, 0x51, 0x73, 0x7c, 0x4a, 0xfe, 0xed, 0x47, 0x42, 0xae, 0xd9, 0x9c, 0x69, 0x16, 0x34, 0x76, - 0x1b, 0xcf, 0x54, 0x53, 0x13, 0xf1, 0x39, 0x38, 0x7a, 0x9d, 0xf3, 0x6e, 0x6d, 0x80, 0x46, 0x27, - 0xe3, 0x17, 0xff, 0xc1, 0xde, 0x37, 0x23, 0xf1, 0x3a, 0xe7, 0x96, 0xa5, 0xc0, 0x51, 0x13, 0xf1, - 0x47, 0x70, 0x0a, 0xf6, 0x6e, 0x7d, 0x50, 0x1f, 0x35, 0xc7, 0x5e, 0x15, 0x4b, 0xa4, 0x99, 0x56, - 0x93, 0x4c, 0xa7, 0x7a, 0x6d, 0xe1, 0x05, 0x80, 0x9a, 0x38, 0x7c, 0x05, 0x4e, 0x41, 0x8b, 0x01, - 0x8e, 0xa3, 0xcb, 0x28, 0x9e, 0x84, 0x9d, 0x27, 0xb8, 0x05, 0x8d, 0x2f, 0xd3, 0x28, 0x3e, 0x9b, - 0x7e, 0x9a, 0x74, 0x10, 0x76, 0xe1, 0xe8, 0xec, 0xf3, 0x64, 0x1a, 0x77, 0x6a, 0xc3, 0x10, 0x5a, - 0x51, 0x2a, 0xf2, 0x05, 0xb7, 0x73, 0xe1, 0x53, 0x70, 0x32, 0x26, 0xb8, 0xd9, 0xde, 0xb5, 0xd4, - 0x45, 0x4e, 0x4d, 0xc4, 0x1e, 0x1c, 0xdd, 0xb2, 0xc5, 0xca, 0x2e, 0x88, 0x02, 0x77, 0xb7, 0xf1, - 0xec, 0x03, 0xb5, 0xc7, 0xf0, 0x02, 0xdc, 0xf3, 0x54, 0xf0, 0x4c, 0xa5, 0x32, 0x7b, 0x0c, 0x97, - 0x5b, 0xc1, 0xf5, 0xa3, 0x06, 0xcd, 0x83, 0x3d, 0xf1, 0x3b, 0x70, 0xef, 0xdc, 0x2b, 0xdd, 0xe9, - 0x11, 0xeb, 0x2f, 0xd9, 0xfb, 0x4b, 0xe2, 0x7d, 0x05, 0xbd, 0x2f, 0xc6, 0x21, 0xc0, 0x7c, 0x3f, - 0x95, 0x2a, 0x65, 0x7d, 0x5e, 0x25, 0xeb, 0xdd, 0xec, 0xc1, 0xc9, 0x6e, 0xe3, 0x1d, 0x80, 0xe8, - 0xc1, 0x1d, 0x5f, 0x42, 0x5b, 0x19, 0xcd, 0xca, 0x9f, 0xd9, 0x75, 0x0c, 0xe3, 0xa0, 0xd2, 0xa8, - 0x03, 0x71, 0x83, 0x67, 0xbb, 0x8d, 0xf7, 0x10, 0x4a, 0x1f, 0xa6, 0x17, 0x4e, 0xa3, 0xd6, 0xa9, - 0xd3, 0xa7, 0x65, 0x1a, 0xbc, 0xfd, 0xb9, 0xed, 0xa3, 0x5f, 0xdb, 0x3e, 0xfa, 0xbd, 0xed, 0xa3, - 0xaf, 0x2f, 0x93, 0x54, 0x7f, 0x5b, 0x5d, 0x91, 0x99, 0x14, 0xbe, 0xe9, 0xe3, 0x9b, 0x3e, 0xbe, - 0x9a, 0xdf, 0xf8, 0xb7, 0x63, 0xfb, 0xc7, 0x3f, 0x58, 0x25, 0x8e, 0xcd, 0xf1, 0xfa, 0x6f, 0x00, - 0x00, 0x00, 0xff, 0xff, 0xe6, 0xcd, 0x1e, 0xb5, 0x3d, 0x03, 0x00, 0x00, + // 488 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0xc6, 0x8e, 0x5b, 0xe2, 0xc9, 0x8f, 0xcc, 0x9e, 0xa2, 0xa8, 0xc4, 0x51, 0x0e, 0x28, 0x5c, + 0xd6, 0x52, 0x10, 0x02, 0x81, 0x38, 0xc4, 0xa9, 0x05, 0x44, 0x72, 0x40, 0x6b, 0x73, 0x68, 0x2f, + 0xc8, 0x4d, 0xb6, 0xc6, 0x6a, 0xd6, 0x6b, 0xc5, 0x9b, 0x8a, 0xdc, 0x78, 0x10, 0x1e, 0x88, 0x23, + 0x4f, 0x10, 0xa1, 0x1c, 0xf3, 0x14, 0xc8, 0xbb, 0x4e, 0x9b, 0x88, 0x70, 0xe8, 0x65, 0x76, 0xc7, + 0x9a, 0xef, 0xfb, 0xc6, 0xdf, 0xcc, 0x42, 0x83, 0x51, 0xb1, 0x48, 0xa6, 0x39, 0xce, 0x16, 0x5c, + 0x70, 0x84, 0xae, 0x5f, 0xe2, 0x34, 0x4e, 0xd2, 0xef, 0x38, 0x8a, 0x69, 0x2a, 0x70, 0x3e, 0xbb, + 0x69, 0xdb, 0x31, 0xe7, 0xf1, 0x9c, 0x3a, 0xb2, 0xe2, 0x6a, 0x79, 0xed, 0x88, 0x84, 0xd1, 0x5c, + 0x44, 0x2c, 0x53, 0xa0, 0x76, 0x7d, 0xca, 0x19, 0xe3, 0x69, 0x99, 0x41, 0xcc, 0x63, 0xae, 0xee, + 0xbd, 0x9f, 0x3a, 0x34, 0x7c, 0x25, 0x40, 0x68, 0xc6, 0x17, 0x02, 0xbd, 0x01, 0x83, 0x51, 0x11, + 0xb5, 0xb4, 0xae, 0xd6, 0xaf, 0x0d, 0xce, 0xf0, 0xbf, 0x7a, 0xd8, 0xa7, 0x22, 0x9a, 0x45, 0x22, + 0x72, 0xab, 0xdb, 0xb5, 0x2d, 0xab, 0x89, 0x8c, 0xe8, 0x1c, 0x0c, 0xb1, 0xca, 0x68, 0x4b, 0xef, + 0x6a, 0xfd, 0xe6, 0xe0, 0xd9, 0x7f, 0xb0, 0xf7, 0x62, 0x38, 0x5c, 0x65, 0x54, 0xb1, 0x14, 0x38, + 0x22, 0x23, 0x7a, 0x07, 0x46, 0xc1, 0xde, 0xaa, 0x74, 0x2b, 0xfd, 0xda, 0xc0, 0x3e, 0xc6, 0x12, + 0x88, 0x48, 0xe4, 0x5e, 0x2a, 0x12, 0xb1, 0x52, 0xf0, 0x02, 0x40, 0x64, 0xec, 0x8d, 0xc1, 0x28, + 0x68, 0x11, 0xc0, 0x69, 0x70, 0x11, 0x84, 0x9e, 0x6f, 0x3d, 0x42, 0x75, 0xa8, 0x7e, 0x9c, 0x04, + 0xe1, 0x70, 0x32, 0xf2, 0x2c, 0x0d, 0x99, 0x70, 0x32, 0x7c, 0xef, 0x4d, 0x42, 0x4b, 0x47, 0x4d, + 0x80, 0xd1, 0x70, 0xf4, 0xc1, 0xfb, 0x7a, 0xf9, 0x69, 0xe2, 0x59, 0x15, 0xd4, 0x00, 0xf3, 0xcb, + 0xe7, 0x20, 0x24, 0xde, 0xd0, 0x0f, 0x2c, 0xa3, 0xe7, 0x43, 0x3d, 0x48, 0x58, 0x36, 0xa7, 0xaa, + 0x6d, 0x74, 0x06, 0x46, 0x1a, 0x31, 0x2a, 0xcd, 0x31, 0x95, 0x72, 0x91, 0x13, 0x19, 0x91, 0x0d, + 0x27, 0xb7, 0xd1, 0x7c, 0xa9, 0xfe, 0x5f, 0x73, 0xcd, 0xed, 0xda, 0x56, 0x1f, 0x88, 0x3a, 0x7a, + 0x63, 0x30, 0xcf, 0x13, 0x46, 0xd3, 0x3c, 0xe1, 0xe9, 0x43, 0xb8, 0xcc, 0x23, 0x5c, 0x3f, 0x74, + 0xa8, 0xed, 0xd9, 0x80, 0x5e, 0x83, 0x79, 0x37, 0xf6, 0x72, 0x78, 0x6d, 0xac, 0x16, 0x03, 0xef, + 0x16, 0x03, 0x87, 0xbb, 0x0a, 0x72, 0x5f, 0x8c, 0x7c, 0x80, 0xd9, 0xae, 0xab, 0xbc, 0x74, 0xfd, + 0xe9, 0x31, 0xd7, 0xef, 0x7a, 0x77, 0x9b, 0xdb, 0xb5, 0xbd, 0x07, 0x22, 0x7b, 0x77, 0x74, 0x01, + 0x8d, 0x5c, 0x7a, 0x56, 0x2e, 0x6e, 0xcb, 0x90, 0x8c, 0xdd, 0xa3, 0x73, 0xdc, 0x33, 0xd7, 0x7d, + 0xb2, 0x5d, 0xdb, 0x87, 0x50, 0x72, 0x98, 0x8e, 0x8d, 0xaa, 0x6e, 0x55, 0xc8, 0xe3, 0x32, 0x75, + 0x5f, 0xfd, 0xda, 0x74, 0xb4, 0xdf, 0x9b, 0x8e, 0xf6, 0x67, 0xd3, 0xd1, 0x2e, 0x9f, 0xc7, 0x89, + 0xf8, 0xb6, 0xbc, 0xc2, 0x53, 0xce, 0x1c, 0xa9, 0xe3, 0x48, 0x1d, 0x27, 0x9f, 0xdd, 0x38, 0xb7, + 0x03, 0xf5, 0x38, 0xde, 0x2a, 0x27, 0x4e, 0xe5, 0xf1, 0xe2, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xee, 0x4a, 0xc6, 0xb7, 0x5c, 0x03, 0x00, 0x00, } func (m *MetricsReport) Marshal() (dAtA []byte, err error) { diff --git a/test/integration/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto b/test/integration/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto index e4cba46fd3..9af8b28c60 100644 --- a/test/integration/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto +++ b/test/integration/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto @@ -1,56 +1,41 @@ syntax = "proto3"; package f5.nginx.agent.sdk; +option go_package = "github.com/nginx/agent/sdk/v2/proto;proto"; +import "google/protobuf/timestamp.proto"; import "common.proto"; import "gogo.proto"; -import "google/protobuf/timestamp.proto"; - -option go_package = "github.com/nginx/agent/sdk/v2/proto;proto"; -// Represents a metric report message MetricsReport { - // Metric type enum enum Type { - // System metric type SYSTEM = 0; - // NGINX instance metric type INSTANCE = 1; - // Agent metric type AGENT = 2; + CACHE_ZONE = 3; + UPSTREAMS = 4; } - // Provides meta information about the metrics - Metadata meta = 1 [(gogoproto.jsontag) = "meta"]; - // Type of metrics - Type type = 2 [(gogoproto.jsontag) = "type"]; - // List of stats entities - repeated StatsEntity data = 3 [(gogoproto.jsontag) = "data"]; + Metadata meta = 1 [(gogoproto.jsontag) = "meta" ]; + Type type = 2 [(gogoproto.jsontag) = "type" ]; + repeated StatsEntity data = 3 [(gogoproto.jsontag) = "data" ]; } -// Represents a simple metric message SimpleMetric { - // Metric name - string name = 1 [(gogoproto.jsontag) = "name"]; - // Metric value - double value = 2 [(gogoproto.jsontag) = "value"]; + string name = 1 [(gogoproto.jsontag) = "name" ]; + double value = 2 [(gogoproto.jsontag) = "value" ]; } -// Represents a dimension which is a dimensional attribute used when classifying and categorizing data +// Dimension defines a dimensional attribute used when classifying and categorizing data message Dimension { - // Dimension name - string name = 1 [(gogoproto.jsontag) = "name"]; - // Dimension value - string value = 2 [(gogoproto.jsontag) = "value"]; + string name = 1 [(gogoproto.jsontag) = "name" ]; + string value = 2 [(gogoproto.jsontag) = "value" ]; } -// Represents a stats entity which is a timestamped entry for dimensions and metrics +// StatsEntity a timestamped entry for Dimensions and Metrics message StatsEntity { - // Timestamp defines the time of stats entity creation google.protobuf.Timestamp timestamp = 1; // DEPRECATED reserved 2; reserved "metrics"; - // List of dimensions - repeated Dimension dimensions = 3 [(gogoproto.jsontag) = "dimensions"]; - // List of metrics - repeated SimpleMetric simplemetrics = 4 [(gogoproto.jsontag) = "simplemetrics"]; + repeated Dimension dimensions = 3 [(gogoproto.jsontag) = "dimensions" ]; + repeated SimpleMetric simplemetrics = 4 [(gogoproto.jsontag) = "simplemetrics" ]; } diff --git a/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go b/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go index 3143605e9c..77fefe5c51 100644 --- a/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go +++ b/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go @@ -25,37 +25,14 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// Metric type enum type MetricsReport_Type int32 const ( -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> adds updated generated files from protobuf - // System metric type - MetricsReport_SYSTEM MetricsReport_Type = 0 - // NGINX instance metric type - MetricsReport_INSTANCE MetricsReport_Type = 1 - // Agent metric type - MetricsReport_AGENT MetricsReport_Type = 2 - // Cache zone metric type -<<<<<<< HEAD - MetricsReport_CACHE_ZONE MetricsReport_Type = 3 - // Upstreams metric type - MetricsReport_UPSTREAMS MetricsReport_Type = 4 -======= MetricsReport_SYSTEM MetricsReport_Type = 0 MetricsReport_INSTANCE MetricsReport_Type = 1 MetricsReport_AGENT MetricsReport_Type = 2 MetricsReport_CACHE_ZONE MetricsReport_Type = 3 MetricsReport_UPSTREAMS MetricsReport_Type = 4 ->>>>>>> Create dedicated cache and upstream metrics reports -======= - MetricsReport_CACHE_ZONE MetricsReport_Type = 3 - // Upstreams metric type - MetricsReport_UPSTREAMS MetricsReport_Type = 4 ->>>>>>> adds updated generated files from protobuf ) var MetricsReport_Type_name = map[int32]string{ @@ -82,17 +59,13 @@ func (MetricsReport_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor_6039342a2ba47b72, []int{0, 0} } -// Represents a metric report type MetricsReport struct { - // Provides meta information about the metrics - Meta *Metadata `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta"` - // Type of metrics - Type MetricsReport_Type `protobuf:"varint,2,opt,name=type,proto3,enum=f5.nginx.agent.sdk.MetricsReport_Type" json:"type"` - // List of stats entities - Data []*StatsEntity `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Meta *Metadata `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta"` + Type MetricsReport_Type `protobuf:"varint,2,opt,name=type,proto3,enum=f5.nginx.agent.sdk.MetricsReport_Type" json:"type"` + Data []*StatsEntity `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *MetricsReport) Reset() { *m = MetricsReport{} } @@ -150,9 +123,7 @@ func (m *MetricsReport) GetData() []*StatsEntity { } type SimpleMetric struct { - // Metric name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` - // Metric value + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` Value float64 `protobuf:"fixed64,2,opt,name=value,proto3" json:"value"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -208,9 +179,7 @@ func (m *SimpleMetric) GetValue() float64 { // Dimension defines a dimensional attribute used when classifying and categorizing data type Dimension struct { - // Dimension name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` - // Dimension value + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -264,25 +233,14 @@ func (m *Dimension) GetValue() string { return "" } -<<<<<<< HEAD -<<<<<<< HEAD -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics -======= // StatsEntity a timestamped entry for Dimensions and Metrics ->>>>>>> Create dedicated cache and upstream metrics reports -======= -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics ->>>>>>> adds updated generated files from protobuf type StatsEntity struct { - // Timestamp defines the time of stats entity creation - Timestamp *types.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - // List of dimensions - Dimensions []*Dimension `protobuf:"bytes,3,rep,name=dimensions,proto3" json:"dimensions"` - // List of metrics - Simplemetrics []*SimpleMetric `protobuf:"bytes,4,rep,name=simplemetrics,proto3" json:"simplemetrics"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Timestamp *types.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Dimensions []*Dimension `protobuf:"bytes,3,rep,name=dimensions,proto3" json:"dimensions"` + Simplemetrics []*SimpleMetric `protobuf:"bytes,4,rep,name=simplemetrics,proto3" json:"simplemetrics"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *StatsEntity) Reset() { *m = StatsEntity{} } diff --git a/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto b/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto index 88827399e7..9af8b28c60 100644 --- a/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto +++ b/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto @@ -6,111 +6,36 @@ import "google/protobuf/timestamp.proto"; import "common.proto"; import "gogo.proto"; -// Represents a metric report message MetricsReport { -<<<<<<< HEAD -<<<<<<< HEAD - // Metric type enum -======= ->>>>>>> Create dedicated cache and upstream metrics reports -======= - // Metric type enum ->>>>>>> adds updated generated files from protobuf enum Type { - // System metric type SYSTEM = 0; - // NGINX instance metric type INSTANCE = 1; - // Agent metric type AGENT = 2; -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> adds updated generated files from protobuf - // Cache zone metric type CACHE_ZONE = 3; - // Upstreams metric type UPSTREAMS = 4; } - // Provides meta information about the metrics Metadata meta = 1 [(gogoproto.jsontag) = "meta" ]; - // Type of metrics Type type = 2 [(gogoproto.jsontag) = "type" ]; - // List of stats entities -<<<<<<< HEAD -======= - CACHE_ZONE = 3; - UPSTREAMS = 4; - } - Metadata meta = 1 [(gogoproto.jsontag) = "meta" ]; - Type type = 2 [(gogoproto.jsontag) = "type" ]; ->>>>>>> Create dedicated cache and upstream metrics reports -======= ->>>>>>> adds updated generated files from protobuf repeated StatsEntity data = 3 [(gogoproto.jsontag) = "data" ]; } message SimpleMetric { -<<<<<<< HEAD -<<<<<<< HEAD - // Metric name - string name = 1 [(gogoproto.jsontag) = "name" ]; - // Metric value -======= - string name = 1 [(gogoproto.jsontag) = "name" ]; ->>>>>>> Create dedicated cache and upstream metrics reports -======= - // Metric name string name = 1 [(gogoproto.jsontag) = "name" ]; - // Metric value ->>>>>>> adds updated generated files from protobuf double value = 2 [(gogoproto.jsontag) = "value" ]; } // Dimension defines a dimensional attribute used when classifying and categorizing data message Dimension { -<<<<<<< HEAD -<<<<<<< HEAD - // Dimension name string name = 1 [(gogoproto.jsontag) = "name" ]; - // Dimension value string value = 2 [(gogoproto.jsontag) = "value" ]; } -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics -======= -======= - // Dimension name ->>>>>>> adds updated generated files from protobuf - string name = 1 [(gogoproto.jsontag) = "name" ]; - // Dimension value - string value = 2 [(gogoproto.jsontag) = "value" ]; -} - -<<<<<<< HEAD // StatsEntity a timestamped entry for Dimensions and Metrics ->>>>>>> Create dedicated cache and upstream metrics reports -======= -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics ->>>>>>> adds updated generated files from protobuf message StatsEntity { - // Timestamp defines the time of stats entity creation google.protobuf.Timestamp timestamp = 1; // DEPRECATED reserved 2; reserved "metrics"; -<<<<<<< HEAD -<<<<<<< HEAD - // List of dimensions - repeated Dimension dimensions = 3 [(gogoproto.jsontag) = "dimensions" ]; - // List of metrics -======= - repeated Dimension dimensions = 3 [(gogoproto.jsontag) = "dimensions" ]; ->>>>>>> Create dedicated cache and upstream metrics reports -======= - // List of dimensions repeated Dimension dimensions = 3 [(gogoproto.jsontag) = "dimensions" ]; - // List of metrics ->>>>>>> adds updated generated files from protobuf repeated SimpleMetric simplemetrics = 4 [(gogoproto.jsontag) = "simplemetrics" ]; } diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/metrics.go b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/metrics.go index 938e071de4..d5c77aa121 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/metrics.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/metrics.go @@ -182,12 +182,8 @@ func (m *Metrics) metricsGoroutine() { } return case <-m.ticker.C: -<<<<<<< HEAD stats := m.collectStats() for _, report := range metrics.GenerateMetricsReports(stats) { -======= - for _, report := range generateMetricsReports(m.collectStats(), true) { ->>>>>>> Create dedicated cache and upstream metrics reports m.pipeline.Process(core.NewMessage(core.MetricReport, report)) } if m.collectorsUpdate.Load() { diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/metrics_throlling.go b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/metrics_throlling.go index 752e244a56..2c94f7909e 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/metrics_throlling.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/metrics_throlling.go @@ -91,29 +91,28 @@ func (r *MetricsThrottle) Process(msg *core.Message) { if r.metricsAggregation { switch report := msg.Data().(type) { case *proto.MetricsReport: - r.mu.Lock() - if _, ok := r.metricsCollections[report.Type]; !ok { - r.metricsCollections[report.Type] = &metrics.Collections{ - Count: 0, - Data: make(map[string]metrics.PerDimension), + if len(report.Data) > 0 { + r.mu.Lock() + if _, ok := r.metricsCollections[report.Type]; !ok { + r.metricsCollections[report.Type] = &metrics.Collections{ + Count: 0, + Data: make(map[string]metrics.PerDimension), + } } + collection := metrics.SaveCollections(*r.metricsCollections[report.Type], report) + r.metricsCollections[report.Type] = &collection + r.mu.Unlock() + log.Debugf("MetricsThrottle: Metrics collection saved [Type: %d]", report.Type) + r.reportsReady.Store(true) } - collection := metrics.SaveCollections(*r.metricsCollections[report.Type], report) - r.metricsCollections[report.Type] = &collection - r.mu.Unlock() - log.Debug("MetricsThrottle: Metrics collection saved") - r.reportsReady.Store(true) } } else { -<<<<<<< HEAD switch report := msg.Data().(type) { case *proto.MetricsReport: - r.metricBuffer = append(r.metricBuffer, report) + if len(report.Data) > 0 { + r.metricBuffer = append(r.metricBuffer, report) + } } -======= - r.metricBuffer = append(r.metricBuffer, - generateMetricsReports(getAllStatsEntities(msg.Data()), false)...) ->>>>>>> Create dedicated cache and upstream metrics reports log.Tracef("MetricsThrottle buffer size: %d of %d", len(r.metricBuffer), r.BulkSize) if len(r.metricBuffer) >= r.BulkSize { log.Info("MetricsThrottle buffer flush") @@ -178,7 +177,6 @@ func (r *MetricsThrottle) syncAgentConfigChange() { r.conf = conf } -<<<<<<< HEAD func (r *MetricsThrottle) getAggregatedReports() (reports []core.Payload) { r.mu.Lock() defer r.mu.Unlock() @@ -198,16 +196,4 @@ func (r *MetricsThrottle) getAggregatedReports() (reports []core.Payload) { } return -======= -func (r *MetricsThrottle) getAggregatedReports() []core.Payload { - r.mu.Lock() - defer r.mu.Unlock() - reports := generateMetricsReports(metrics.GenerateMetrics(r.metricsCollections), false) - r.metricsCollections = metrics.Collections{ - Count: 0, - Data: make(map[string]metrics.PerDimension), - } - - return reports ->>>>>>> Create dedicated cache and upstream metrics reports } diff --git a/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go b/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go index 3143605e9c..77fefe5c51 100644 --- a/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go +++ b/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.pb.go @@ -25,37 +25,14 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// Metric type enum type MetricsReport_Type int32 const ( -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> adds updated generated files from protobuf - // System metric type - MetricsReport_SYSTEM MetricsReport_Type = 0 - // NGINX instance metric type - MetricsReport_INSTANCE MetricsReport_Type = 1 - // Agent metric type - MetricsReport_AGENT MetricsReport_Type = 2 - // Cache zone metric type -<<<<<<< HEAD - MetricsReport_CACHE_ZONE MetricsReport_Type = 3 - // Upstreams metric type - MetricsReport_UPSTREAMS MetricsReport_Type = 4 -======= MetricsReport_SYSTEM MetricsReport_Type = 0 MetricsReport_INSTANCE MetricsReport_Type = 1 MetricsReport_AGENT MetricsReport_Type = 2 MetricsReport_CACHE_ZONE MetricsReport_Type = 3 MetricsReport_UPSTREAMS MetricsReport_Type = 4 ->>>>>>> Create dedicated cache and upstream metrics reports -======= - MetricsReport_CACHE_ZONE MetricsReport_Type = 3 - // Upstreams metric type - MetricsReport_UPSTREAMS MetricsReport_Type = 4 ->>>>>>> adds updated generated files from protobuf ) var MetricsReport_Type_name = map[int32]string{ @@ -82,17 +59,13 @@ func (MetricsReport_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor_6039342a2ba47b72, []int{0, 0} } -// Represents a metric report type MetricsReport struct { - // Provides meta information about the metrics - Meta *Metadata `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta"` - // Type of metrics - Type MetricsReport_Type `protobuf:"varint,2,opt,name=type,proto3,enum=f5.nginx.agent.sdk.MetricsReport_Type" json:"type"` - // List of stats entities - Data []*StatsEntity `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Meta *Metadata `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta"` + Type MetricsReport_Type `protobuf:"varint,2,opt,name=type,proto3,enum=f5.nginx.agent.sdk.MetricsReport_Type" json:"type"` + Data []*StatsEntity `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *MetricsReport) Reset() { *m = MetricsReport{} } @@ -150,9 +123,7 @@ func (m *MetricsReport) GetData() []*StatsEntity { } type SimpleMetric struct { - // Metric name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` - // Metric value + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` Value float64 `protobuf:"fixed64,2,opt,name=value,proto3" json:"value"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -208,9 +179,7 @@ func (m *SimpleMetric) GetValue() float64 { // Dimension defines a dimensional attribute used when classifying and categorizing data type Dimension struct { - // Dimension name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` - // Dimension value + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -264,25 +233,14 @@ func (m *Dimension) GetValue() string { return "" } -<<<<<<< HEAD -<<<<<<< HEAD -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics -======= // StatsEntity a timestamped entry for Dimensions and Metrics ->>>>>>> Create dedicated cache and upstream metrics reports -======= -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics ->>>>>>> adds updated generated files from protobuf type StatsEntity struct { - // Timestamp defines the time of stats entity creation - Timestamp *types.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - // List of dimensions - Dimensions []*Dimension `protobuf:"bytes,3,rep,name=dimensions,proto3" json:"dimensions"` - // List of metrics - Simplemetrics []*SimpleMetric `protobuf:"bytes,4,rep,name=simplemetrics,proto3" json:"simplemetrics"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Timestamp *types.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Dimensions []*Dimension `protobuf:"bytes,3,rep,name=dimensions,proto3" json:"dimensions"` + Simplemetrics []*SimpleMetric `protobuf:"bytes,4,rep,name=simplemetrics,proto3" json:"simplemetrics"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *StatsEntity) Reset() { *m = StatsEntity{} } diff --git a/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto b/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto index 88827399e7..9af8b28c60 100644 --- a/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto +++ b/vendor/github.com/nginx/agent/sdk/v2/proto/metrics.proto @@ -6,111 +6,36 @@ import "google/protobuf/timestamp.proto"; import "common.proto"; import "gogo.proto"; -// Represents a metric report message MetricsReport { -<<<<<<< HEAD -<<<<<<< HEAD - // Metric type enum -======= ->>>>>>> Create dedicated cache and upstream metrics reports -======= - // Metric type enum ->>>>>>> adds updated generated files from protobuf enum Type { - // System metric type SYSTEM = 0; - // NGINX instance metric type INSTANCE = 1; - // Agent metric type AGENT = 2; -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> adds updated generated files from protobuf - // Cache zone metric type CACHE_ZONE = 3; - // Upstreams metric type UPSTREAMS = 4; } - // Provides meta information about the metrics Metadata meta = 1 [(gogoproto.jsontag) = "meta" ]; - // Type of metrics Type type = 2 [(gogoproto.jsontag) = "type" ]; - // List of stats entities -<<<<<<< HEAD -======= - CACHE_ZONE = 3; - UPSTREAMS = 4; - } - Metadata meta = 1 [(gogoproto.jsontag) = "meta" ]; - Type type = 2 [(gogoproto.jsontag) = "type" ]; ->>>>>>> Create dedicated cache and upstream metrics reports -======= ->>>>>>> adds updated generated files from protobuf repeated StatsEntity data = 3 [(gogoproto.jsontag) = "data" ]; } message SimpleMetric { -<<<<<<< HEAD -<<<<<<< HEAD - // Metric name - string name = 1 [(gogoproto.jsontag) = "name" ]; - // Metric value -======= - string name = 1 [(gogoproto.jsontag) = "name" ]; ->>>>>>> Create dedicated cache and upstream metrics reports -======= - // Metric name string name = 1 [(gogoproto.jsontag) = "name" ]; - // Metric value ->>>>>>> adds updated generated files from protobuf double value = 2 [(gogoproto.jsontag) = "value" ]; } // Dimension defines a dimensional attribute used when classifying and categorizing data message Dimension { -<<<<<<< HEAD -<<<<<<< HEAD - // Dimension name string name = 1 [(gogoproto.jsontag) = "name" ]; - // Dimension value string value = 2 [(gogoproto.jsontag) = "value" ]; } -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics -======= -======= - // Dimension name ->>>>>>> adds updated generated files from protobuf - string name = 1 [(gogoproto.jsontag) = "name" ]; - // Dimension value - string value = 2 [(gogoproto.jsontag) = "value" ]; -} - -<<<<<<< HEAD // StatsEntity a timestamped entry for Dimensions and Metrics ->>>>>>> Create dedicated cache and upstream metrics reports -======= -// StatsEntity defines a stats entity which is a timestamped entry for dimensions and metrics ->>>>>>> adds updated generated files from protobuf message StatsEntity { - // Timestamp defines the time of stats entity creation google.protobuf.Timestamp timestamp = 1; // DEPRECATED reserved 2; reserved "metrics"; -<<<<<<< HEAD -<<<<<<< HEAD - // List of dimensions - repeated Dimension dimensions = 3 [(gogoproto.jsontag) = "dimensions" ]; - // List of metrics -======= - repeated Dimension dimensions = 3 [(gogoproto.jsontag) = "dimensions" ]; ->>>>>>> Create dedicated cache and upstream metrics reports -======= - // List of dimensions repeated Dimension dimensions = 3 [(gogoproto.jsontag) = "dimensions" ]; - // List of metrics ->>>>>>> adds updated generated files from protobuf repeated SimpleMetric simplemetrics = 4 [(gogoproto.jsontag) = "simplemetrics" ]; }