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

fixbug: Update commandName in RunAndEmitStats #3437

Conversation

albertorm95
Copy link
Contributor

@albertorm95 albertorm95 commented May 23, 2023

what

  • Use the CommandName.String() from the ctx instead of fixed string.

why

{
    "level": "error",
    "ts": "2023-05-23T10:35:45.772Z",
    "caller": "events/command_runner.go:429",
    "msg": "PANIC: descriptor Desc{fqName: \"atlantis_project_policy check_execution_time\", help: \"atlantis_project_policy check_execution_time summary\", constLabels: {}, variableLabels: [terraform_version workspace pr_number base_repo project project_path]} is invalid: \"atlantis_project_policy check_execution_time\" is not a valid metric name\ngithub.com/uber-go/[email protected]+incompatible/prometheus/reporter.go:306 (0xb02707)\ngithub.com/uber-go/[email protected]+incompatible/prometheus/reporter.go:554 (0xb02062)\ngithub.com/uber-go/[email protected]+incompatible/scope.go:363 (0x9e5787)\ngithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:66 (0xfa8e82)\ngithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:42 (0xfa86b4)\ngithub.com/runatlantis/atlantis/server/events/project_command_pool_executor.go:48 (0xfbf121)\ngithub.com/runatlantis/atlantis/server/events/policy_check_command_runner.go:65 (0xfb2107)\ngithub.com/runatlantis/atlantis/server/events/plan_command_runner.go:165 (0xfaf930)\ngithub.com/runatlantis/atlantis/server/events/plan_command_runner.go:288 (0xfb1304)\ngithub.com/runatlantis/atlantis/server/events/command_runner.go:174 (0xf94f8d)\nruntime/asm_amd64.s:1598 (0x46b2e0)\n",
    "json": {
        "repo": "foo",
        "pull": "1234"
    },
    "stacktrace": "github.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).logPanics\n\tgithub.com/runatlantis/atlantis/server/events/command_runner.go:429\nruntime.gopanic\n\truntime/panic.go:884\ngithub.com/uber-go/tally/prometheus.NewReporter.func1\n\tgithub.com/uber-go/[email protected]+incompatible/prometheus/reporter.go:306\ngithub.com/uber-go/tally/prometheus.(*reporter).AllocateTimer\n\tgithub.com/uber-go/[email protected]+incompatible/prometheus/reporter.go:554\ngithub.com/uber-go/tally.(*scope).Timer\n\tgithub.com/uber-go/[email protected]+incompatible/scope.go:363\ngithub.com/runatlantis/atlantis/server/events.RunAndEmitStats\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:66\ngithub.com/runatlantis/atlantis/server/events.(*InstrumentedProjectCommandRunner).PolicyCheck\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:42\ngithub.com/runatlantis/atlantis/server/events.runProjectCmds\n\tgithub.com/runatlantis/atlantis/server/events/project_command_pool_executor.go:48\ngithub.com/runatlantis/atlantis/server/events.(*PolicyCheckCommandRunner).Run\n\tgithub.com/runatlantis/atlantis/server/events/policy_check_command_runner.go:65\ngithub.com/runatlantis/atlantis/server/events.(*PlanCommandRunner).runAutoplan\n\tgithub.com/runatlantis/atlantis/server/events/plan_command_runner.go:165\ngithub.com/runatlantis/atlantis/server/events.(*PlanCommandRunner).Run\n\tgithub.com/runatlantis/atlantis/server/events/plan_command_runner.go:288\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunAutoplanCommand\n\tgithub.com/runatlantis/atlantis/server/events/command_runner.go:174"
}
  • The solution: instead of using a fixed string we re-use the ctx.CommandName.String() value that already have the correct command names,
    func (c Name) String() string {
    switch c {
    case Apply:
    return "apply"
    case Plan, Autoplan:
    return "plan"
    case Unlock:
    return "unlock"
    case PolicyCheck:
    return "policy_check"
    case ApprovePolicies:
    return "approve_policies"
    case Version:
    return "version"
    case Import:
    return "import"
    case State:
    return "state"
    }
    return ""
    }

tests

Debugging:
Before:
policy_check:
Screenshot 2023-05-23 at 3 44 18 PM

and then panic:
image

After:
plan:
Screenshot 2023-05-23 at 3 42 26 PM

policy_check
Screenshot 2023-05-23 at 3 42 44 PM

approve_policies
Screenshot 2023-05-23 at 3 39 40 PM

apply
Screenshot 2023-05-23 at 3 40 33 PM

state or state rm
Screenshot 2023-05-23 at 3 41 06 PM

Metrics:

