Skip to content

Commit ec797b5

Browse files
authored
Merge branch 'main' into docs/release-process
2 parents 0397ff5 + dccd7cc commit ec797b5

File tree

4 files changed

+41
-74
lines changed

4 files changed

+41
-74
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,19 @@ linters:
3737
- asasalint
3838
- asciicheck
3939
- bidichk
40+
- contextcheck
4041
- dupword
42+
- durationcheck
4143
- errcheck
44+
- errchkjson
4245
- errname
4346
- errorlint
4447
- exportloopref
4548
- fatcontext
4649
- forcetypeassert
4750
- gocheckcompilerdirectives
51+
- gochecksumtype
52+
- gocritic
4853
- godot
4954
- gofmt
5055
- gofumpt
@@ -58,6 +63,7 @@ linters:
5863
- loggercheck
5964
- makezero
6065
- misspell
66+
- musttag
6167
- nilerr
6268
- noctx
6369
- nolintlint

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Flags:
300300
| `nginxplus_upstream_server_ssl_handshakes` | Counter | Successful SSL handshakes | `server`, `upstream` |
301301
| `nginxplus_upstream_server_ssl_handshakes_failed` | Counter | Failed SSL handshakes | `server`, `upstream` |
302302
| `nginxplus_upstream_server_ssl_session_reuses` | Counter | Session reuses during SSL handshake | `server`, `upstream` |
303-
| `nginxplus_upstream_keepalive` | Gauge | Idle keepalive connections | `upstream` |
303+
| `nginxplus_upstream_keepalive` | Gauge | Idle keepalive connections | `upstream` |
304304
| `nginxplus_upstream_zombies` | Gauge | Servers removed from the group but still processing active client requests | `upstream` |
305305

306306
#### [Stream Upstreams](https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_stream_upstream)
@@ -394,7 +394,7 @@ Flags:
394394
| `nginxplus_stream_limit_connection_rejected` | Counter | Total number of connections that were rejected | `zone` |
395395
| `nginxplus_stream_limit_connection_rejected_dry_run` | Counter | Total number of connections accounted as rejected in the dry run mode | `zone` |
396396

397-
#### [Cache](https://nginx.org/en/docs/http/ngx_http_api_module.html#http_caches_http_cache_zone_name)
397+
#### [Cache](https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_http_cache)
398398

399399
| Name | Type | Description | Labels |
400400
| ------------------------------------------- | ------- | ----------------------------------------------------------------------- | ------- |
@@ -420,16 +420,16 @@ Flags:
420420
| `nginxplus_cache_bypass_responses_written` | Counter | Total number of cache bypasses written to cache | `cache` |
421421
| `nginxplus_cache_bypass_bytes_written` | Counter | Total number of bytes written to cache from cache bypasses | `cache` |
422422

423-
#### [Worker](hhttps://nginx.org/en/docs/http/ngx_http_api_module.html#workers)
423+
#### [Worker](https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_worker)
424424

425-
| Name | Type | Description | Labels |
426-
| ---------------------------------------- | ------- | ---------------------------------------------------------------------------------------------- | ----------- |
427-
| `nginxplus_worker_connection_accepted` | Counter | The total number of accepted client connections | `id`, `pid` |
428-
| `nginxplus_worker_connection_dropped` | Counter | The total number of accepted client connections | `id`, `pid` |
429-
| `nginxplus_worker_connection_active` | Gauge | The current number of active client connections | `id`, `pid` |
430-
| `nginxplus_worker_connection_idle` | Gauge | The current number of idle client connection | `id`, `pid` |
431-
| `nginxplus_worker_http_requests_total` | Counter | The total number of client requests received by the worker process | `id`, `pid` |
432-
| `nginxplus_worker_http_requests_current` | Gauge | The current number of client requests that are currently being processed by the worker process | `id`, `pid` |
425+
| Name | Type | Description | Labels |
426+
| ---------------------------------------- | ------- | ------------------------------------------------------------------------ | ----------- |
427+
| `nginxplus_worker_connection_accepted` | Counter | The total number of accepted client connections | `id`, `pid` |
428+
| `nginxplus_worker_connection_dropped` | Counter | The total number of dropped client connections | `id`, `pid` |
429+
| `nginxplus_worker_connection_active` | Gauge | The current number of active client connections | `id`, `pid` |
430+
| `nginxplus_worker_connection_idle` | Gauge | The current number of idle client connection | `id`, `pid` |
431+
| `nginxplus_worker_http_requests_total` | Counter | The total number of client requests received | `id`, `pid` |
432+
| `nginxplus_worker_http_requests_current` | Gauge | The current number of client requests that are currently being processed | `id`, `pid` |
433433

