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 debug binary to the docker image #3686

Merged
merged 2 commits into from
Feb 11, 2019
Merged

Conversation

alexkursell
Copy link
Contributor

What this PR does / why we need it:
This PR adds a command-line tool to the image, /dbg, that can inspect various parts of the nginx configuration, including the dynamic parts used by lua. This should make it easier to debug problems to do with the generated configuration.

Right now, it can query the /configuration/backends and /configuration/general endpoints and display the result. In the case of the backend endpoint, it can also filter the output by backend name. It also includes a subcommand that essentially performs cat /etc/nginx/nginx.conf just to save on typing.

In the future, I'd also like to add the ability to inspect the dynamically loaded SSL keys that are also managed by lua, as well as anything else that makes debugging easier.

Which issue this PR fixes : Addresses #3679

cc: @ElvinEfendi

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 21, 2019
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please email the CNCF helpdesk: [email protected]

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jan 21, 2019
@alexkursell
Copy link
Contributor Author

I've signed the CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 22, 2019
Copy link

@diazjf diazjf left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. it would be very useful.

Still needs:

  • unit tests
  • documentation on usage

cmd/dbg/main.go Outdated

func backends() {
//Get the backend information from the nginx instance
body, requestErr := makeRequest("http://127.0.0.1:18080/configuration/backends")
Copy link

Choose a reason for hiding this comment

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

Instead of http://127.0.0.1:18080/configuration/backends being hardcoded here, it can be a global variable.

Also 18080 should be obtained be user configurable.

cmd/dbg/main.go Outdated
}

func backendsList() {
body, requestErr := makeRequest("http://127.0.0.1:18080/configuration/backends")
Copy link

Choose a reason for hiding this comment

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

Instead of http://127.0.0.1:18080/configuration/backends being hardcoded here, it can be a global variable.

Also 18080 should be obtained be user configurable.

cmd/dbg/main.go Outdated
}

func backendsGet(name string) {
body, requestErr := makeRequest("http://127.0.0.1:18080/configuration/backends")
Copy link

Choose a reason for hiding this comment

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

Instead of http://127.0.0.1:18080/configuration/backends being hardcoded here, it can be a global variable.

Also 18080 should be obtained be user configurable.

cmd/dbg/main.go Outdated

func general() {
//Get the other (general) information from the nginx instance
body, requestErr := makeRequest("http://127.0.0.1:18080/configuration/general")
Copy link

Choose a reason for hiding this comment

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

Instead of http://127.0.0.1:18080/configuration/general being hardcoded here, it can be a global variable.

Also 18080 should be obtained be user configurable.

cmd/dbg/main.go Outdated
fmt.Println(err)
return nil, err
}
defer resp.Body.Close()
Copy link

Choose a reason for hiding this comment

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

You should begin with the defer. Defer is always be triggered when a function ends.

cmd/dbg/main.go Outdated
fmt.Println(err)
return
}
defer confFile.Close()
Copy link

Choose a reason for hiding this comment

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

You should begin with the defer. Defer is always be triggered when a function ends.

@aledbf aledbf added the do-not-merge/blocked-paths Indicates that a PR should not merge because it touches files in blocked paths. label Jan 30, 2019
@aledbf
Copy link
Member

aledbf commented Jan 30, 2019

@alexkursell just in case, I am removing the server listening on port 18080 in #3684

@ElvinEfendi
Copy link
Member

@alexkursell let's use a proper cli library instead: https://github.com/spf13/cobra seems to be the one in k8s realm.

I am removing the server listening on port 18080 in #3684

As long as we have got the right abstraction here, the change should not be an issue. So this is not a blocker.

@@ -214,6 +214,19 @@ func (f *Framework) NginxLogs() (string, error) {
return nginxLogs(f.KubeClientSet, f.IngressController.Namespace)
}

// PodCommand executes any command inside the nginx pod
func (f *Framework) PodCommand(cmd string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

there's already a function to do this: ExecIngressPod

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 1, 2019
@alexkursell alexkursell force-pushed the dbg-tool branch 2 times, most recently from 5661b43 to f1daec2 Compare February 6, 2019 22:05
@aledbf
Copy link
Member

aledbf commented Feb 6, 2019

@alexkursell there is something wrong with this PR. If you need to add new dependencies, you need to run something like

rm -rf images/grpc-fortune-teller/
make dep-ensure

to avoid adding the grpc-fortune-teller dependencies.
Then, before committing the changes, restore images/grpc-fortune-teller/.

Also, usually we squash the commit, using one for the code changes and another for the changes in the vendor directory

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 7, 2019
cmd/dbg/main.go Outdated
fmt.Print(string(contents))
}

func makeConfigRequest(path string) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

cmd/dbg/main.go Show resolved Hide resolved
@aledbf aledbf removed the do-not-merge/blocked-paths Indicates that a PR should not merge because it touches files in blocked paths. label Feb 7, 2019
@aledbf
Copy link
Member

aledbf commented Feb 7, 2019

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 7, 2019
@aledbf
Copy link
Member

aledbf commented Feb 7, 2019

deferring lgtm to @ElvinEfendi

cmd/dbg/main.go Outdated
"os"
)

var (
Copy link
Member

Choose a reason for hiding this comment

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

these are const, not var

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

@ElvinEfendi
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 11, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, alexkursell, ElvinEfendi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ElvinEfendi
Copy link
Member

closes #3679

@k8s-ci-robot k8s-ci-robot merged commit 9ba6799 into kubernetes:master Feb 11, 2019
@ElvinEfendi ElvinEfendi deleted the dbg-tool branch February 11, 2019 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants