Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func SetDefaults() {
Viper.SetDefault(MetricsBulkSize, Defaults.AgentMetrics.BulkSize)
Viper.SetDefault(MetricsReportInterval, Defaults.AgentMetrics.ReportInterval)
Viper.SetDefault(MetricsCollectionInterval, Defaults.AgentMetrics.CollectionInterval)

// NGINX DEFAULTS
Viper.SetDefault(NginxClientVersion, Defaults.Nginx.NginxClientVersion)
}

func SetAdvancedMetricsDefaults() {
Expand Down Expand Up @@ -304,6 +307,7 @@ func getNginx() Nginx {
ExcludeLogs: Viper.GetString(NginxExcludeLogs),
Debug: Viper.GetBool(NginxDebug),
NginxCountingSocket: Viper.GetString(NginxCountingSocket),
NginxClientVersion: Viper.GetInt(NginxClientVersion),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
Nginx: Nginx{
Debug: false,
NginxCountingSocket: "unix:/var/run/nginx-agent/nginx.sock",
NginxClientVersion: 6,
},
ConfigDirs: "/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules:/etc/nms",
AllowedDirectoriesMap: map[string]struct{}{},
Expand Down Expand Up @@ -140,6 +141,7 @@ const (
NginxExcludeLogs = NginxKey + KeyDelimiter + "exclude_logs"
NginxDebug = NginxKey + KeyDelimiter + "debug"
NginxCountingSocket = NginxKey + KeyDelimiter + "socket"
NginxClientVersion = NginxKey + KeyDelimiter + "client_version"

// viper keys used in config
DataplaneKey = "dataplane"
Expand Down
1 change: 1 addition & 0 deletions src/core/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Nginx struct {
ExcludeLogs string `mapstructure:"exclude_logs" yaml:"-"`
Debug bool `mapstructure:"debug" yaml:"-"`
NginxCountingSocket string `mapstructure:"socket" yaml:"-"`
NginxClientVersion int `mapstructure:"client_version" yaml:"-"`
}

type Dataplane struct {
Expand Down
2 changes: 1 addition & 1 deletion src/core/metrics/collectors/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func buildSources(dimensions *metrics.CommonDim, binary core.NginxBinary, collec
nginxSources = append(nginxSources, sources.NewNginxAccessLog(dimensions, sources.OSSNamespace, binary, sources.OSSNginxType, collectorConf.CollectionInterval))
nginxSources = append(nginxSources, sources.NewNginxErrorLog(dimensions, sources.OSSNamespace, binary, sources.OSSNginxType, collectorConf.CollectionInterval))
} else if collectorConf.PlusAPI != "" {
nginxSources = append(nginxSources, sources.NewNginxPlus(dimensions, sources.OSSNamespace, sources.PlusNamespace, collectorConf.PlusAPI))
nginxSources = append(nginxSources, sources.NewNginxPlus(dimensions, sources.OSSNamespace, sources.PlusNamespace, collectorConf.PlusAPI, collectorConf.ClientVersion))
nginxSources = append(nginxSources, sources.NewNginxAccessLog(dimensions, sources.OSSNamespace, binary, sources.PlusNginxType, collectorConf.CollectionInterval))
nginxSources = append(nginxSources, sources.NewNginxErrorLog(dimensions, sources.OSSNamespace, binary, sources.PlusNginxType, collectorConf.CollectionInterval))
} else {
Expand Down
1 change: 1 addition & 0 deletions src/core/metrics/metrics_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type NginxCollectorConfig struct {
CollectionInterval time.Duration
AccessLogs []string
ErrorLogs []string
ClientVersion int
}

func NewStatsEntity(dims []*proto.Dimension, samples []*proto.SimpleMetric) *proto.StatsEntity {
Expand Down
13 changes: 7 additions & 6 deletions src/core/metrics/sources/nginx_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ type NginxPlus struct {
plusNamespace,
plusAPI string
// This is for keeping the previous stats. Need to report the delta.
prevStats *plusclient.Stats
init sync.Once
prevStats *plusclient.Stats
init sync.Once
clientVersion int
}

func NewNginxPlus(baseDimensions *metrics.CommonDim, nginxNamespace, plusNamespace, plusAPI string) *NginxPlus {
return &NginxPlus{baseDimensions: baseDimensions, nginxNamespace: nginxNamespace, plusNamespace: plusNamespace, plusAPI: plusAPI}
func NewNginxPlus(baseDimensions *metrics.CommonDim, nginxNamespace, plusNamespace, plusAPI string, clientVersion int) *NginxPlus {
return &NginxPlus{baseDimensions: baseDimensions, nginxNamespace: nginxNamespace, plusNamespace: plusNamespace, plusAPI: plusAPI, clientVersion: clientVersion}
}

func (c *NginxPlus) Collect(ctx context.Context, wg *sync.WaitGroup, m chan<- *proto.StatsEntity) {
defer wg.Done()
c.init.Do(func() {
cl, err := plusclient.NewNginxClient(&http.Client{}, c.plusAPI)
cl, err := plusclient.NewNginxClientWithVersion(&http.Client{}, c.plusAPI, c.clientVersion)
if err != nil {
log.Errorf("Failed to create plus metrics client: %v", err)
SendNginxDownStatus(ctx, c.baseDimensions.ToDimensions(), m)
Expand All @@ -59,7 +60,7 @@ func (c *NginxPlus) Collect(ctx context.Context, wg *sync.WaitGroup, m chan<- *p
}
})

cl, err := plusclient.NewNginxClient(&http.Client{}, c.plusAPI)
cl, err := plusclient.NewNginxClientWithVersion(&http.Client{}, c.plusAPI, c.clientVersion)
if err != nil {
log.Errorf("Failed to create plus metrics client: %v", err)
SendNginxDownStatus(ctx, c.baseDimensions.ToDimensions(), m)
Expand Down
4 changes: 2 additions & 2 deletions src/core/metrics/sources/nginx_plus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (f *FakeNginxPlus) Collect(ctx context.Context, wg *sync.WaitGroup, m chan<
}

func TestNginxPlusUpdate(t *testing.T) {
nginxPlus := NewNginxPlus(&metrics.CommonDim{}, "test", PlusNamespace, "http://localhost:8080/api")
nginxPlus := NewNginxPlus(&metrics.CommonDim{}, "test", PlusNamespace, "http://localhost:8080/api", 6)

assert.Equal(t, "", nginxPlus.baseDimensions.InstanceTags)
assert.Equal(t, "http://localhost:8080/api", nginxPlus.plusAPI)
Expand Down Expand Up @@ -643,7 +643,7 @@ func TestNginxPlus_Collect(t *testing.T) {
for _, test := range tests {
ctx := context.TODO()

f := &FakeNginxPlus{NewNginxPlus(test.baseDimensions, "nginx", "plus", "")}
f := &FakeNginxPlus{NewNginxPlus(test.baseDimensions, "nginx", "plus", "", 6)}
wg := &sync.WaitGroup{}
wg.Add(1)
go f.Collect(ctx, wg, test.m)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ func createCollectorConfigsMap(config *config.Config, env core.Environment, bina
AccessLogs: sdk.GetAccessLogs(accessLogs),
ErrorLogs: sdk.GetErrorLogs(errorLogs),
NginxId: detail.NginxId,
ClientVersion: config.Nginx.NginxClientVersion,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/component/advanced_metrics_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ func toMessage(data ...interface{}) []byte {
func assertMessageSent(t *testing.T, addr string, dataToSend [][]byte) {
numberOfRetries := 3
conn, err := net.Dial("unix", addr)

// if net.Dial fails connection will be retried 3 times
for i := 0; i <= numberOfRetries && err != nil; i++ {
time.Sleep(5 * time.Millisecond)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.