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 smart diff to testutil.GatherAndCompare family of utilities. #996

Closed
bwplotka opened this issue Mar 4, 2022 · 1 comment · Fixed by #998
Closed

Add smart diff to testutil.GatherAndCompare family of utilities. #996

bwplotka opened this issue Mar 4, 2022 · 1 comment · Fixed by #998

Comments

@bwplotka
Copy link
Member

bwplotka commented Mar 4, 2022

Currently, it's much better to just use require.Equal from testify to compare outputs of scrape, since it gives nice diff:

0304 12:33:58.224133 4120671 server.go:406] "Adding debug handlers to kubelet server"
    server_test.go:1449: 
        	Error Trace:	server_test.go:1449
        	Error:      	Not equal: 
        	            	...
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -3648,3 +3648,3 @@
        	            	 container_processes{container="",id="/user.slice/user-1000.slice/[email protected]/session.slice/pulseaudio.service",image="",name="",namespace="",pod=""} 0 1645535816846
        	            	-# HELP container_scrape_error 1 if there was an error while getting container metrics, 0 otherwise.
        	            	+# HELP container_scrape_error 1 if there was an error while getting container metrics, 0 otherwise
        	            	 # TYPE container_scrape_error gauge
        	            	@@ -3939,3 +3939,3 @@
        	            	 container_spec_cpu_period{container="",id="/user.slice/user-1000.slice/[email protected]/session.slice/pulseaudio.service",image="",name="",namespace="",pod=""} 0
        	            	-# HELP container_spec_cpu_shares CPU share (limit) of the container.
        	            	+# HELP container_spec_cpu_shares CPU share of the container.
        	            	 # TYPE container_spec_cpu_shares gauge
        	Test:       	TestCadvisorMetrics

If I do this with our compare, it is huge unreadable blob without diff ): Just got, want. Let's improve experience here!

@sourikghosh
Copy link
Contributor

sourikghosh commented Mar 4, 2022

@bwplotka you want to change this compare func to use require.Equal

func compare(got, want []*dto.MetricFamily) error {

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

Successfully merging a pull request may close this issue.

2 participants