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-1025] Render check output using status component #21881

Merged
merged 9 commits into from
Jan 6, 2024

Conversation

GustavoCaso
Copy link
Member

@GustavoCaso GustavoCaso commented Jan 5, 2024

What does this PR do?

Use the comp/core/status component to collect and render the output for the agent check subcommand.

We are slowly introducing the status component as the main component to handle the status for all agent flavors.

This PR changes:

  • Move all the helper methods for rendering Text and HTML to the status component. We also updated all the places where we previously used the pkg/status helper functions.
  • Create the collector status provider
  • Update the pkg/cli/subcommands/check/command.go to use the status component

Motivation

Additional Notes

Possible Drawbacks / Trade-offs

Describe how to test/QA your changes

  • Executing the check <checkName> command should work as expected.

    Steps to reproduce it:

    • Build the agent
    • Execute the check command ./bin/agent/agent check cpu -c dev/dist/datadog.yaml. Validate that the output is correct.
    • Execute the check command to return JSON ./bin/agent/agent check cpu --json -c dev/dist/datadog.yaml. Validate that the output is correct
  • Agent GUI

    • Build the agent
    • Execute the launch GUI command ./bin/agent/agent launch-gui -c dev/dist/datadog.yaml.
    • Navigate to the main page of the GUI. make sure the general and the collector status section are correct
  • Process agent

    • Build the process agent
    • Run /opt/datadog-agent/embedded/bin/process-agent status. Validate that the output is correct.

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. Except if the qa/skip-qa label, with required either qa/done or qa/no-code-change labels, are 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.

@GustavoCaso GustavoCaso force-pushed the render-check-output-using-status-component branch from c6cf8af to 89b001f Compare January 5, 2024 09:58
Copy link

cit-pr-commenter bot commented Jan 5, 2024

Go Package Import Differences

Baseline: b8ceee3
Comparison: e0ac5ce

binaryosarchchange
agentlinuxamd64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
agentlinuxarm64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
agentwindowsamd64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
agentwindows386
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
agentdarwinamd64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
agentdarwinarm64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
iot-agentlinuxamd64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
iot-agentlinuxarm64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
heroku-agentlinuxamd64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
cluster-agentlinuxamd64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
cluster-agentlinuxarm64
+2, -0
+github.com/DataDog/datadog-agent/comp/core/status
+github.com/DataDog/datadog-agent/comp/core/status/statusimpl
cluster-agent-cloudfoundrylinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
cluster-agent-cloudfoundrylinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
process-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
process-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
process-agentwindowsamd64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
process-agentdarwinamd64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
process-agentdarwinarm64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
heroku-process-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
security-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status
security-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/comp/core/status

@GustavoCaso GustavoCaso changed the title Render check output using status component [ASCII-1025] Render check output using status component Jan 5, 2024
@GustavoCaso GustavoCaso added this to the 7.51.0 milestone Jan 5, 2024
@GustavoCaso GustavoCaso marked this pull request as ready for review January 5, 2024 10:49
@GustavoCaso GustavoCaso requested review from a team as code owners January 5, 2024 10:49
@GustavoCaso GustavoCaso force-pushed the render-check-output-using-status-component branch from 6b52b7d to 7d485d9 Compare January 5, 2024 10:55
@pr-commenter
Copy link

pr-commenter bot commented Jan 5, 2024

Bloop Bleep... Dogbot Here

Regression Detector Results

Run ID: c544acb2-412a-44f6-8cfd-a25295d7f042
Baseline: dd9da68
Comparison: e0ac5ce
Total CPUs: 7

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
idle memory utilization +0.44 [+0.42, +0.47]
file_to_blackhole % cpu utilization -0.03 [-6.58, +6.51]
file_tree memory utilization -0.48 [-0.58, -0.39]

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI
otel_to_otel_logs ingress throughput +0.57 [-0.12, +1.26]
idle memory utilization +0.44 [+0.42, +0.47]
process_agent_real_time_mode memory utilization +0.18 [+0.14, +0.21]
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.06, +0.06]
uds_dogstatsd_to_api ingress throughput -0.00 [-0.03, +0.03]
process_agent_standard_check memory utilization -0.00 [-0.08, +0.07]
trace_agent_msgpack ingress throughput -0.02 [-0.04, -0.00]
file_to_blackhole % cpu utilization -0.03 [-6.58, +6.51]
trace_agent_json ingress throughput -0.05 [-0.08, -0.02]
process_agent_standard_check_with_stats memory utilization -0.06 [-0.13, +0.00]
file_tree memory utilization -0.48 [-0.58, -0.39]
tcp_syslog_to_blackhole ingress throughput -0.81 [-0.87, -0.74]

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

