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

Add a config endpoint on a new api server #21025

Merged
merged 33 commits into from
Dec 5, 2023
Merged

Conversation

pgimalac
Copy link
Member

@pgimalac pgimalac commented Nov 22, 2023

What does this PR do?

Add a config endpoint to query config values on a new api server (on a new host and port).

Motivation

Eventually allow synchronizing config values (which can be dynamic with RC) across agent processes.

Additional Notes

The new server is on a different host and port than the existing cmd api server, which means we have to create an entirely new http server.
The security of the server is the same as the one of the usual API server.
I renamed a few functions to factor both servers and make the difference clearer.

I used the same cert for both servers, but we can easily refactor it to use separate ones, it might be better if we want both servers to be completely separate.

Possible Drawbacks / Trade-offs

Describe how to test/QA your changes

Enable the endpoint by setting a non zero value to agent_ipc_port (eg. 5004).
Check that the original API server still works, and that the new api server works properly to fetch api_key.
Only api_key is allowed to be queried as of now, so check that anything else returns an error.

The following command queries the endpoint from CLI:

curl -qs -H "authorization: Bearer $(cat <auth_token path>)" -k https://localhost:5004/config/v1/api_key

Check that expvars are properly filled, either with flare or with the endpoint directly:

curl -s http://localhost:5000/debug/vars | jq '.core_config_endpoint'

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • Use the major_change label if your change either has a major impact on the code base, is impacting multiple teams or is changing important well-established internals of the Agent. This label will be use during QA to make sure each team pay extra attention to the changed behavior. For any customer facing change use a releasenote.
  • A release note has been added or the changelog/no-changelog label has been applied.
  • Changed code has automated tests for its functionality.
  • Adequate QA/testing plan information is provided if the qa/skip-qa label is not applied.
  • At least one team/.. label has been applied, indicating the team(s) that should QA this change.
  • If applicable, docs team has been notified or an issue has been opened on the documentation repo.
  • If applicable, the need-change/operator and need-change/helm labels have been applied.
  • If applicable, the k8s/<min-version> label, indicating the lowest Kubernetes version compatible with this feature.
  • If applicable, the config template has been updated.

@pr-commenter
Copy link

pr-commenter bot commented Nov 22, 2023

Bloop Bleep... Dogbot Here

Regression Detector Results

Run ID: cdc6290e-71b5-4624-87c4-314d290a4a33
Baseline: c58efae
Comparison: fde8155
Total CPUs: 7

Explanation

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

No interesting changes in experiment optimization goals with confidence ≥ 90.00% and |Δ mean %| ≥ 5.00%.

Experiments that were not declared erratic but were detected as being so, coefficient of variation cutoff 0.10:

experiment goal Δ mean % Δ mean % CI confidence
otel_to_otel_logs ingress throughput +0.68 [-0.93, +2.28] 51.22%

Experiments where analysis encountered missing or malformed data:

dogstatsd_string_interner_128MiB_100
dogstatsd_string_interner_128MiB_1k
dogstatsd_string_interner_64MiB_1k
dogstatsd_string_interner_8MiB_100
dogstatsd_string_interner_8MiB_10k
dogstatsd_string_interner_8MiB_1k
dogstatsd_string_interner_8MiB_50k
file_to_blackhole
idle
tcp_dd_logs_filter_exclude
tcp_syslog_to_blackhole
uds_dogstatsd_to_api

Usually, this warning means that there is no usable optimization goal data for that experiment, which could be a result of misconfiguration.

Fine details of change detection per experiment.

experiment goal Δ mean % Δ mean % CI confidence
otel_to_otel_logs ingress throughput +0.68 [-0.93, +2.28] 51.22%
trace_agent_msgpack ingress throughput +0.02 [-0.11, +0.15] 20.94%
trace_agent_json ingress throughput +0.01 [-0.12, +0.15] 13.79%
dogstatsd_string_interner_8MiB_100k ingress throughput +0.00 [-0.08, +0.08] 3.37%
dogstatsd_string_interner_64MiB_100 ingress throughput -0.00 [-0.14, +0.14] 0.81%
file_tree egress throughput -0.10 [-1.91, +1.70] 7.47%

pkg/config/config.go Outdated Show resolved Hide resolved
cmd/agent/api/server_config.go Outdated Show resolved Hide resolved
cmd/agent/api/server_config.go Outdated Show resolved Hide resolved
cmd/agent/api/server.go Outdated Show resolved Hide resolved
@pgimalac pgimalac marked this pull request as ready for review November 27, 2023 10:26
@pgimalac pgimalac requested a review from a team as a code owner November 27, 2023 10:26
Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

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

Left some comments - seems like a reasonable change overall but given the impact more eyes on it can't hurt.

