Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support periodic ping to principal for keeping connection alive #288

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jparsai
Copy link
Collaborator

@jparsai jparsai commented Feb 4, 2025

This PR is to introduce a configurable periodic ping to keep connection alive between agent and principal using grpc keepalive feature.

By default it is disabled and to enable it you need to set value of keep-alive-ping-interval in startup script or set env variable KEEP_ALIVE_PING_INTERVAL at agent side and at principal side you have to set value of wait-duration-for-agent-ping in startup script or set value of env variable WAIT_DURATION_FOR_AGENT_PING .

Fixes #171

@codecov-commenter
Copy link

codecov-commenter commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 2.17391% with 45 lines in your changes missing coverage. Please review.

Project coverage is 49.30%. Comparing base (bd7c4e3) to head (69c0e60).

Files with missing lines Patch % Lines
cmd/cmdutil/utils.go 0.00% 10 Missing ⚠️
cmd/agent/main.go 0.00% 9 Missing ⚠️
pkg/client/remote.go 10.00% 8 Missing and 1 partial ⚠️
cmd/principal/main.go 0.00% 8 Missing ⚠️
principal/options.go 0.00% 5 Missing ⚠️
principal/listen.go 0.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #288      +/-   ##
==========================================
- Coverage   49.65%   49.30%   -0.35%     
==========================================
  Files          73       74       +1     
  Lines        6404     6449      +45     
==========================================
  Hits         3180     3180              
- Misses       2959     3002      +43     
- Partials      265      267       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chetan-rns
Copy link
Collaborator

gRPC has support for configuring keepalives. Do you think we should use it?

https://grpc.io/docs/guides/keepalive/

@jparsai jparsai force-pushed the keep-alive branch 2 times, most recently from bf4a65d to 032b731 Compare February 13, 2025 12:14
@jparsai
Copy link
Collaborator Author

jparsai commented Feb 13, 2025

gRPC has support for configuring keepalives. Do you think we should use it?

https://grpc.io/docs/guides/keepalive/

@chetan-rns addressed your comment PTAL

@@ -176,6 +182,9 @@ func NewAgentRunCommand() *cobra.Command {
command.Flags().IntVar(&metricsPort, "metrics-port",
env.NumWithDefault("ARGOCD_AGENT_METRICS_PORT", cmd.ValidPort, 8181),
"Port the metrics server will listen on")
command.Flags().StringVar(&keepAlivePingInterval, "keep-alive-ping-interval",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cobra framework has flags that take duration strings as arguments (Duration, DurationVar, etc). Using these might remove the need for parsing the duration string yourself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it, but we have to parse for env variable. PTAL

Copy link
Collaborator

@jannfis jannfis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some comments, and a question: What exactly is the wait-duration-for-agent-ping doing, why does it need to be set?

"github.com/sirupsen/logrus"
)

func ParseKeepAlivePingInterval(interval string) time.Duration {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to make this function more generic and part of the internal/env package, so that it streamlines with the rest of the code base.

@@ -275,6 +280,9 @@ func NewPrincipalRunCommand() *cobra.Command {
command.Flags().BoolVar(&enableResourceProxy, "enable-resource-proxy",
env.BoolWithDefault("ARGOCD_PRINCIPAL_ENABLE_RESOURCE_PROXY", true),
"Whether to enable the resource proxy")
command.Flags().DurationVar(&waitDurationForAgentPing, "wait-duration-for-agent-ping",
cmdutil.ParseKeepAlivePingInterval(env.StringWithDefault("WAIT_DURATION_FOR_AGENT_PING", nil, "")),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think WAIT_DURATION_FOR_AGENT_PING is not a good name for the environment variable. PTAL at how the other environment variables that we use as arguments are named, and make this one align.

@@ -176,6 +183,9 @@ func NewAgentRunCommand() *cobra.Command {
command.Flags().IntVar(&metricsPort, "metrics-port",
env.NumWithDefault("ARGOCD_AGENT_METRICS_PORT", cmd.ValidPort, 8181),
"Port the metrics server will listen on")
command.Flags().DurationVar(&keepAlivePingInterval, "keep-alive-ping-interval",
cmdutil.ParseKeepAlivePingInterval(env.StringWithDefault("KEEP_ALIVE_PING_INTERVAL", nil, "")),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think KEEP_ALIVE_PING_INTERVAL is not a good name for the environment variable. PTAL at how the other environment variables that we use as arguments are named, and make this one align.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide configurable keep-alive interval for event stream
4 participants