diff --git a/sdk/proto/events/event.pb.go b/sdk/proto/events/event.pb.go
index 0d8ac2fec..903408281 100644
--- a/sdk/proto/events/event.pb.go
+++ b/sdk/proto/events/event.pb.go
@@ -123,6 +123,7 @@ func (m *Metadata) GetCategory() string {
type Event struct {
Metadata *Metadata `protobuf:"bytes,1,opt,name=Metadata,proto3" json:"metadata"`
// Types that are valid to be assigned to Data:
+ //
// *Event_ActivityEvent
// *Event_SecurityViolationEvent
Data isEvent_Data `protobuf_oneof:"data"`
diff --git a/src/extensions/advanced-metrics/pkg/publisher/publisher_test.go b/src/extensions/advanced-metrics/pkg/publisher/publisher_test.go
index fd6b4f04b..186432328 100644
--- a/src/extensions/advanced-metrics/pkg/publisher/publisher_test.go
+++ b/src/extensions/advanced-metrics/pkg/publisher/publisher_test.go
@@ -20,6 +20,13 @@ func TestPublisher(t *testing.T) {
expectedMetrics []*MetricSet
dimensionsLookups map[int]map[int]string
}{
+ {
+ name: "no metric with no dimension",
+ schema: schema.NewSchema([]*schema.Field{}...),
+ samples: map[string]*sample.Sample{},
+ dimensionsLookups: map[int]map[int]string{},
+ expectedMetrics: []*MetricSet{},
+ },
{
name: "single metric with single dimension",
schema: schema.NewSchema([]*schema.Field{
diff --git a/src/plugins/advanced_metrics.go b/src/plugins/advanced_metrics.go
index 9839b4ea1..3c3c3ac3a 100644
--- a/src/plugins/advanced_metrics.go
+++ b/src/plugins/advanced_metrics.go
@@ -226,7 +226,10 @@ func (m *AdvancedMetrics) run() {
return
}
now := types.TimestampNow()
- m.pipeline.Process(core.NewMessage(core.CommMetrics, []core.Payload{toMetricReport(mr, now, commonDimensions)}))
+ report := toMetricReport(mr, now, commonDimensions)
+ if len(report.Data) != 0 {
+ m.pipeline.Process(core.NewMessage(core.CommMetrics, []core.Payload{report}))
+ }
case <-m.pipeline.Context().Done():
return
}
diff --git a/test/component/advanced_metrics_component_test.go b/test/component/advanced_metrics_component_test.go
index b3a28a9a5..cd8452d32 100644
--- a/test/component/advanced_metrics_component_test.go
+++ b/test/component/advanced_metrics_component_test.go
@@ -53,7 +53,7 @@ var (
)
func init() {
- logrus.SetLevel(logrus.DebugLevel)
+ logrus.SetLevel(logrus.TraceLevel)
}
// TestAdvancedMetricsSimple this is simple test which presents basic logic of advanced_metrics module
diff --git a/test/integration/vendor/github.com/tonistiigi/fsutil/.golangci.yml b/test/integration/vendor/github.com/tonistiigi/fsutil/.golangci.yml
new file mode 100644
index 000000000..788dfd53d
--- /dev/null
+++ b/test/integration/vendor/github.com/tonistiigi/fsutil/.golangci.yml
@@ -0,0 +1,20 @@
+run:
+ timeout: 10m
+ skip-files:
+ - ".*\\.pb\\.go$"
+
+linters:
+ enable:
+ - gofmt
+ - govet
+ - deadcode
+ - goimports
+ - ineffassign
+ - misspell
+ - unused
+ - varcheck
+ - golint
+ - staticcheck
+ - typecheck
+ - structcheck
+ disable-all: true
diff --git a/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/events/event.pb.go b/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/events/event.pb.go
index 0d8ac2fec..903408281 100644
--- a/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/events/event.pb.go
+++ b/test/performance/vendor/github.com/nginx/agent/sdk/v2/proto/events/event.pb.go
@@ -123,6 +123,7 @@ func (m *Metadata) GetCategory() string {
type Event struct {
Metadata *Metadata `protobuf:"bytes,1,opt,name=Metadata,proto3" json:"metadata"`
// Types that are valid to be assigned to Data:
+ //
// *Event_ActivityEvent
// *Event_SecurityViolationEvent
Data isEvent_Data `protobuf_oneof:"data"`
diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/nginx_access_log.go b/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/nginx_access_log.go
index f18dc9fb7..69d0dcf43 100644
--- a/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/nginx_access_log.go
+++ b/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/nginx_access_log.go
@@ -18,6 +18,10 @@ import (
"github.com/nginx/agent/v2/src/core/metrics/sources/tailer"
)
+const (
+ spaceDelim = " "
+)
+
// This metrics source is used to tail the NGINX access logs to retrieve http metrics.
type NginxAccessLog struct {
@@ -207,26 +211,30 @@ func (c *NginxAccessLog) logStats(ctx context.Context, logFile, logFormat string
}
if access.Request != "" {
- splitRequest := strings.Split(access.Request, " ")
- n := fmt.Sprintf("method.%s", strings.ToLower(splitRequest[0]))
+ method, _, protocol := getParsedRequest(access.Request)
+ n := fmt.Sprintf("method.%s", strings.ToLower(method))
if isOtherMethod(n) {
n = "method.others"
}
counters[n] = counters[n] + 1
if access.ServerProtocol == "" {
- httpProtocolVersion := strings.Split(splitRequest[2], "/")[1]
- httpProtocolVersion = strings.ReplaceAll(httpProtocolVersion, ".", "_")
- n = fmt.Sprintf("v%s", httpProtocolVersion)
- counters[n] = counters[n] + 1
+ if strings.Count(protocol, "/") == 1 {
+ httpProtocolVersion := strings.Split(protocol, "/")[1]
+ httpProtocolVersion = strings.ReplaceAll(httpProtocolVersion, ".", "_")
+ n = fmt.Sprintf("v%s", httpProtocolVersion)
+ counters[n] = counters[n] + 1
+ }
}
}
if access.ServerProtocol != "" {
- httpProtocolVersion := strings.Split(access.ServerProtocol, "/")[1]
- httpProtocolVersion = strings.ReplaceAll(httpProtocolVersion, ".", "_")
- n := fmt.Sprintf("v%s", httpProtocolVersion)
- counters[n] = counters[n] + 1
+ if strings.Count(access.ServerProtocol, "/") == 1 {
+ httpProtocolVersion := strings.Split(access.ServerProtocol, "/")[1]
+ httpProtocolVersion = strings.ReplaceAll(httpProtocolVersion, ".", "_")
+ n := fmt.Sprintf("v%s", httpProtocolVersion)
+ counters[n] = counters[n] + 1
+ }
}
// don't need the http status for NGINX Plus
@@ -294,6 +302,35 @@ func (c *NginxAccessLog) logStats(ctx context.Context, logFile, logFormat string
}
}
+func getParsedRequest(request string) (method string, uri string, protocol string) {
+ if len(request) == 0 {
+ return
+ }
+
+ startURIIdx := strings.Index(request, spaceDelim)
+ if startURIIdx == -1 {
+ return
+ }
+
+ endURIIdx := strings.LastIndex(request, spaceDelim)
+ // Ideally, endURIIdx should never be -1 here, as startURIIdx should have handled it already
+ if endURIIdx == -1 {
+ return
+ }
+
+ // For Example: GET /user/register?ahrefp' or ' HTTP/1.1
+
+ // method -> GET
+ method = request[:startURIIdx]
+
+ // uri -> /user/register?ahrefp' or '
+ uri = request[startURIIdx+1 : endURIIdx]
+
+ // protocol -> HTTP/1.1
+ protocol = request[endURIIdx+1:]
+ return
+}
+
func getRequestLengthMetricValue(requestLengths []float64) float64 {
value := 0.0
diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/extensions/nginx-app-protect/monitoring/processor/nap.go b/test/performance/vendor/github.com/nginx/agent/v2/src/extensions/nginx-app-protect/monitoring/processor/nap.go
index ea34ce712..9a93efe49 100644
--- a/test/performance/vendor/github.com/nginx/agent/v2/src/extensions/nginx-app-protect/monitoring/processor/nap.go
+++ b/test/performance/vendor/github.com/nginx/agent/v2/src/extensions/nginx-app-protect/monitoring/processor/nap.go
@@ -81,7 +81,6 @@ var (
subViolations,
supportID,
threatCampaignNames,
- httpURI,
violationRating,
httpHostname,
xForwardedForHeaderVal,
@@ -97,6 +96,7 @@ var (
clientApplication,
clientApplicationVersion,
transportProtocol,
+ httpURI,
}
)
@@ -464,7 +464,7 @@ func setValue(napConfig *NAPConfig, key, value string, logger *logrus.Entry) err
case sigSetNames:
napConfig.SigSetNames = replaceEncodedList(value, listSeperator)
case threatCampaignNames:
- napConfig.ThreatCampaignNames = value
+ napConfig.ThreatCampaignNames = replaceEncodedList(value, listSeperator)
case violationDetails:
napConfig.ViolationDetailsXML = func(data string) *BADMSG {
var xmlData BADMSG
@@ -513,7 +513,7 @@ func setValue(napConfig *NAPConfig, key, value string, logger *logrus.Entry) err
case sigCVEs:
napConfig.SignatureCVEs = replaceEncodedList(value, listSeperator)
case subViolations:
- napConfig.SubViolations = value
+ napConfig.SubViolations = replaceEncodedList(value, listSeperator)
case supportID:
napConfig.SupportID = value
case violations:
diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/advanced_metrics.go b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/advanced_metrics.go
index 9839b4ea1..3c3c3ac3a 100644
--- a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/advanced_metrics.go
+++ b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/advanced_metrics.go
@@ -226,7 +226,10 @@ func (m *AdvancedMetrics) run() {
return
}
now := types.TimestampNow()
- m.pipeline.Process(core.NewMessage(core.CommMetrics, []core.Payload{toMetricReport(mr, now, commonDimensions)}))
+ report := toMetricReport(mr, now, commonDimensions)
+ if len(report.Data) != 0 {
+ m.pipeline.Process(core.NewMessage(core.CommMetrics, []core.Payload{report}))
+ }
case <-m.pipeline.Context().Done():
return
}
diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nap_monitoring.go b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nap_monitoring.go
index 832b88562..e10d28b1b 100644
--- a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nap_monitoring.go
+++ b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nap_monitoring.go
@@ -108,7 +108,7 @@ func (n *NAPMonitoring) run() {
}
case <-riTicker.C:
if len(report.Events) > 0 {
- log.Infof("reached a report interval of %vs, sending %d Security Violation Events as a report", n.reportInterval.Seconds(), n.reportCount)
+ log.Infof("reached a report interval of %vs, sending %d Security Violation Events as a report", n.reportInterval.Seconds(), len(report.Events))
n.send(report)
}
case <-n.ctx.Done():
diff --git a/vendor/github.com/nginx/agent/sdk/v2/proto/events/event.pb.go b/vendor/github.com/nginx/agent/sdk/v2/proto/events/event.pb.go
index 0d8ac2fec..903408281 100644
--- a/vendor/github.com/nginx/agent/sdk/v2/proto/events/event.pb.go
+++ b/vendor/github.com/nginx/agent/sdk/v2/proto/events/event.pb.go
@@ -123,6 +123,7 @@ func (m *Metadata) GetCategory() string {
type Event struct {
Metadata *Metadata `protobuf:"bytes,1,opt,name=Metadata,proto3" json:"metadata"`
// Types that are valid to be assigned to Data:
+ //
// *Event_ActivityEvent
// *Event_SecurityViolationEvent
Data isEvent_Data `protobuf_oneof:"data"`