Skip to content

Commit 678ddbc

Browse files
committed
Add agent config option to set NGINX API URL
1 parent 4e188b5 commit 678ddbc

File tree

15 files changed

+149
-89
lines changed

15 files changed

+149
-89
lines changed

docs/proto/proto.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
- [AgentConnectStatus.StatusCode](#f5-nginx-agent-sdk-AgentConnectStatus-StatusCode)
1919
- [AgentLogging.Level](#f5-nginx-agent-sdk-AgentLogging-Level)
2020

21+
- [command_svc.proto](#command_svc-proto)
22+
- [Commander](#f5-nginx-agent-sdk-Commander)
23+
2124
- [command.proto](#command-proto)
2225
- [AgentActivityStatus](#f5-nginx-agent-sdk-AgentActivityStatus)
2326
- [ChunkedResourceChunk](#f5-nginx-agent-sdk-ChunkedResourceChunk)
@@ -39,9 +42,6 @@
3942
- [NginxConfigStatus.Status](#f5-nginx-agent-sdk-NginxConfigStatus-Status)
4043
- [UploadStatus.TransferStatus](#f5-nginx-agent-sdk-UploadStatus-TransferStatus)
4144

42-
- [command_svc.proto](#command_svc-proto)
43-
- [Commander](#f5-nginx-agent-sdk-Commander)
44-
4545
- [common.proto](#common-proto)
4646
- [CertificateDates](#f5-nginx-agent-sdk-CertificateDates)
4747
- [CertificateName](#f5-nginx-agent-sdk-CertificateName)
@@ -341,6 +341,34 @@ Log level enum
341341

342342

343343

344+
<a name="command_svc-proto"></a>
345+
<p align="right"><a href="#top">Top</a></p>
346+
347+
## command_svc.proto
348+
349+
350+
351+
352+
353+
354+
355+
356+
357+
<a name="f5-nginx-agent-sdk-Commander"></a>
358+
359+
### Commander
360+
Represents a service used to sent command messages between the management server and the agent.
361+
362+
| Method Name | Request Type | Response Type | Description |
363+
| ----------- | ------------ | ------------- | ------------|
364+
| CommandChannel | [Command](#f5-nginx-agent-sdk-Command) stream | [Command](#f5-nginx-agent-sdk-Command) stream | A Bidirectional streaming RPC established by the agent and is kept open |
365+
| Download | [DownloadRequest](#f5-nginx-agent-sdk-DownloadRequest) | [DataChunk](#f5-nginx-agent-sdk-DataChunk) stream | A streaming RPC established by the agent and is used to download resources associated with commands The download stream will be kept open for the duration of the data transfer and will be closed when its done. The transfer is a stream of chunks as follows: header -&gt; data chunk 1 -&gt; data chunk N. Each data chunk is of a size smaller than the maximum gRPC payload |
366+
| Upload | [DataChunk](#f5-nginx-agent-sdk-DataChunk) stream | [UploadStatus](#f5-nginx-agent-sdk-UploadStatus) | A streaming RPC established by the agent and is used to upload resources associated with commands |
367+
368+
369+
370+
371+
344372
<a name="command-proto"></a>
345373
<p align="right"><a href="#top">Top</a></p>
346374

@@ -652,34 +680,6 @@ Transfer status enum
652680

653681

654682

655-
<a name="command_svc-proto"></a>
656-
<p align="right"><a href="#top">Top</a></p>
657-
658-
## command_svc.proto
659-
660-
661-
662-
663-
664-
665-
666-
667-
668-
<a name="f5-nginx-agent-sdk-Commander"></a>
669-
670-
### Commander
671-
Represents a service used to sent command messages between the management server and the agent.
672-
673-
| Method Name | Request Type | Response Type | Description |
674-
| ----------- | ------------ | ------------- | ------------|
675-
| CommandChannel | [Command](#f5-nginx-agent-sdk-Command) stream | [Command](#f5-nginx-agent-sdk-Command) stream | A Bidirectional streaming RPC established by the agent and is kept open |
676-
| Download | [DownloadRequest](#f5-nginx-agent-sdk-DownloadRequest) | [DataChunk](#f5-nginx-agent-sdk-DataChunk) stream | A streaming RPC established by the agent and is used to download resources associated with commands The download stream will be kept open for the duration of the data transfer and will be closed when its done. The transfer is a stream of chunks as follows: header -&gt; data chunk 1 -&gt; data chunk N. Each data chunk is of a size smaller than the maximum gRPC payload |
677-
| Upload | [DataChunk](#f5-nginx-agent-sdk-DataChunk) stream | [UploadStatus](#f5-nginx-agent-sdk-UploadStatus) | A streaming RPC established by the agent and is used to upload resources associated with commands |
678-
679-
680-
681-
682-
683683
<a name="common-proto"></a>
684684
<p align="right"><a href="#top">Top</a></p>
685685

src/core/config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ func getNginx() Nginx {
354354
NginxClientVersion: Viper.GetInt(NginxClientVersion),
355355
ConfigReloadMonitoringPeriod: Viper.GetDuration(NginxConfigReloadMonitoringPeriod),
356356
TreatWarningsAsErrors: Viper.GetBool(NginxTreatWarningsAsErrors),
357-
ApiTls: TLSConfig{
358-
Ca: Viper.GetString(NginxApiTlsCa),
357+
API: &NginxAPI{
358+
URL: Viper.GetString(NginxApiURLKey),
359+
TLS: TLSConfig{Ca: Viper.GetString(NginxApiTlsCa)},
359360
},
360361
}
361362
}

src/core/config/defaults.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ var (
6666
NginxClientVersion: 7, // NGINX Plus R25+
6767
ConfigReloadMonitoringPeriod: 10 * time.Second,
6868
TreatWarningsAsErrors: false,
69-
ApiTls: TLSConfig{
70-
Ca: "",
69+
API: &NginxAPI{
70+
URL: "",
71+
TLS: TLSConfig{
72+
Ca: "",
73+
},
7174
},
7275
},
7376
ConfigDirs: "/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules:/etc/nms",
@@ -179,6 +182,7 @@ const (
179182
NginxConfigReloadMonitoringPeriod = NginxKey + agent_config.KeyDelimiter + "config_reload_monitoring_period"
180183
NginxTreatWarningsAsErrors = NginxKey + agent_config.KeyDelimiter + "treat_warnings_as_errors"
181184
NginxApiTlsCa = NginxKey + agent_config.KeyDelimiter + "api_tls_ca"
185+
NginxApiURLKey = NginxKey + agent_config.KeyDelimiter + "api_url"
182186

183187
// viper keys used in config
184188
DataplaneKey = "dataplane"
@@ -325,10 +329,15 @@ var (
325329
Usage: "On nginx -t, treat warnings as failures on configuration application.",
326330
DefaultValue: Defaults.Nginx.TreatWarningsAsErrors,
327331
},
332+
&StringFlag{
333+
Name: NginxApiURLKey,
334+
Usage: "The NGINX Plus API URL.",
335+
DefaultValue: Defaults.Nginx.API.URL,
336+
},
328337
&StringFlag{
329338
Name: NginxApiTlsCa,
330339
Usage: "The NGINX Plus CA certificate file location needed to call the NGINX Plus API if SSL is enabled.",
331-
DefaultValue: Defaults.Nginx.ApiTls.Ca,
340+
DefaultValue: Defaults.Nginx.API.TLS.Ca,
332341
},
333342
// Metrics
334343
&DurationFlag{

src/core/config/types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,12 @@ type Nginx struct {
155155
NginxClientVersion int `mapstructure:"client_version" yaml:"-"`
156156
ConfigReloadMonitoringPeriod time.Duration `mapstructure:"config_reload_monitoring_period" yaml:"-"`
157157
TreatWarningsAsErrors bool `mapstructure:"treat_warnings_as_errors" yaml:"-"`
158-
ApiTls TLSConfig `mapstructure:"api_tls" yaml:"-"`
158+
API *NginxAPI `mapstructure:"api"`
159+
}
160+
161+
type NginxAPI struct {
162+
URL string `mapstructure:"url"`
163+
TLS TLSConfig `mapstructure:"tls"`
159164
}
160165

161166
type Dataplane struct {

src/core/metrics/sources/nginx_plus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func NewNginxPlus(baseDimensions *metrics.CommonDim, nginxNamespace, plusNamespa
8787

8888
client := http.DefaultClient
8989

90-
if conf.Nginx.ApiTls.Ca != "" && conf.IsFileAllowed(conf.Nginx.ApiTls.Ca) {
91-
data, err := os.ReadFile(conf.Nginx.ApiTls.Ca)
90+
if conf.Nginx.API != nil && conf.Nginx.API.TLS.Ca != "" && conf.IsFileAllowed(conf.Nginx.API.TLS.Ca) {
91+
data, err := os.ReadFile(conf.Nginx.API.TLS.Ca)
9292
if err != nil {
9393
log.Errorf("Unable to collect NGINX Plus metrics. Failed to read NGINX CA certificate file: %v", err)
9494
return nil

src/core/nginx.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,25 @@ func (n *NginxBinaryType) GetNginxDetailsFromProcess(nginxProcess *Process) *pro
220220
n.statusUrlMutex.RUnlock()
221221

222222
if urlsLength == 0 || nginxStatus == "" {
223-
stubStatusApiUrl, err := sdk.GetStubStatusApiUrl(nginxDetailsFacade.ConfPath, n.config.IgnoreDirectives)
224-
if err != nil {
225-
log.Tracef("Unable to get Stub Status API URL from the configuration: NGINX OSS metrics will be unavailable for this system. please configure a Stub Status API to get NGINX OSS metrics: %v", err)
226-
}
223+
// If NGINX API URL is configured in agent config then use that istead of discovering the URL from the NGINX configuration
224+
if n.config.Nginx.API != nil && n.config.Nginx.API.URL != "" {
225+
nginxDetailsFacade.StatusUrl = n.config.Nginx.API.URL
226+
} else {
227+
stubStatusApiUrl, err := sdk.GetStubStatusApiUrl(nginxDetailsFacade.ConfPath, n.config.IgnoreDirectives)
228+
if err != nil {
229+
log.Tracef("Unable to get Stub Status API URL from the configuration: NGINX OSS metrics will be unavailable for this system. please configure a Stub Status API to get NGINX OSS metrics: %v", err)
230+
}
227231

228-
nginxPlusApiUrl, err := sdk.GetNginxPlusApiUrl(nginxDetailsFacade.ConfPath, n.config.IgnoreDirectives)
229-
if err != nil {
230-
log.Tracef("Unable to get NGINX Plus API URL from the configuration: NGINX Plus metrics will be unavailable for this system. please configure a NGINX Plus API to get NGINX Plus metrics: %v", err)
231-
}
232+
nginxPlusApiUrl, err := sdk.GetNginxPlusApiUrl(nginxDetailsFacade.ConfPath, n.config.IgnoreDirectives)
233+
if err != nil {
234+
log.Tracef("Unable to get NGINX Plus API URL from the configuration: NGINX Plus metrics will be unavailable for this system. please configure a NGINX Plus API to get NGINX Plus metrics: %v", err)
235+
}
232236

233-
if nginxDetailsFacade.Plus.Enabled {
234-
nginxDetailsFacade.StatusUrl = nginxPlusApiUrl
235-
} else {
236-
nginxDetailsFacade.StatusUrl = stubStatusApiUrl
237+
if nginxDetailsFacade.Plus.Enabled {
238+
nginxDetailsFacade.StatusUrl = nginxPlusApiUrl
239+
} else {
240+
nginxDetailsFacade.StatusUrl = stubStatusApiUrl
241+
}
237242
}
238243

239244
n.statusUrlMutex.Lock()

test/integration/vendor/github.com/nginx/agent/v2/src/core/config/config.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/vendor/github.com/nginx/agent/v2/src/core/config/defaults.go

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/vendor/github.com/nginx/agent/v2/src/core/config/types.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go

Lines changed: 17 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)