Show Metrics
# HELP atlantis_api_getprojectjobs_execution_error atlantis_api_getprojectjobs_execution_error counter
# TYPE atlantis_api_getprojectjobs_execution_error counter
atlantis_api_getprojectjobs_execution_error 0
# HELP atlantis_api_getprojectjobs_execution_time atlantis_api_getprojectjobs_execution_time summary
# TYPE atlantis_api_getprojectjobs_execution_time summary
atlantis_api_getprojectjobs_execution_time{quantile="0.5"} 0.001327792
atlantis_api_getprojectjobs_execution_time{quantile="0.75"} 0.001327792
atlantis_api_getprojectjobs_execution_time{quantile="0.95"} 0.001327792
atlantis_api_getprojectjobs_execution_time{quantile="0.99"} 0.001327792
atlantis_api_getprojectjobs_execution_time{quantile="0.999"} 0.001327792
atlantis_api_getprojectjobs_execution_time_sum 0.001327792
atlantis_api_getprojectjobs_execution_time_count 1
# HELP atlantis_builder_execution_error atlantis_builder_execution_error counter
# TYPE atlantis_builder_execution_error counter
atlantis_builder_execution_error 0
# HELP atlantis_builder_execution_success atlantis_builder_execution_success counter
# TYPE atlantis_builder_execution_success counter
atlantis_builder_execution_success 3
# HELP atlantis_builder_execution_time atlantis_builder_execution_time summary
# TYPE atlantis_builder_execution_time summary
atlantis_builder_execution_time{quantile="0.5"} 0.273653083
atlantis_builder_execution_time{quantile="0.75"} 0.29153175
atlantis_builder_execution_time{quantile="0.95"} 0.29153175
atlantis_builder_execution_time{quantile="0.99"} 0.29153175
atlantis_builder_execution_time{quantile="0.999"} 0.29153175
atlantis_builder_execution_time_sum 0.6252524159999999
atlantis_builder_execution_time_count 3
# HELP atlantis_cmd_comment_apply_execution_time atlantis_cmd_comment_apply_execution_time summary
# TYPE atlantis_cmd_comment_apply_execution_time summary
atlantis_cmd_comment_apply_execution_time{quantile="0.5"} 3.660074417
atlantis_cmd_comment_apply_execution_time{quantile="0.75"} 3.660074417
atlantis_cmd_comment_apply_execution_time{quantile="0.95"} 3.660074417
atlantis_cmd_comment_apply_execution_time{quantile="0.99"} 3.660074417
atlantis_cmd_comment_apply_execution_time{quantile="0.999"} 3.660074417
atlantis_cmd_comment_apply_execution_time_sum 3.660074417
atlantis_cmd_comment_apply_execution_time_count 1
# HELP atlantis_cmd_comment_approve_policies_execution_time atlantis_cmd_comment_approve_policies_execution_time summary
# TYPE atlantis_cmd_comment_approve_policies_execution_time summary
atlantis_cmd_comment_approve_policies_execution_time{quantile="0.5"} 2.260303041
atlantis_cmd_comment_approve_policies_execution_time{quantile="0.75"} 2.260303041
atlantis_cmd_comment_approve_policies_execution_time{quantile="0.95"} 2.260303041
atlantis_cmd_comment_approve_policies_execution_time{quantile="0.99"} 2.260303041
atlantis_cmd_comment_approve_policies_execution_time{quantile="0.999"} 2.260303041
atlantis_cmd_comment_approve_policies_execution_time_sum 2.260303041
atlantis_cmd_comment_approve_policies_execution_time_count 1
# HELP atlantis_cmd_comment_plan_execution_time atlantis_cmd_comment_plan_execution_time summary
# TYPE atlantis_cmd_comment_plan_execution_time summary
atlantis_cmd_comment_plan_execution_time{quantile="0.5"} 8.784708625
atlantis_cmd_comment_plan_execution_time{quantile="0.75"} 8.784708625
atlantis_cmd_comment_plan_execution_time{quantile="0.95"} 8.784708625
atlantis_cmd_comment_plan_execution_time{quantile="0.99"} 8.784708625
atlantis_cmd_comment_plan_execution_time{quantile="0.999"} 8.784708625
atlantis_cmd_comment_plan_execution_time_sum 8.784708625
atlantis_cmd_comment_plan_execution_time_count 1
# HELP atlantis_cmd_comment_state_execution_time atlantis_cmd_comment_state_execution_time summary
# TYPE atlantis_cmd_comment_state_execution_time summary
atlantis_cmd_comment_state_execution_time{quantile="0.5"} 2.251546541
atlantis_cmd_comment_state_execution_time{quantile="0.75"} 2.251546541
atlantis_cmd_comment_state_execution_time{quantile="0.95"} 2.251546541
atlantis_cmd_comment_state_execution_time{quantile="0.99"} 2.251546541
atlantis_cmd_comment_state_execution_time{quantile="0.999"} 2.251546541
atlantis_cmd_comment_state_execution_time_sum 2.251546541
atlantis_cmd_comment_state_execution_time_count 1
# HELP atlantis_github_create_comment_execution_error atlantis_github_create_comment_execution_error counter
# TYPE atlantis_github_create_comment_execution_error counter
atlantis_github_create_comment_execution_error{base_repo="foo/repo",pr_number="7"} 0
# HELP atlantis_github_create_comment_execution_success atlantis_github_create_comment_execution_success counter
# TYPE atlantis_github_create_comment_execution_success counter
atlantis_github_create_comment_execution_success{base_repo="foo/repo",pr_number="7"} 5
# HELP atlantis_github_create_comment_execution_time atlantis_github_create_comment_execution_time summary
# TYPE atlantis_github_create_comment_execution_time summary
atlantis_github_create_comment_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.5"} 0.945310875
atlantis_github_create_comment_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.75"} 0.951462833
atlantis_github_create_comment_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.95"} 1.037311916
atlantis_github_create_comment_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.99"} 1.037311916
atlantis_github_create_comment_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.999"} 1.037311916
atlantis_github_create_comment_execution_time_sum{base_repo="foo/repo",pr_number="7"} 4.786881541
atlantis_github_create_comment_execution_time_count{base_repo="foo/repo",pr_number="7"} 5
# HELP atlantis_github_event_comment_created_success_200 atlantis_github_event_comment_created_success_200 counter
# TYPE atlantis_github_event_comment_created_success_200 counter
atlantis_github_event_comment_created_success_200{base_repo="foo/repo",pr_number="7"} 9
# HELP atlantis_github_get_modified_files_execution_error atlantis_github_get_modified_files_execution_error counter
# TYPE atlantis_github_get_modified_files_execution_error counter
atlantis_github_get_modified_files_execution_error{base_repo="foo/repo",pr_number="7"} 0
# HELP atlantis_github_get_modified_files_execution_success atlantis_github_get_modified_files_execution_success counter
# TYPE atlantis_github_get_modified_files_execution_success counter
atlantis_github_get_modified_files_execution_success{base_repo="foo/repo",pr_number="7"} 2
# HELP atlantis_github_get_modified_files_execution_time atlantis_github_get_modified_files_execution_time summary
# TYPE atlantis_github_get_modified_files_execution_time summary
atlantis_github_get_modified_files_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.5"} 0.237940792
atlantis_github_get_modified_files_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.75"} 0.238934292
atlantis_github_get_modified_files_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.95"} 0.238934292
atlantis_github_get_modified_files_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.99"} 0.238934292
atlantis_github_get_modified_files_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.999"} 0.238934292
atlantis_github_get_modified_files_execution_time_sum{base_repo="foo/repo",pr_number="7"} 0.476875084
atlantis_github_get_modified_files_execution_time_count{base_repo="foo/repo",pr_number="7"} 2
# HELP atlantis_github_get_pull_request_execution_error atlantis_github_get_pull_request_execution_error counter
# TYPE atlantis_github_get_pull_request_execution_error counter
atlantis_github_get_pull_request_execution_error{base_repo="foo/repo",pr_number="7"} 0
# HELP atlantis_github_get_pull_request_execution_success atlantis_github_get_pull_request_execution_success counter
# TYPE atlantis_github_get_pull_request_execution_success counter
atlantis_github_get_pull_request_execution_success{base_repo="foo/repo",pr_number="7"} 4
# HELP atlantis_github_get_pull_request_execution_time atlantis_github_get_pull_request_execution_time summary
# TYPE atlantis_github_get_pull_request_execution_time summary
atlantis_github_get_pull_request_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.5"} 0.372129292
atlantis_github_get_pull_request_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.75"} 0.398244209
atlantis_github_get_pull_request_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.95"} 0.495629083
atlantis_github_get_pull_request_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.99"} 0.495629083
atlantis_github_get_pull_request_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.999"} 0.495629083
atlantis_github_get_pull_request_execution_time_sum{base_repo="foo/repo",pr_number="7"} 1.626428251
atlantis_github_get_pull_request_execution_time_count{base_repo="foo/repo",pr_number="7"} 4
# HELP atlantis_github_pull_is_approved_execution_error atlantis_github_pull_is_approved_execution_error counter
# TYPE atlantis_github_pull_is_approved_execution_error counter
atlantis_github_pull_is_approved_execution_error{base_repo="foo/repo",pr_number="7"} 0
# HELP atlantis_github_pull_is_approved_execution_success atlantis_github_pull_is_approved_execution_success counter
# TYPE atlantis_github_pull_is_approved_execution_success counter
atlantis_github_pull_is_approved_execution_success{base_repo="foo/repo",pr_number="7"} 2
# HELP atlantis_github_pull_is_approved_execution_time atlantis_github_pull_is_approved_execution_time summary
# TYPE atlantis_github_pull_is_approved_execution_time summary
atlantis_github_pull_is_approved_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.5"} 0.410166625
atlantis_github_pull_is_approved_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.75"} 0.425089625
atlantis_github_pull_is_approved_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.95"} 0.425089625
atlantis_github_pull_is_approved_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.99"} 0.425089625
atlantis_github_pull_is_approved_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.999"} 0.425089625
atlantis_github_pull_is_approved_execution_time_sum{base_repo="foo/repo",pr_number="7"} 0.83525625
atlantis_github_pull_is_approved_execution_time_count{base_repo="foo/repo",pr_number="7"} 2
# HELP atlantis_github_pull_is_mergeable_execution_error atlantis_github_pull_is_mergeable_execution_error counter
# TYPE atlantis_github_pull_is_mergeable_execution_error counter
atlantis_github_pull_is_mergeable_execution_error{base_repo="foo/repo",pr_number="7"} 0
# HELP atlantis_github_pull_is_mergeable_execution_success atlantis_github_pull_is_mergeable_execution_success counter
# TYPE atlantis_github_pull_is_mergeable_execution_success counter
atlantis_github_pull_is_mergeable_execution_success{base_repo="foo/repo",pr_number="7"} 2
# HELP atlantis_github_pull_is_mergeable_execution_time atlantis_github_pull_is_mergeable_execution_time summary
# TYPE atlantis_github_pull_is_mergeable_execution_time summary
atlantis_github_pull_is_mergeable_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.5"} 0.346136334
atlantis_github_pull_is_mergeable_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.75"} 0.357433667
atlantis_github_pull_is_mergeable_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.95"} 0.357433667
atlantis_github_pull_is_mergeable_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.99"} 0.357433667
atlantis_github_pull_is_mergeable_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.999"} 0.357433667
atlantis_github_pull_is_mergeable_execution_time_sum{base_repo="foo/repo",pr_number="7"} 0.703570001
atlantis_github_pull_is_mergeable_execution_time_count{base_repo="foo/repo",pr_number="7"} 2
# HELP atlantis_github_react_to_comment_execution_error atlantis_github_react_to_comment_execution_error counter
# TYPE atlantis_github_react_to_comment_execution_error counter
atlantis_github_react_to_comment_execution_error 0
# HELP atlantis_github_react_to_comment_execution_success atlantis_github_react_to_comment_execution_success counter
# TYPE atlantis_github_react_to_comment_execution_success counter
atlantis_github_react_to_comment_execution_success 4
# HELP atlantis_github_react_to_comment_execution_time atlantis_github_react_to_comment_execution_time summary
# TYPE atlantis_github_react_to_comment_execution_time summary
atlantis_github_react_to_comment_execution_time{quantile="0.5"} 0.337575875
atlantis_github_react_to_comment_execution_time{quantile="0.75"} 0.340190375
atlantis_github_react_to_comment_execution_time{quantile="0.95"} 0.502541125
atlantis_github_react_to_comment_execution_time{quantile="0.99"} 0.502541125
atlantis_github_react_to_comment_execution_time{quantile="0.999"} 0.502541125
atlantis_github_react_to_comment_execution_time_sum 1.4956419589999999
atlantis_github_react_to_comment_execution_time_count 4
# HELP atlantis_github_update_status_execution_error atlantis_github_update_status_execution_error counter
# TYPE atlantis_github_update_status_execution_error counter
atlantis_github_update_status_execution_error{base_repo="foo/repo",pr_number="7"} 0
# HELP atlantis_github_update_status_execution_success atlantis_github_update_status_execution_success counter
# TYPE atlantis_github_update_status_execution_success counter
atlantis_github_update_status_execution_success{base_repo="foo/repo",pr_number="7"} 12
# HELP atlantis_github_update_status_execution_time atlantis_github_update_status_execution_time summary
# TYPE atlantis_github_update_status_execution_time summary
atlantis_github_update_status_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.5"} 0.3601065
atlantis_github_update_status_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.75"} 0.396579292
atlantis_github_update_status_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.95"} 0.516521125
atlantis_github_update_status_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.99"} 0.516521125
atlantis_github_update_status_execution_time{base_repo="foo/repo",pr_number="7",quantile="0.999"} 0.516521125
atlantis_github_update_status_execution_time_sum{base_repo="foo/repo",pr_number="7"} 4.520204251
atlantis_github_update_status_execution_time_count{base_repo="foo/repo",pr_number="7"} 12
# HELP atlantis_project_apply_execution_error atlantis_project_apply_execution_error counter
# TYPE atlantis_project_apply_execution_error counter
atlantis_project_apply_execution_error{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_apply_execution_failure atlantis_project_apply_execution_failure counter
# TYPE atlantis_project_apply_execution_failure counter
atlantis_project_apply_execution_failure{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_apply_execution_success atlantis_project_apply_execution_success counter
# TYPE atlantis_project_apply_execution_success counter
atlantis_project_apply_execution_success{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_apply_execution_time atlantis_project_apply_execution_time summary
# TYPE atlantis_project_apply_execution_time summary
atlantis_project_apply_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.5"} 0.859556167
atlantis_project_apply_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.75"} 0.859556167
atlantis_project_apply_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.95"} 0.859556167
atlantis_project_apply_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.99"} 0.859556167
atlantis_project_apply_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.999"} 0.859556167
atlantis_project_apply_execution_time_sum{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0.859556167
atlantis_project_apply_execution_time_count{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_approve_policies_execution_error atlantis_project_approve_policies_execution_error counter
# TYPE atlantis_project_approve_policies_execution_error counter
atlantis_project_approve_policies_execution_error{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_approve_policies_execution_failure atlantis_project_approve_policies_execution_failure counter
# TYPE atlantis_project_approve_policies_execution_failure counter
atlantis_project_approve_policies_execution_failure{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_approve_policies_execution_success atlantis_project_approve_policies_execution_success counter
# TYPE atlantis_project_approve_policies_execution_success counter
atlantis_project_approve_policies_execution_success{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_approve_policies_execution_time atlantis_project_approve_policies_execution_time summary
# TYPE atlantis_project_approve_policies_execution_time summary
atlantis_project_approve_policies_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.5"} 0.011936
atlantis_project_approve_policies_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.75"} 0.011936
atlantis_project_approve_policies_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.95"} 0.011936
atlantis_project_approve_policies_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.99"} 0.011936
atlantis_project_approve_policies_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.999"} 0.011936
atlantis_project_approve_policies_execution_time_sum{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0.011936
atlantis_project_approve_policies_execution_time_count{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_execution_error atlantis_project_execution_error counter
# TYPE atlantis_project_execution_error counter
atlantis_project_execution_error{base_repo="",pr_number="",project="",project_path="",terraform_version="",workspace=""} 0
# HELP atlantis_project_execution_failure atlantis_project_execution_failure counter
# TYPE atlantis_project_execution_failure counter
atlantis_project_execution_failure{base_repo="",pr_number="",project="",project_path="",terraform_version="",workspace=""} 0
# HELP atlantis_project_execution_success atlantis_project_execution_success counter
# TYPE atlantis_project_execution_success counter
atlantis_project_execution_success{base_repo="",pr_number="",project="",project_path="",terraform_version="",workspace=""} 0
# HELP atlantis_project_plan_execution_error atlantis_project_plan_execution_error counter
# TYPE atlantis_project_plan_execution_error counter
atlantis_project_plan_execution_error{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_plan_execution_failure atlantis_project_plan_execution_failure counter
# TYPE atlantis_project_plan_execution_failure counter
atlantis_project_plan_execution_failure{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_plan_execution_success atlantis_project_plan_execution_success counter
# TYPE atlantis_project_plan_execution_success counter
atlantis_project_plan_execution_success{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_plan_execution_time atlantis_project_plan_execution_time summary
# TYPE atlantis_project_plan_execution_time summary
atlantis_project_plan_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.5"} 1.521709416
atlantis_project_plan_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.75"} 1.521709416
atlantis_project_plan_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.95"} 1.521709416
atlantis_project_plan_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.99"} 1.521709416
atlantis_project_plan_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.999"} 1.521709416
atlantis_project_plan_execution_time_sum{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1.521709416
atlantis_project_plan_execution_time_count{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_policy_check_execution_error atlantis_project_policy_check_execution_error counter
# TYPE atlantis_project_policy_check_execution_error counter
atlantis_project_policy_check_execution_error{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_policy_check_execution_failure atlantis_project_policy_check_execution_failure counter
# TYPE atlantis_project_policy_check_execution_failure counter
atlantis_project_policy_check_execution_failure{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_policy_check_execution_success atlantis_project_policy_check_execution_success counter
# TYPE atlantis_project_policy_check_execution_success counter
atlantis_project_policy_check_execution_success{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_policy_check_execution_time atlantis_project_policy_check_execution_time summary
# TYPE atlantis_project_policy_check_execution_time summary
atlantis_project_policy_check_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.5"} 0.115006584
atlantis_project_policy_check_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.75"} 0.115006584
atlantis_project_policy_check_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.95"} 0.115006584
atlantis_project_policy_check_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.99"} 0.115006584
atlantis_project_policy_check_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.999"} 0.115006584
atlantis_project_policy_check_execution_time_sum{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0.115006584
atlantis_project_policy_check_execution_time_count{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_state_execution_error atlantis_project_state_execution_error counter
# TYPE atlantis_project_state_execution_error counter
atlantis_project_state_execution_error{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_state_execution_failure atlantis_project_state_execution_failure counter
# TYPE atlantis_project_state_execution_failure counter
atlantis_project_state_execution_failure{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0
# HELP atlantis_project_state_execution_success atlantis_project_state_execution_success counter
# TYPE atlantis_project_state_execution_success counter
atlantis_project_state_execution_success{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_project_state_execution_time atlantis_project_state_execution_time summary
# TYPE atlantis_project_state_execution_time summary
atlantis_project_state_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.5"} 0.622787375
atlantis_project_state_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.75"} 0.622787375
atlantis_project_state_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.95"} 0.622787375
atlantis_project_state_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.99"} 0.622787375
atlantis_project_state_execution_time{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default",quantile="0.999"} 0.622787375
atlantis_project_state_execution_time_sum{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 0.622787375
atlantis_project_state_execution_time_count{base_repo="foo/repo",pr_number="7",project="atlantis-example-live",project_path="example",terraform_version="1.3.4",workspace="default"} 1
# HELP atlantis_pullclosed_cleanup_execution_error atlantis_pullclosed_cleanup_execution_error counter
# TYPE atlantis_pullclosed_cleanup_execution_error counter
atlantis_pullclosed_cleanup_execution_error 0
# HELP atlantis_pullclosed_cleanup_execution_success atlantis_pullclosed_cleanup_execution_success counter
# TYPE atlantis_pullclosed_cleanup_execution_success counter
atlantis_pullclosed_cleanup_execution_success 0
# HELP atlantis_scheduled_runtime_cpu_cgo_calls atlantis_scheduled_runtime_cpu_cgo_calls gauge
# TYPE atlantis_scheduled_runtime_cpu_cgo_calls gauge
atlantis_scheduled_runtime_cpu_cgo_calls 0
# HELP atlantis_scheduled_runtime_cpu_goroutines atlantis_scheduled_runtime_cpu_goroutines gauge
# TYPE atlantis_scheduled_runtime_cpu_goroutines gauge
atlantis_scheduled_runtime_cpu_goroutines 19
# HELP atlantis_scheduled_runtime_memory_alloc atlantis_scheduled_runtime_memory_alloc gauge
# TYPE atlantis_scheduled_runtime_memory_alloc gauge
atlantis_scheduled_runtime_memory_alloc 9.707016e+06
# HELP atlantis_scheduled_runtime_memory_frees atlantis_scheduled_runtime_memory_frees gauge
# TYPE atlantis_scheduled_runtime_memory_frees gauge
atlantis_scheduled_runtime_memory_frees 79581
# HELP atlantis_scheduled_runtime_memory_gc_count atlantis_scheduled_runtime_memory_gc_count gauge
# TYPE atlantis_scheduled_runtime_memory_gc_count gauge
atlantis_scheduled_runtime_memory_gc_count 7
# HELP atlantis_scheduled_runtime_memory_gc_last atlantis_scheduled_runtime_memory_gc_last gauge
# TYPE atlantis_scheduled_runtime_memory_gc_last gauge
atlantis_scheduled_runtime_memory_gc_last 1.684849706485546e+18
# HELP atlantis_scheduled_runtime_memory_gc_next atlantis_scheduled_runtime_memory_gc_next gauge
# TYPE atlantis_scheduled_runtime_memory_gc_next gauge
atlantis_scheduled_runtime_memory_gc_next 1.6133696e+07
# HELP atlantis_scheduled_runtime_memory_gc_pause_total atlantis_scheduled_runtime_memory_gc_pause_total gauge
# TYPE atlantis_scheduled_runtime_memory_gc_pause_total gauge
atlantis_scheduled_runtime_memory_gc_pause_total 1.226333e+06
# HELP atlantis_scheduled_runtime_memory_gc_sys atlantis_scheduled_runtime_memory_gc_sys gauge
# TYPE atlantis_scheduled_runtime_memory_gc_sys gauge
atlantis_scheduled_runtime_memory_gc_sys 4.7154e+06
# HELP atlantis_scheduled_runtime_memory_heap_alloc atlantis_scheduled_runtime_memory_heap_alloc gauge
# TYPE atlantis_scheduled_runtime_memory_heap_alloc gauge
atlantis_scheduled_runtime_memory_heap_alloc 9.707016e+06
# HELP atlantis_scheduled_runtime_memory_heap_idle atlantis_scheduled_runtime_memory_heap_idle gauge
# TYPE atlantis_scheduled_runtime_memory_heap_idle gauge
atlantis_scheduled_runtime_memory_heap_idle 7.028736e+06
# HELP atlantis_scheduled_runtime_memory_heap_inuse atlantis_scheduled_runtime_memory_heap_inuse gauge
# TYPE atlantis_scheduled_runtime_memory_heap_inuse gauge
atlantis_scheduled_runtime_memory_heap_inuse 1.302528e+07
# HELP atlantis_scheduled_runtime_memory_heap_objects atlantis_scheduled_runtime_memory_heap_objects gauge
# TYPE atlantis_scheduled_runtime_memory_heap_objects gauge
atlantis_scheduled_runtime_memory_heap_objects 38741
# HELP atlantis_scheduled_runtime_memory_heap_released atlantis_scheduled_runtime_memory_heap_released gauge
# TYPE atlantis_scheduled_runtime_memory_heap_released gauge
atlantis_scheduled_runtime_memory_heap_released 2.99008e+06
# HELP atlantis_scheduled_runtime_memory_heap_sys atlantis_scheduled_runtime_memory_heap_sys gauge
# TYPE atlantis_scheduled_runtime_memory_heap_sys gauge
atlantis_scheduled_runtime_memory_heap_sys 2.0054016e+07
# HELP atlantis_scheduled_runtime_memory_lookups atlantis_scheduled_runtime_memory_lookups gauge
# TYPE atlantis_scheduled_runtime_memory_lookups gauge
atlantis_scheduled_runtime_memory_lookups 0
# HELP atlantis_scheduled_runtime_memory_malloc atlantis_scheduled_runtime_memory_malloc gauge
# TYPE atlantis_scheduled_runtime_memory_malloc gauge
atlantis_scheduled_runtime_memory_malloc 118322
# HELP atlantis_scheduled_runtime_memory_othersys atlantis_scheduled_runtime_memory_othersys gauge
# TYPE atlantis_scheduled_runtime_memory_othersys gauge
atlantis_scheduled_runtime_memory_othersys 1.689479e+06
# HELP atlantis_scheduled_runtime_memory_stack_inuse atlantis_scheduled_runtime_memory_stack_inuse gauge
# TYPE atlantis_scheduled_runtime_memory_stack_inuse gauge
atlantis_scheduled_runtime_memory_stack_inuse 917504
# HELP atlantis_scheduled_runtime_memory_stack_mcache_inuse atlantis_scheduled_runtime_memory_stack_mcache_inuse gauge
# TYPE atlantis_scheduled_runtime_memory_stack_mcache_inuse gauge
atlantis_scheduled_runtime_memory_stack_mcache_inuse 9600
# HELP atlantis_scheduled_runtime_memory_stack_mcache_sys atlantis_scheduled_runtime_memory_stack_mcache_sys gauge
# TYPE atlantis_scheduled_runtime_memory_stack_mcache_sys gauge
atlantis_scheduled_runtime_memory_stack_mcache_sys 15600
# HELP atlantis_scheduled_runtime_memory_stack_mspan_inuse atlantis_scheduled_runtime_memory_stack_mspan_inuse gauge
# TYPE atlantis_scheduled_runtime_memory_stack_mspan_inuse gauge
atlantis_scheduled_runtime_memory_stack_mspan_inuse 193760
# HELP atlantis_scheduled_runtime_memory_stack_sys atlantis_scheduled_runtime_memory_stack_sys gauge
# TYPE atlantis_scheduled_runtime_memory_stack_sys gauge
atlantis_scheduled_runtime_memory_stack_sys 195840
# HELP atlantis_scheduled_runtime_memory_sys atlantis_scheduled_runtime_memory_sys gauge
# TYPE atlantis_scheduled_runtime_memory_sys gauge
atlantis_scheduled_runtime_memory_sys 2.7593744e+07
# HELP atlantis_scheduled_runtime_memory_total atlantis_scheduled_runtime_memory_total gauge
# TYPE atlantis_scheduled_runtime_memory_total gauge
atlantis_scheduled_runtime_memory_total 2.3479704e+07

references

@albertorm95 albertorm95 requested a review from a team as a code owner May 23, 2023 11:46
@github-actions github-actions bot added the go Pull requests that update Go code label May 23, 2023
@@ -35,30 +35,31 @@ func NewInstrumentedProjectCommandRunner(scope tally.Scope, projectCommandRunner
}

func (p *InstrumentedProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult {
return RunAndEmitStats("plan", ctx, p.projectCommandRunner.Plan, p.scope)
return RunAndEmitStats(ctx, p.projectCommandRunner.Plan, p.scope)
Copy link
Member

Choose a reason for hiding this comment

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

Any chance of adding a unit or e2e test 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.

I didn't see this comment, let me check

Copy link
Contributor Author

@albertorm95 albertorm95 May 23, 2023

Choose a reason for hiding this comment

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

I don't know how to develop the test 🥺, is there a boilerplate or something I can use as guide, should I just look at other tests?

Copy link
Member

Choose a reason for hiding this comment

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

For now @albertorm95 , please look to other tests for examples.

https://github.com/runatlantis/atlantis/blob/23443a9262c3817d01f397636d4387ba4e392b41/server/events/import_command_runner_test.go

Then we can create server/events/instrumented_project_command_runner_test.go and then write a test that will test the output of the RunAndEmitStats function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working on 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.

@nitrocode I try to develop the code, but it looks like there is a lot of work to do in order to make that NewInstrumentedProjectCommandRunner or RunAndEmitStats testable, looks like I need to develop a mock? and then add it to the events.NewPlanCommandRunner() and same for apply, etc.., I don't feel confident enough to do this

The latest release is already failing because of this. What do you suggest to do in this case?

Copy link
Member

@nitrocode nitrocode May 23, 2023

Choose a reason for hiding this comment

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

I'm tempted to merge based on the above comments regarding testing and how you tested end to end.

cc: @GenPage @jamengual thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

@GenPage GenPage added waiting-on-response Waiting for a response from the user needs tests Change requires tests work-in-progress labels May 23, 2023
@GenPage GenPage added this to the v0.24.1 milestone May 23, 2023
@GenPage
Copy link
Member

GenPage commented May 23, 2023

This should fix #3439

@GenPage
Copy link
Member

GenPage commented May 23, 2023

@pseudomorph Can you test on your end before merging?

@pseudomorph
Copy link
Contributor

@GenPage - I don't have Prometheus set up. Perhaps @chriskuchin would be able to help test? Is there an image published for this change?

@chriskuchin
Copy link

My only running atlantis instance is the one my team uses. I might be able to roll a test image but if someone has a local setup the prometheus config would just require in the server side yaml. You won't actually need a prometheus server for it to trigger.

metrics:
  prometheus:
    endpoint: "/metrics"

@nitrocode
Copy link
Member

It's either we merge this or revert #3416. I'm OK with reverting and also OK with merging this. However, we could merge this and it results in another bad build whereas reverting will at least ensure a healthy build.

@nitrocode
Copy link
Member

Ok let's merge and hope for the best. If not, we can revert both prs

@nitrocode nitrocode merged commit 4a7fc33 into runatlantis:main May 24, 2023
@nitrocode
Copy link
Member

nitrocode commented May 24, 2023

A new image will be created after this is finished in 20 to 30 mins

https://github.com/runatlantis/atlantis/actions/runs/5063551272/jobs/9090284221

@albertorm95 (et al) once the job finishes, the following images will be available. Please give one a try in your setup and confirm it works. Then we can release 0.24.1.

  ghcr.io/runatlantis/atlantis:dev-alpine
  ghcr.io/runatlantis/atlantis:dev-alpine-4a7fc33
  ghcr.io/runatlantis/atlantis:dev

@albertorm95
Copy link
Contributor Author

albertorm95 commented May 24, 2023

A new image will be created after this is finished in 20 to 30 mins

https://github.com/runatlantis/atlantis/actions/runs/5063551272/jobs/9090284221

@albertorm95 (et al) once the job finishes, the following images will be available. Please give one a try in your setup and confirm it works. Then we can release 0.24.1.

  ghcr.io/runatlantis/atlantis:dev-alpine
  ghcr.io/runatlantis/atlantis:dev-alpine-4a7fc33
  ghcr.io/runatlantis/atlantis:dev

done

@albertorm95 albertorm95 deleted the bugfix-add-missing-command-name-in-metrics branch May 25, 2023 07:35
mtavaresmedeiros pushed a commit to mtavaresmedeiros/atlantis that referenced this pull request Jul 3, 2023
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code needs tests Change requires tests waiting-on-response Waiting for a response from the user work-in-progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants