Skip to content

Commit

Permalink
Merge branch 'main' into add-repo-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean-Coakley committed May 24, 2023
2 parents a934046 + 62ceb58 commit 3d2435d
Show file tree
Hide file tree
Showing 2,352 changed files with 288,243 additions and 24,307 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- 'main'
- 'release-*'
paths-ignore:
- "**.md"
- "docs/**"
- "hugo/**"
pull_request:
types:
- opened
Expand Down
42 changes: 42 additions & 0 deletions docs/proto/proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- [AgentDetails](#f5-nginx-agent-sdk-AgentDetails)
- [AgentLogging](#f5-nginx-agent-sdk-AgentLogging)
- [AgentMeta](#f5-nginx-agent-sdk-AgentMeta)
- [Backoff](#f5-nginx-agent-sdk-Backoff)
- [Server](#f5-nginx-agent-sdk-Server)

- [AgentConnectStatus.StatusCode](#f5-nginx-agent-sdk-AgentConnectStatus-StatusCode)
- [AgentLogging.Level](#f5-nginx-agent-sdk-AgentLogging-Level)
Expand Down Expand Up @@ -204,6 +206,7 @@ Represents agent details. This message is sent from the management server to the
| extensions | [string](#string) | repeated | List of agent extensions that are enabled |
| tags | [string](#string) | repeated | List of tags |
| alias | [string](#string) | | Alias name for the agent |
| server | [Server](#f5-nginx-agent-sdk-Server) | | Server setting for the agent |



Expand Down Expand Up @@ -251,6 +254,45 @@ Represents agent metadata




<a name="f5-nginx-agent-sdk-Backoff"></a>

### Backoff



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| initial_interval | [int64](#int64) | | First backoff time interval in seconds |
| randomization_factor | [double](#double) | | Random value used to create range around next backoff interval |
| multiplier | [double](#double) | | Value to be multiplied with current backoff interval |
| max_interval | [int64](#int64) | | Max interval in seconds between two retries |
| max_elapsed_time | [int64](#int64) | | Elapsed time in seconds after which backoff stops. It never stops if max_elapsed_time == 0. |






<a name="f5-nginx-agent-sdk-Server"></a>

### Server



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| host | [string](#string) | | Host name or IP of the host to connect to |
| grpc_port | [int32](#int32) | | Grpc port to connect to |
| token | [string](#string) | | Shared secrect between the server and client |
| metrics | [string](#string) | | Metrics server name |
| command | [string](#string) | | Command server name |
| backoff | [Backoff](#f5-nginx-agent-sdk-Backoff) | | Backoff settings for exponential retry and backoff |








Expand Down
191 changes: 157 additions & 34 deletions go.mod

Large diffs are not rendered by default.

464 changes: 391 additions & 73 deletions go.sum

Large diffs are not rendered by default.

334 changes: 322 additions & 12 deletions go.work.sum

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions hugo/content/technical-specifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Alpine Linux
- 3.14 (x86_64, aarch64)
- 3.15 (x86_64, aarch64)
- 3.16 (x86_64, aarch64)
- 3.17 (x86_64, aarch64)

Amazon Linux 2
- LTS (x86_64, aarch64)
Expand All @@ -39,12 +40,13 @@ FreeBSD

Oracle Linux
- 7.4+ (x86_64)
- 8.1+ (x86_64, aarch64)
- 8.1+ (x86_64)
- 9 (x86_64)

Red Hat Enterprise Linux (RHEL)
- 7.4+ (x86_64)
- 8.1+ (x86_64)
- 9.0+ (x86_64)
- 7.4+ (x86_64, aarch64)
- 8.1+ (x86_64, aarch64)
- 9.0+ (x86_64, aarch64)

Rocky Linux
- 8 (x86_64, aarch64)
Expand Down
8 changes: 4 additions & 4 deletions nginx-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#
# Configuration file for NGINX Agent.
#
# This file is to track agent configuration values that are meant to be statically set. There
# are additional agent configuration values that are set via the API and agent install script
# This file is to track NGINX Agent configuration values that are meant to be statically set. There
# are additional NGINX Agent configuration values that are set via the API and NGINX Agent install script
# which can be found in /var/lib/nginx-agent/agent-dynamic.conf.

log:
Expand All @@ -20,7 +20,7 @@ nginx:

dataplane:
status:
# poll interval for data plane status - the frequency the agent will query the dataplane for changes
# poll interval for data plane status - the frequency the NGINX Agent will query the dataplane for changes
poll_interval: 30s
# report interval for data plane status - the maximum duration to wait before syncing dataplane information if no updates have being observed
report_interval: 24h
Expand All @@ -37,5 +37,5 @@ metrics:
config_dirs: "/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules:/etc/nms"

api:
# default port for Agent API, this is for the server configuration of the REST API
# default port for NGINX Agent API, this is for the server configuration of the REST API
port: 8081
2 changes: 1 addition & 1 deletion scripts/packages/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: nginx-agent
version: "${VERSION}"
origin: www/nginx-agent
comment: "Monitors NGINX"
desc: "Unified agent for various NGINX control plane services."
desc: "NGINX Agent for various NGINX control plane services."
maintainer: "NGINX Inc. <[email protected]>"
www: https://nginx.com
prefix: /
9 changes: 4 additions & 5 deletions scripts/packages/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ add_default_config_file() {
#
# Configuration file for NGINX Agent.
#
# This file is to track agent configuration values that are meant to be statically set. There
# are additional agent configuration values that are set via the API and agent install script
# This file is to track NGINX Agent configuration values that are meant to be statically set. There
# are additional NGINX Agent configuration values that are set via the API and NGINX Agent install script
# which can be found in /var/lib/nginx-agent/agent-dynamic.conf.
# specify the server grpc port to connect to
Expand Down Expand Up @@ -224,7 +224,7 @@ nginx:
dataplane:
status:
# poll interval for data plane status - the frequency the agent will query the dataplane for changes
# poll interval for data plane status - the frequency the NGINX Agent will query the dataplane for changes
poll_interval: 30s
# report interval for data plane status - the maximum duration to wait before syncing dataplane information if no updates have being observed
report_interval: 24h
Expand All @@ -241,7 +241,7 @@ metrics:
config_dirs: "/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules:/etc/nms"
api:
# default port for Agent API, this is for the server configuration of the REST API
# default port for NGINX Agent API, this is for the server configuration of the REST API
port: 8081
EOF
printf "PostInstall: Updating file permissions for nginx-agent.conf to 0640\n"
Expand Down Expand Up @@ -303,4 +303,3 @@ summary() {
upgrade_config_file
summary
}

10 changes: 0 additions & 10 deletions scripts/packages/postremove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@ if [ "$ID" = "freebsd" ]; then
echo "Stop and remove nginx-agent service"
service nginx-agent onestop >/dev/null 2>&1 || true
sysrc -x nginx_agent_enable >/dev/null 2>&1 || true
echo "Removing /usr/local/etc/nginx-agent directory"
rm -rf "/usr/local/etc/nginx-agent"
echo "Removing /var/db/nginx-agent directory"
rm -rf "/var/db/nginx-agent"
elif command -V systemctl >/dev/null 2>&1; then
echo "Stop and disable nginx-agent service"
systemctl stop nginx-agent >/dev/null 2>&1 || true
systemctl disable nginx-agent >/dev/null 2>&1 || true
echo "Running daemon-reload"
systemctl daemon-reload || true
echo "Removing /etc/nginx-agent directory"
rm -rf "/etc/nginx-agent"
echo "Removing /var/lib/nginx-agent directory"
rm -rf "/var/lib/nginx-agent"
fi

echo "Removing /var/run/nginx-agent directory"
rm -rf "/var/run/nginx-agent"
echo "Removing /var/log/nginx-agent directory"
rm -rf "/var/log/nginx-agent"
14 changes: 6 additions & 8 deletions scripts/packages/preinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ AGENT_DYNAMIC_CONFIG_COMMENT="#
#
# Dynamic configuration file for NGINX Agent.
#
# The purpose of this file is to track agent configuration
# values that can be dynamically changed via the API and the agent install script.
# The purpose of this file is to track NGINX Agent configuration
# values that can be dynamically changed via the API and the NGINX Agent install script.
# You may edit this file, but API calls that modify the tags on this system will
# overwrite the tag values in this file.
#
# The agent configuration values that API calls can modify are as follows:
# The NGINX Agent configuration values that API calls can modify are as follows:
# - tags
#
# The agent configuration value(s) that the agent install script can modify are as follows:
# The NGINX Agent configuration value(s) that the NGINX Agent install script can modify are as follows:
# - instance_group
"
Expand All @@ -67,8 +67,6 @@ err_exit() {

title() {
printf "\n --- NGINX Agent Package Installer --- \n\n"
printf " --- Will install the NGINX Agent in 5 seconds ---\n"
sleep 5
}

ensure_sudo() {
Expand Down Expand Up @@ -109,7 +107,7 @@ update_config_file() {
printf "Updating %s ...\n" "${AGENT_DYNAMIC_CONFIG_FILE}"

if [ ! -f "$AGENT_CONFIG_FILE" ]; then
printf "Agent config file %s does not exist. Could not be updated\n" "$AGENT_CONFIG_FILE"
printf "NGINX Agent config file %s does not exist. Could not be updated\n" "$AGENT_CONFIG_FILE"
exit 0
fi

Expand Down Expand Up @@ -160,4 +158,4 @@ update_config_file() {
ensure_sudo
load_config_values
update_config_file
}
}
4 changes: 2 additions & 2 deletions scripts/selinux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ sudo ./nginx_agent.sh --update

## Debugging
* To check for policy violation look at the file `/var/log/audit/audit.log`
* To check if agent is confined by selinux: `ps -efZ | grep nginx-agent`
* To check if NGINX Agent is confined by selinux: `ps -efZ | grep nginx-agent`
* For debugging nginx selinux issues refer to this nginx blog: https://www.nginx.com/blog/using-nginx-plus-with-selinux

## References
* https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/writing-a-custom-selinux-policy_using-selinux
* https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/writing-a-custom-selinux-policy_using-selinux
1 change: 1 addition & 0 deletions scripts/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ import (
_ "github.com/bufbuild/buf/cmd/buf"
_ "github.com/goreleaser/nfpm/v2/cmd/nfpm"
_ "github.com/evilmartians/lefthook"
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
)
24 changes: 15 additions & 9 deletions sdk/backoff.go → sdk/backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

package sdk
package backoff

import (
"context"
Expand All @@ -19,19 +19,25 @@ const (
BACKOFF_MULTIPLIER = backoff.DefaultMultiplier
)

type BackoffSettings struct {
InitialInterval time.Duration
MaxInterval time.Duration
MaxElapsedTime time.Duration
Multiplier float64
Jitter float64
}

func WaitUntil(
ctx context.Context,
initialInterval time.Duration,
maxInterval time.Duration,
maxElapsedTime time.Duration,
backoffSettings BackoffSettings,
operation backoff.Operation,
) error {
exponentialBackoff := backoff.NewExponentialBackOff()
exponentialBackoff.InitialInterval = initialInterval
exponentialBackoff.MaxInterval = maxInterval
exponentialBackoff.MaxElapsedTime = maxElapsedTime
exponentialBackoff.RandomizationFactor = BACKOFF_JITTER
exponentialBackoff.Multiplier = BACKOFF_MULTIPLIER
exponentialBackoff.InitialInterval = backoffSettings.InitialInterval
exponentialBackoff.MaxInterval = backoffSettings.MaxInterval
exponentialBackoff.MaxElapsedTime = backoffSettings.MaxElapsedTime
exponentialBackoff.RandomizationFactor = backoffSettings.Jitter
exponentialBackoff.Multiplier = backoffSettings.Multiplier

expoBackoffWithContext := backoff.WithContext(exponentialBackoff, ctx)

Expand Down
11 changes: 9 additions & 2 deletions sdk/backoff_test.go → sdk/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

package sdk
package backoff

import (
"context"
Expand Down Expand Up @@ -87,7 +87,14 @@ func TestBackOff(t *testing.T) {
}

for _, test := range tests {
result := WaitUntil(test.context, test.initialInterval, test.maxInterval, test.maxElapsedTime, test.operation)
backoff := BackoffSettings{
InitialInterval: test.initialInterval,
MaxInterval: test.maxInterval,
MaxElapsedTime: test.maxElapsedTime,
Jitter: BACKOFF_JITTER,
Multiplier: BACKOFF_MULTIPLIER,
}
result := WaitUntil(test.context, backoff, test.operation)

if test.expectedError {
assert.Errorf(t, result, test.name)
Expand Down
21 changes: 8 additions & 13 deletions sdk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ import (

"google.golang.org/grpc"

"github.com/nginx/agent/sdk/v2/backoff"
"github.com/nginx/agent/sdk/v2/interceptors"
"github.com/nginx/agent/sdk/v2/proto"
)

type BackoffSettings struct {
initialInterval time.Duration
maxInterval time.Duration
maxTimeout time.Duration
sendMaxTimeout time.Duration
}

type MsgClassification int

const (
Expand All @@ -35,11 +29,12 @@ const (
)

var (
DefaultBackoffSettings = BackoffSettings{
initialInterval: 10 * time.Second,
maxInterval: 60 * time.Second,
maxTimeout: 0,
sendMaxTimeout: 2 * time.Minute,
DefaultBackoffSettings = backoff.BackoffSettings{
InitialInterval: 10 * time.Second,
MaxInterval: 60 * time.Second,
MaxElapsedTime: 2 * time.Minute,
Jitter: backoff.BACKOFF_JITTER,
Multiplier: backoff.BACKOFF_MULTIPLIER,
}
)

Expand Down Expand Up @@ -68,7 +63,7 @@ type (
WithInterceptor(interceptor interceptors.Interceptor) Client
WithClientInterceptor(interceptor interceptors.ClientInterceptor) Client

WithBackoffSettings(backoffSettings BackoffSettings) Client
WithBackoffSettings(backoffSettings backoff.BackoffSettings) Client
}
MetricReporter interface {
Client
Expand Down
Loading

0 comments on commit 3d2435d

Please sign in to comment.