cmd/agent/api/security.go Outdated Show resolved Hide resolved
cmd/agent/api/security.go Outdated Show resolved Hide resolved
cmd/agent/api/security.go Show resolved Hide resolved
cmd/agent/api/server.go Outdated Show resolved Hide resolved
cmd/agent/api/server.go Outdated Show resolved Hide resolved
cmd/agent/api/server.go Outdated Show resolved Hide resolved
cmd/agent/api/server.go Outdated Show resolved Hide resolved
cmd/agent/api/server.go Outdated Show resolved Hide resolved
cmd/agent/api/server_ipc.go Outdated Show resolved Hide resolved
cmd/agent/api/server_cmd.go Outdated Show resolved Hide resolved
cmd/agent/api/security.go Show resolved Hide resolved
tlsListener := tls.NewListener(listener, srv.TLSConfig)
if apiConfigEnabled {
if err := startIPCServer(apiConfigHostPort, tlsConfig); err != nil {
StopServer()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to call StopServer when startIPCServer fail? Ideally when startIPCServer returns an error, startIPCServer should release any resources allocated if any.

Copy link
Member

Choose a reason for hiding this comment

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

Also, the fact that we are using global variables cmdListener and ipcConfigListener makes it more difficult to grok what is going on. Have you consider moving away from global variables and having server struct that holds cmdListener and ipcConfigListener information? That way, we could have functions like StopCMDServer and StopIPCServer , the same for startCMDServer and startIPCServer defined as part of the server struct

Copy link
Member

Choose a reason for hiding this comment

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

I know it was previously using var listener net.Listener but it might be a good opportunity to refactor such pattern 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

@ogaca-dd I need to call StopServer if startIPCServer fails because the other server was started beforehand, and needs to be stopped. I added some comments to make that clearer.

@GustavoCaso This would be implemented in the comp PR, in this one I try to avoid changing things I don't need to

Copy link
Member

@GustavoCaso GustavoCaso Nov 30, 2023

Choose a reason for hiding this comment

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

comp PR

You mean the API component PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the componentization of the API will likely remove these global variables

Comment on lines +103 to +107
apiAddr, tlsConfig, tlsCertPool,
configService, flare, dogstatsdServer,
capture, serverDebug, wmeta, logsAgent,
senderManager, hostMetadata, invAgent,
demux, invHost, secretResolver,
Copy link
Member

Choose a reason for hiding this comment

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

It may not be a convention in Go, but I see having too many parameters/arguments in a function as a code smell.

Maybe a suggestion for the CMD server could be its struct that we initialize and later call startServer or something. I also understand it might not be the right suggestion for this particular use case. At least we can start a conversation 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I definitely agree, IMO the API should at some point become a generic components others could register endpoints into, but this would be part of an eventual refactor of the API component

Copy link
Contributor

@Kaderinho Kaderinho Nov 30, 2023

Choose a reason for hiding this comment

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

FWIW, all these arguments will be removed in the near future as we'll embed them in the API Component directly (they will be injected to the API component through Fx)

See comment here:

// * StartServer args will be moved into the Component struct directly

Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

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

Just a few comments (mostly non-blocking)

cmd/agent/api/internal/config/endpoint_test.go Outdated Show resolved Hide resolved
cmd/agent/api/listener.go Outdated Show resolved Hide resolved
func initializeTLS() error {
cert, key := buildSelfSignedKeyPair()
func initializeTLS(additionalHostIdentities ...string) (*tls.Certificate, *x509.CertPool, error) {
log.Info("Initializing TLS certificates")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Related to the original comment around logging, it would be good to identify what TLS certificates we're initializing, probably by the caller ID/name so that we know the requestor of the cert. I know we print out the hosts with the name in securiity.go but that log line could be far away from this one in the output.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add that in a separate PR where we can discuss what kind of information we want around TLS initialization

pkg/api/security/security.go Outdated Show resolved Hide resolved
ctx, gwmux, tlsAddr, dopts)
if err != nil {
return fmt.Errorf("error registering agent handler from endpoint %s: %v", tlsAddr, err)
if err := util.CreateAndSetAuthToken(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any tests around the token validation on either the old server code or the new?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I know of, I'll open a separate PR to fix that (I would like to merge this one as it's blocking other PRs)

@pgimalac
Copy link
Member Author

pgimalac commented Dec 5, 2023

/merge

@dd-devflow
Copy link

dd-devflow bot commented Dec 5, 2023

🚂 MergeQueue

Pull request added to the queue.

This build is going to start soon! (estimated merge in less than 45m)

you can cancel this operation by commenting your pull request with /merge -c!

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

Successfully merging this pull request may close these issues.

6 participants