434434
Connect to the `/metrics` page of the running exporter to see the complete list of metrics along with their
435435
descriptions. Note: to see server zones related metrics you must configure [status

collector/nginx_plus.go

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ type LabelUpdater interface {
2727
DeleteStreamServerZoneLabels(zoneNames []string)
2828
UpdateCacheZoneLabels(cacheLabelValues map[string][]string)
2929
DeleteCacheZoneLabels(cacheNames []string)
30-
UpdateWorkerLabels(workerLabelValues map[string][]string)
31-
DeleteWorkerLabels(workerNames []string)
3230
}
3331

3432
// NginxPlusCollector collects NGINX Plus metrics. It implements prometheus.Collector interface.
@@ -56,7 +54,6 @@ type NginxPlusCollector struct {
5654
serverZoneLabels map[string][]string
5755
streamServerZoneLabels map[string][]string
5856
upstreamServerPeerLabels map[string][]string
59-
workerLabels map[string][]string
6057
cacheZoneLabels map[string][]string
6158
totalMetrics map[string]*prometheus.Desc
6259
variableLabelNames VariableLabelNames
@@ -226,30 +223,6 @@ func (c *NginxPlusCollector) getStreamUpstreamServerPeerLabelValues(peer string)
226223
return c.streamUpstreamServerPeerLabels[peer]
227224
}
228225

229-
// UpdateWorkerLabels updates the Worker Labels.
230-
func (c *NginxPlusCollector) UpdateWorkerLabels(workerLabelValues map[string][]string) {
231-
c.variableLabelsMutex.Lock()
232-
for k, v := range workerLabelValues {
233-
c.workerLabels[k] = v
234-
}
235-
c.variableLabelsMutex.Unlock()
236-
}
237-
238-
// DeleteWorkerLabels deletes the Worker Labels.
239-
func (c *NginxPlusCollector) DeleteWorkerLabels(id []string) {
240-
c.variableLabelsMutex.Lock()
241-
for _, k := range id {
242-
delete(c.workerLabels, k)
243-
}
244-
c.variableLabelsMutex.Unlock()
245-
}
246-
247-
func (c *NginxPlusCollector) getWorkerLabelValues(id string) []string {
248-
c.variableLabelsMutex.RLock()
249-
defer c.variableLabelsMutex.RUnlock()
250-
return c.workerLabels[id]
251-
}
252-
253226
// VariableLabelNames holds all the variable label names for the different metrics.
254227
type VariableLabelNames struct {
255228
UpstreamServerVariableLabelNames []string
@@ -259,12 +232,11 @@ type VariableLabelNames struct {
259232
StreamServerZoneVariableLabelNames []string
260233
StreamUpstreamServerVariableLabelNames []string
261234
CacheZoneLabelNames []string
262-
WorkerPIDVariableLabelNames []string
263235
}
264236

265237
// NewVariableLabelNames NewVariableLabels creates a new struct for VariableNames for the collector.
266238
func NewVariableLabelNames(upstreamServerVariableLabelNames []string, serverZoneVariableLabelNames []string, upstreamServerPeerVariableLabelNames []string,
267-
streamUpstreamServerVariableLabelNames []string, streamServerZoneLabels []string, streamUpstreamServerPeerVariableLabelNames []string, cacheZoneLabelNames []string, workerPIDVariableLabelNames []string,
239+
streamUpstreamServerVariableLabelNames []string, streamServerZoneLabels []string, streamUpstreamServerPeerVariableLabelNames []string, cacheZoneLabelNames []string,
268240
) VariableLabelNames {
269241
return VariableLabelNames{
270242
UpstreamServerVariableLabelNames: upstreamServerVariableLabelNames,
@@ -274,14 +246,16 @@ func NewVariableLabelNames(upstreamServerVariableLabelNames []string, serverZone
274246
StreamServerZoneVariableLabelNames: streamServerZoneLabels,
275247
StreamUpstreamServerPeerVariableLabelNames: streamUpstreamServerPeerVariableLabelNames,
276248
CacheZoneLabelNames: cacheZoneLabelNames,
277-
WorkerPIDVariableLabelNames: workerPIDVariableLabelNames,
278249
}
279250
}
280251

281252
// NewNginxPlusCollector creates an NginxPlusCollector.
282253
func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string, variableLabelNames VariableLabelNames, constLabels map[string]string, logger log.Logger) *NginxPlusCollector {
283-
upstreamServerVariableLabelNames := append(variableLabelNames.UpstreamServerVariableLabelNames, variableLabelNames.UpstreamServerPeerVariableLabelNames...)
284-
streamUpstreamServerVariableLabelNames := append(variableLabelNames.StreamUpstreamServerVariableLabelNames, variableLabelNames.StreamUpstreamServerPeerVariableLabelNames...)
254+
upstreamServerVariableLabelNames := variableLabelNames.UpstreamServerVariableLabelNames
255+
streamUpstreamServerVariableLabelNames := variableLabelNames.StreamUpstreamServerVariableLabelNames
256+
257+
upstreamServerVariableLabelNames = append(upstreamServerVariableLabelNames, variableLabelNames.UpstreamServerPeerVariableLabelNames...)
258+
streamUpstreamServerVariableLabelNames = append(streamUpstreamServerVariableLabelNames, variableLabelNames.StreamUpstreamServerPeerVariableLabelNames...)
285259
return &NginxPlusCollector{
286260
variableLabelNames: variableLabelNames,
287261
upstreamServerLabels: make(map[string][]string),
@@ -575,12 +549,12 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
575549
"bypass_bytes_written": newCacheZoneMetric(namespace, "bypass_bytes_written", "Total number of bytes written to cache from cache bypasses", constLabels),
576550
},
577551
workerMetrics: map[string]*prometheus.Desc{
578-
"connection_accepted": newWorkerMetric(namespace, "connection_accepted", "The total number of accepted client connections", variableLabelNames.WorkerPIDVariableLabelNames, constLabels),
579-
"connection_dropped": newWorkerMetric(namespace, "connection_dropped", "The total number of dropped client connections", variableLabelNames.WorkerPIDVariableLabelNames, constLabels),
580-
"connection_active": newWorkerMetric(namespace, "connection_active", "The current number of active client connections", variableLabelNames.WorkerPIDVariableLabelNames, constLabels),
581-
"connection_idle": newWorkerMetric(namespace, "connection_idle", "The current number of idle client connections", variableLabelNames.WorkerPIDVariableLabelNames, constLabels),
582-
"http_requests_total": newWorkerMetric(namespace, "http_requests_total", "The total number of client requests received by the worker process", variableLabelNames.WorkerPIDVariableLabelNames, constLabels),
583-
"http_requests_current": newWorkerMetric(namespace, "http_requests_current", "The current number of client requests that are currently being processed by the worker process", variableLabelNames.WorkerPIDVariableLabelNames, constLabels),
552+
"connection_accepted": newWorkerMetric(namespace, "connection_accepted", "The total number of accepted client connections", constLabels),
553+
"connection_dropped": newWorkerMetric(namespace, "connection_dropped", "The total number of dropped client connections", constLabels),
554+
"connection_active": newWorkerMetric(namespace, "connection_active", "The current number of active client connections", constLabels),
555+
"connection_idle": newWorkerMetric(namespace, "connection_idle", "The current number of idle client connections", constLabels),
556+
"http_requests_total": newWorkerMetric(namespace, "http_requests_total", "The total number of client requests received by the worker process", constLabels),
557+
"http_requests_current": newWorkerMetric(namespace, "http_requests_current", "The current number of client requests that are currently being processed by the worker process", constLabels),
584558
},
585559
}
586560
}
@@ -1249,26 +1223,15 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) {
12491223
ch <- prometheus.MustNewConstMetric(c.cacheZoneMetrics["bypass_bytes_written"], prometheus.CounterValue, float64(zone.Bypass.BytesWritten), name)
12501224
}
12511225