comp/core/status/render_helpers.go Outdated Show resolved Hide resolved
Comment on lines -40 to -41
"lastErrorTraceback": func(s string) htemplate.HTML { return doNotEscape(lastErrorTraceback(s)) },
"lastErrorMessage": func(s string) htemplate.HTML { return doNotEscape(lastErrorMessage(s)) },
Copy link
Member

Choose a reason for hiding this comment

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

Those two functions used to call doNotEscape, I don't think it's called in the new version ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Those functions were previously overwritten by the GUI (The only user of these functions)

https://github.com/DataDog/datadog-agent/pull/21881/files#diff-9383e04199c01250407664833b73220eddb920d02d521388fab568e0c6559247L24-L29

So, I replaced the functions with those ones. Also, the new functions effectively call the same functionality as doNotEscape

Copy link
Member Author

Choose a reason for hiding this comment

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

There is room for cleanup and improvement. Which I will do on subsequent PRs

Comment on lines 151 to 157
switch v := unixTime.(type) {
case int64:
return parseFunction(int64(v))
case float64:
return parseFunction(int64(v))
default:
return ""
Copy link
Member

Choose a reason for hiding this comment

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

💭 thought: ‏Instead of defining a parse function, you could just perform the cast at the start of the function

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 don't mind having the parsing function

pkg/cli/subcommands/check/command.go Outdated Show resolved Hide resolved
pkg/cli/subcommands/check/command.go Show resolved Hide resolved
Comment on lines 435 to 465
checkMap := make(map[checkid.ID]*stats.Stats)
checkMap[c.ID()] = s
var checkResult map[string]interface{}
resultBytes, err := json.Marshal(s)
if err != nil {
return err
}

err = json.Unmarshal(resultBytes, &checkResult)
if err != nil {
return err
}

checkMap := make(map[string]interface{})

checkMap[string(c.ID())] = checkResult
Copy link
Member

Choose a reason for hiding this comment

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

❓ question: ‏Why do you need to marshal and unmarshal instead of just adding the check stat in the map like before ?

Copy link
Member Author

@GustavoCaso GustavoCaso Jan 5, 2024

Choose a reason for hiding this comment

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

Previously marshall was happening here: https://github.com/DataDog/datadog-agent/pull/21881/files#diff-4a83275fbbf7764c4d251dde368ca784c146ed15c8b49dbc9946ecb0450e57b2L513 and the unmarshal was happening here:

stats, renderError, err := unmarshalStatus(data)
and that function was previously call here: https://github.com/DataDog/datadog-agent/pull/21881/files#diff-4a83275fbbf7764c4d251dde368ca784c146ed15c8b49dbc9946ecb0450e57b2L514

We need to transform *stats.Stats to a map[string]interface{} because the helper functions expect to have that signature:

{{ $version := version $CheckInstances }}

func getVersion(instances map[string]interface{}) string {
if len(instances) == 0 {
return ""
}
for _, instance := range instances {
instanceMap := instance.(map[string]interface{})
version, ok := instanceMap["CheckVersion"]
if !ok {
return ""
}
str, ok := version.(string)
if !ok {
return ""
}
return str
}
return ""

So we just moved the marshal and unmarshal to a different location.

pkg/status/collector/collector.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kkhor-datadog kkhor-datadog left a comment

Choose a reason for hiding this comment

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

Mind adding instructions for testing the process agent status? Similar to your previous PR: #20824

Copy link
Contributor

@dustmop dustmop left a comment

Choose a reason for hiding this comment

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

Two small nits

comp/core/status/render_helpers.go Outdated Show resolved Hide resolved
pkg/status/render/render.go Outdated Show resolved Hide resolved
@GustavoCaso GustavoCaso force-pushed the render-check-output-using-status-component branch from ff32f9e to e0ac5ce Compare January 5, 2024 18:05
@GustavoCaso
Copy link
Member Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Jan 6, 2024

🚂 MergeQueue

Pull request added to the queue.

This build is next! (estimated merge in less than 44m)

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

@dd-mergequeue dd-mergequeue bot merged commit 5c918b0 into main Jan 6, 2024
166 checks passed
@dd-mergequeue dd-mergequeue bot deleted the render-check-output-using-status-component branch January 6, 2024 00:57
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.

4 participants