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

[ASCII-1513] Add json flag to diagnose command #25010

Closed
wants to merge 15 commits into from

Conversation

louis-cqrl
Copy link
Contributor

What does this PR do?

This PR allow diagnose output in json format

Motivation

https://datadoghq.atlassian.net/browse/ASCII-325

Additional Notes

Possible Drawbacks / Trade-offs

Describe how to test/QA your changes

Run datadog-agent diagnose -j and datadog-agent diagnose --json
See if the output is a valid JSON
See if it contains the same information as datadog-agent diagnose -v

@pr-commenter
Copy link

pr-commenter bot commented Apr 23, 2024

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

inv create-vm --pipeline-id=32818544 --os-family=ubuntu

@louis-cqrl louis-cqrl marked this pull request as ready for review April 23, 2024 14:08
@louis-cqrl louis-cqrl requested review from a team as code owners April 23, 2024 14:08
cmd/agent/subcommands/diagnose/README.md Outdated Show resolved Hide resolved
cmd/agent/subcommands/diagnose/README.md Outdated Show resolved Hide resolved
Comment on lines 271 to 272
StatusCode: 400, // Hardcoded 400 status code since error is not nil
URL: url,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these necessary and sure we don't change an existing behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they are new field of diagnosis, they are not mandatory so it should not change anything

})
} else {
url, err := logshttp.CheckConnectivityDiagnose(endpoints.Main, config.Datadog)

name := fmt.Sprintf("Connectivity to %s", url)
diag := createDiagnosis(name, url, "", err)
diag := createDiagnosis("", 200, name, url, "", err) // Hardcoded 200 status code since error is nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we have any endpoint name to set here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the names seems to be the url so it is not needed

@pr-commenter
Copy link

pr-commenter bot commented Apr 23, 2024

Regression Detector

Regression Detector Results

Run ID: b6b57bcd-0ba1-4d0b-afb2-7192434dbebd
Baseline: 83daf1c
Comparison: bc894a1

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

No significant changes in experiment optimization goals

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

There were no significant changes in experiment optimization goals at this confidence level and effect size tolerance.

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI
file_to_blackhole % cpu utilization -19.37 [-24.45, -14.30]

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI
tcp_syslog_to_blackhole ingress throughput +10.87 [-11.42, +33.17]
pycheck_1000_100byte_tags % cpu utilization +0.79 [-3.86, +5.44]
process_agent_standard_check_with_stats memory utilization +0.54 [+0.48, +0.60]
basic_py_check % cpu utilization +0.41 [-2.11, +2.92]
trace_agent_msgpack ingress throughput +0.01 [-0.00, +0.02]
trace_agent_json ingress throughput +0.00 [-0.01, +0.01]
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.05, +0.04]
uds_dogstatsd_to_api ingress throughput -0.01 [-0.21, +0.19]
idle memory utilization -0.14 [-0.17, -0.11]
otel_to_otel_logs ingress throughput -0.21 [-0.59, +0.16]
process_agent_real_time_mode memory utilization -0.22 [-0.27, -0.18]
process_agent_standard_check memory utilization -0.32 [-0.38, -0.26]
uds_dogstatsd_to_api_cpu % cpu utilization -0.98 [-3.84, +1.88]
file_to_blackhole % cpu utilization -19.37 [-24.45, -14.30]

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".

cmd/agent/subcommands/diagnose/README.md Outdated Show resolved Hide resolved
cmd/agent/subcommands/diagnose/README.md Outdated Show resolved Hide resolved
louis-cqrl and others added 2 commits April 23, 2024 19:25
Co-authored-by: Ursula Chen <58821586+urseberry@users.noreply.github.com>
Co-authored-by: Ursula Chen <58821586+urseberry@users.noreply.github.com>
@louis-cqrl louis-cqrl requested review from urseberry and remeh April 23, 2024 17:26
Copy link
Contributor

@Kaderinho Kaderinho left a comment

Choose a reason for hiding this comment

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

The JSON part LGTM but I'm not sure about the fields you added tbh. If technically possible I would prefer these to be hidden behind an interface (so we don't need to add new fields for new type of diagnose)

@iglendd can we have your thoughts on this please since you designed that part 🙏

@@ -35,6 +35,7 @@ Flags:
-t, --list list diagnose suites
-l, --local force diagnose execution by the command line instead of the agent process (useful when troubleshooting privilege related problems)
-v, --verbose verbose output, includes passed diagnoses, and diagnoses description
-j, --json output in a json file
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ question: you mean format here (instead of file) ?‏

Copy link
Member

Choose a reason for hiding this comment

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

doc string from the code is output diagnosis results in JSON format. We should use the same for the doc,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hoooo yes good catch I'll modify it this evening

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Normally, internal diagnose functions run in the context of the Agent and other services. It can be overridden with –run-as-user options, and if specified, diagnose functions are executed in the context of the Agent diagnose CLI process if possible.

## ```json``` option
Normally, diagnose is displayed on stdout. If the JSON option is specified, the output is formatted as JSON
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 thought: ‏JSON is still printed on stdout right ? If yes, I don't think the first sentence is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it changed at the last minute to just display it on stdout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


diagnose, err := runDiagnose(w, diagCfg, deps)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ question: ‏are we sure that err is JSON formatted here ? (e.g. if I have an error when I run --json I might want a JSON output {"error": "..."})

Copy link
Contributor Author