1252-
for _, worker := range stats.Workers {
1253-
labelValues := []string{strconv.FormatInt(int64(worker.ID), 10), strconv.FormatInt(int64(worker.ProcessID), 10)}
1254-
varLabelValues := c.getWorkerLabelValues(strconv.FormatInt(int64(worker.ID), 10))
1255-
1256-
if c.variableLabelNames.WorkerPIDVariableLabelNames != nil && len(varLabelValues) != len(c.variableLabelNames.WorkerPIDVariableLabelNames) {
1257-
level.Debug(c.logger).Log("wrong number of labels for worker %v. For labels %v, got values: %v. Empty labels will be used instead",
1258-
strconv.FormatInt(int64(worker.ID), 10), c.variableLabelNames.WorkerPIDVariableLabelNames, varLabelValues)
1259-
for range c.variableLabelNames.WorkerPIDVariableLabelNames {
1260-
labelValues = append(labelValues, "")
1261-
}
1262-
} else {
1263-
labelValues = append(labelValues, varLabelValues...)
1264-
}
1265-
1266-
ch <- prometheus.MustNewConstMetric(c.workerMetrics["connection_accepted"], prometheus.CounterValue, float64(worker.Connections.Accepted), labelValues...)
1267-
ch <- prometheus.MustNewConstMetric(c.workerMetrics["connection_dropped"], prometheus.CounterValue, float64(worker.Connections.Dropped), labelValues...)
1268-
ch <- prometheus.MustNewConstMetric(c.workerMetrics["connection_active"], prometheus.GaugeValue, float64(worker.Connections.Active), labelValues...)
1269-
ch <- prometheus.MustNewConstMetric(c.workerMetrics["connection_idle"], prometheus.GaugeValue, float64(worker.Connections.Idle), labelValues...)
1270-
ch <- prometheus.MustNewConstMetric(c.workerMetrics["http_requests_total"], prometheus.CounterValue, float64(worker.HTTP.HTTPRequests.Total), labelValues...)
1271-
ch <- prometheus.MustNewConstMetric(c.workerMetrics["http_requests_current"], prometheus.GaugeValue, float64(worker.HTTP.HTTPRequests.Current), labelValues...)
1226+
for id, worker := range stats.Workers {
1227+
workerID := strconv.FormatInt(int64(id), 10)
1228+
workerPID := strconv.FormatUint(worker.ProcessID, 10)
1229+
ch <- prometheus.MustNewConstMetric(c.workerMetrics["connection_accepted"], prometheus.CounterValue, float64(worker.Connections.Accepted), workerID, workerPID)
1230+
ch <- prometheus.MustNewConstMetric(c.workerMetrics["connection_dropped"], prometheus.CounterValue, float64(worker.Connections.Dropped), workerID, workerPID)
1231+
ch <- prometheus.MustNewConstMetric(c.workerMetrics["connection_active"], prometheus.GaugeValue, float64(worker.Connections.Active), workerID, workerPID)
1232+
ch <- prometheus.MustNewConstMetric(c.workerMetrics["connection_idle"], prometheus.GaugeValue, float64(worker.Connections.Idle), workerID, workerPID)
1233+
ch <- prometheus.MustNewConstMetric(c.workerMetrics["http_requests_total"], prometheus.CounterValue, float64(worker.HTTP.HTTPRequests.Total), workerID, workerPID)
1234+
ch <- prometheus.MustNewConstMetric(c.workerMetrics["http_requests_current"], prometheus.GaugeValue, float64(worker.HTTP.HTTPRequests.Current), workerID, workerPID)
12721235
}
12731236
}
12741237

@@ -1345,8 +1308,6 @@ func newCacheZoneMetric(namespace string, metricName string, docString string, c
13451308
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "cache", metricName), docString, []string{"zone"}, constLabels)
13461309
}
13471310

1348-
func newWorkerMetric(namespace string, metricName string, docString string, variableLabelNames []string, constLabels prometheus.Labels) *prometheus.Desc {
1349-
labels := []string{"id", "pid"}
1350-
labels = append(labels, variableLabelNames...)
1351-
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "worker", metricName), docString, labels, constLabels)
1311+
func newWorkerMetric(namespace string, metricName string, docString string, constLabels prometheus.Labels) *prometheus.Desc {
1312+
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "worker", metricName), docString, []string{"id", "pid"}, constLabels)
13521313
}

exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func registerCollector(logger log.Logger, transport *http.Transport,
253253
level.Error(logger).Log("msg", "Could not create Nginx Plus Client", "error", err.Error())
254254
os.Exit(1)
255255
}
256-
variableLabelNames := collector.NewVariableLabelNames(nil, nil, nil, nil, nil, nil, nil, nil)
256+
variableLabelNames := collector.NewVariableLabelNames(nil, nil, nil, nil, nil, nil, nil)
257257
prometheus.MustRegister(collector.NewNginxPlusCollector(plusClient, "nginxplus", variableLabelNames, labels, logger))
258258
} else {
259259
ossClient := client.NewNginxClient(httpClient, addr)

0 commit comments

Comments
 (0)