@louis-cqrl louis-cqrl Apr 24, 2024

Choose a reason for hiding this comment

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

No this is not json formatted but I can do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried something but not sure it will work I let you check

@louis-cqrl
Copy link
Contributor Author

The JSON part LGTM but I'm not sure about the fields you added tbh. If technically possible I would prefer these to be hidden behind an interface (so we don't need to add new fields for new type of diagnose)

@iglendd can we have your thoughts on this please since you designed that part 🙏

I added it in the field of diagnosis cause it seems difficult to take back the informations through all different functions it goes

@louis-cqrl louis-cqrl requested a review from Kaderinho April 24, 2024 13:46
@@ -35,6 +35,7 @@ Flags:
-t, --list list diagnose suites
-l, --local force diagnose execution by the command line instead of the agent process (useful when troubleshooting privilege related problems)
-v, --verbose verbose output, includes passed diagnoses, and diagnoses description
-j, --json output in a json file
Copy link
Member

Choose a reason for hiding this comment

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

doc string from the code is output diagnosis results in JSON format. We should use the same for the doc,

Comment on lines 126 to 129
Name: name,
StatusCode: statusCode,
URL: logURL,
EndpointName: endpointName,
Copy link
Member

Choose a reason for hiding this comment

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

What's the different between Name and EndpointName ?

Copy link
Contributor Author

@louis-cqrl louis-cqrl Apr 24, 2024

Choose a reason for hiding this comment

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

Most of the time name is in this format:
"Connectivity to <endpoint url> (is Ok|failed)"
and endpointName is the name of the endpoint such as series_v2 flare etc

// endpoint URL
URL string
// Name of the endpoint
EndpointName string
Copy link
Member

Choose a reason for hiding this comment

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

If we already have a Name field, why do we need a EndpointName ? Also diagnose could be about anything, not just endpoint so we should avoid any specific field like URL, StatusCode or EndpointName.

In general, the --json option should show the exact same data than the regular version of the command but in a JSON format.

Copy link
Contributor Author

@louis-cqrl louis-cqrl Apr 24, 2024

Choose a reason for hiding this comment

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

If we want to use the field name we will need to refacto a bit diagnose code, since as I talked above name field is just uses to store a whole string that does not fit to what we want to display

louis-cqrl and others added 2 commits April 24, 2024 16:04
@louis-cqrl louis-cqrl requested a review from a team as a code owner April 26, 2024 06:34
louis-cqrl and others added 3 commits May 17, 2024 15:48
Co-authored-by: GustavoCaso <gustavo.caso@datadoghq.com>
* Remove SuiteDeps from ListStdOut

* Remove diagnose.Run in api component (Use either CLI or InProcess version)

* As `RunningInAgentProcess` is false, calling `getSuitesForCLIProcess` is equivalent to calling `getSuites`

* Simplify cluster agent diagnose command
Create RunStdOutAutodiscovery that runs only check "connectivity-datadog-autodiscovery"

* Remove diagnose.SuitesDeps from GetClusterAgentDiagnose

* Fix cmdDiagnose

* Remove `RunningInAgentProcess`

* Remove getDiagnose

* Inline some functions

* Add comment to improve API component

* Replace RunStdOutAutodiscovery by RunStdOutLocalCheck

* Improve code after merge from origin/main
@louis-cqrl louis-cqrl requested a review from a team as a code owner May 17, 2024 13:55
Copy link

Go Package Import Differences

Baseline: d73006c
Comparison: e9f6225

binaryosarchchange
agentlinuxamd64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
agentlinuxarm64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
agentwindowsamd64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
agentwindows386
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
agentdarwinamd64
+0, -6
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
-go4.org/mem
-hash/maphash
agentdarwinarm64
+0, -6
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
-go4.org/mem
-hash/maphash
iot-agentlinuxamd64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
iot-agentlinuxarm64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
heroku-agentlinuxamd64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
cluster-agentlinuxamd64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
cluster-agentlinuxarm64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
cluster-agent-cloudfoundrylinuxamd64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
cluster-agent-cloudfoundrylinuxarm64
+0, -4
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
security-agentlinuxamd64
+0, -11
-github.com/DataDog/agent-payload/v5/contimage
-github.com/DataDog/agent-payload/v5/contlcycle
-github.com/DataDog/agent-payload/v5/cyclonedx_v1_4
-github.com/DataDog/agent-payload/v5/sbom
-github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl
-github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver
-github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist
security-agentlinuxarm64
+0, -11
-github.com/DataDog/agent-payload/v5/contimage
-github.com/DataDog/agent-payload/v5/contlcycle
-github.com/DataDog/agent-payload/v5/cyclonedx_v1_4
-github.com/DataDog/agent-payload/v5/sbom
-github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl
-github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver
-github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl
-github.com/DataDog/datadog-agent/pkg/diagnose/connectivity
-github.com/DataDog/datadog-agent/pkg/diagnose/ports
-github.com/DataDog/datadog-agent/pkg/util/port
-github.com/DataDog/datadog-agent/pkg/util/port/portlist

@louis-cqrl louis-cqrl marked this pull request as draft June 11, 2024 08:18
@dd-devflow dd-devflow bot closed this Nov 17, 2024
@dd-devflow dd-devflow bot deleted the louis-cqrl/json-diagnose-file branch November 17, 2024 00:01
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.

7 participants