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 a flag to skip tests using Cloud Logging API #69

Merged
merged 7 commits into from
Feb 20, 2025

Conversation

Okabe-Junya
Copy link
Contributor

@Okabe-Junya Okabe-Junya commented Feb 14, 2025

close #57

Background

Currently, some tests that make API requests to Google Cloud resources cannot be executed, which prevents running Go unit tests in development environments and CI.
Therefore, we want to implement a flag to skip tests that requests to Google Cloud resources

What

  • Implement a flag (skip-cloud-logging) to skip tests that send API requests to Cloud Logging.
    • The flag is implemented in internal/testflags and is (blank-)imported in each test file.
    • Note: Since Go tests generate a binary for each package, be aware that without the blank import, running go test ./... -args -skip-cloud-logging=true will not work.

Usage

$ go test ./...  -args -skip-cloud-logging=true

Result

One of the tests is failing, but this error existed before working on this PR.

$ go test ./...  -args -skip-cloud-logging=true
result
?       github.com/GoogleCloudPlatform/khi/cmd/kubernetes-history-inspector     [no test files]
?       github.com/GoogleCloudPlatform/khi/internal/testflags   [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/common/constants [no test files]
ok      github.com/GoogleCloudPlatform/khi/pkg/common   0.201s
?       github.com/GoogleCloudPlatform/khi/pkg/common/worker    [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/inspection       [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/inspection/env   [no test files]
ok      github.com/GoogleCloudPlatform/khi/pkg/common/cache     1.126s
ok      github.com/GoogleCloudPlatform/khi/pkg/common/errorreport       0.848s
ok      github.com/GoogleCloudPlatform/khi/pkg/common/flag      0.500s
ok      github.com/GoogleCloudPlatform/khi/pkg/common/grouper   0.671s
ok      github.com/GoogleCloudPlatform/khi/pkg/common/httpclient        0.914s
ok      github.com/GoogleCloudPlatform/khi/pkg/common/parserutil        1.215s
?       github.com/GoogleCloudPlatform/khi/pkg/inspection/task  [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/inspection/task/serializer       [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/lifecycle        [no test files]
ok      github.com/GoogleCloudPlatform/khi/pkg/common/token     3.178s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/common        0.969s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/form  0.906s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/inspectiondata        0.658s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/ioconfig      0.998s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/logger        1.164s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/metadata      1.275s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/metadata/error        1.161s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/metadata/form 1.118s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/metadata/header       1.126s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/metadata/logger       0.995s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/metadata/plan 1.036s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/metadata/progress     3.525s
ok      github.com/GoogleCloudPlatform/khi/pkg/inspection/metadata/query        1.032s
ok      github.com/GoogleCloudPlatform/khi/pkg/log      0.990s
ok      github.com/GoogleCloudPlatform/khi/pkg/log/structure    0.998s
ok      github.com/GoogleCloudPlatform/khi/pkg/log/structure/adapter    1.028s
ok      github.com/GoogleCloudPlatform/khi/pkg/log/structure/merger     0.999s
ok      github.com/GoogleCloudPlatform/khi/pkg/log/structure/structuredata      1.212s
?       github.com/GoogleCloudPlatform/khi/pkg/parser   [no test files]
ok      github.com/GoogleCloudPlatform/khi/pkg/log/structure/structuredatastore 3.027s
ok      github.com/GoogleCloudPlatform/khi/pkg/model    1.280s
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/query [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gdcv-for-baremetal       [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gdcv-for-vmware  [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke      [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit    [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/k8saudittask       [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder   [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder/bindingrecorder   [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder/commonrecorder    [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder/noderecorder      [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder/ownerreferencerecorder    [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder/snegrecorder      [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder/statusrecorder    [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/types      [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke-on-aws       [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke-on-azure     [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/form    [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/gcp/api [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/gcp/api/httpclient      [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/inspection      [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/inspection/env  [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/metadata        [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/parser  [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/task    [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/testchangeset   [no test files]
?       github.com/GoogleCloudPlatform/khi/pkg/testutil/testtask        [no test files]
?       github.com/GoogleCloudPlatform/khi/scripts/frontend-codegen     [no test files]
ok      github.com/GoogleCloudPlatform/khi/pkg/model/binarychunk        34.106s
ok      github.com/GoogleCloudPlatform/khi/pkg/model/enum       1.266s
ok      github.com/GoogleCloudPlatform/khi/pkg/model/history    2.577s
ok      github.com/GoogleCloudPlatform/khi/pkg/model/history/grouper    0.895s
ok      github.com/GoogleCloudPlatform/khi/pkg/model/history/resourceinfo       1.018s [no tests to run]
ok      github.com/GoogleCloudPlatform/khi/pkg/model/history/resourceinfo/noderesource  1.125s
ok      github.com/GoogleCloudPlatform/khi/pkg/model/history/resourceinfo/resourcelease 0.974s
ok      github.com/GoogleCloudPlatform/khi/pkg/model/history/resourcepath       0.956s
ok      github.com/GoogleCloudPlatform/khi/pkg/model/k8s        0.505s
ok      github.com/GoogleCloudPlatform/khi/pkg/model/k8s/configsource   0.626s
ok      github.com/GoogleCloudPlatform/khi/pkg/parameters       0.748s
ok      github.com/GoogleCloudPlatform/khi/pkg/parser/k8s       0.797s
ok      github.com/GoogleCloudPlatform/khi/pkg/parser/yaml/yamlutil     0.908s
ok      github.com/GoogleCloudPlatform/khi/pkg/popup    5.058s
ok      github.com/GoogleCloudPlatform/khi/pkg/rawlogs  13.493s
global > WARN task VfdcFIqoMyQAzUWE was finished with an error
context canceled
errorend > ERROR test error
global > WARN task RFBGeLizvhiXeIBD was finished with an error
failed to run a task graph.
 definition ID=errorend got an error. 
 ERROR:
test error
--- FAIL: TestKHIServer_EndpointExistsWithConfigs (0.00s)
    --- FAIL: TestKHIServer_EndpointExistsWithConfigs/custom_server_base_path_on_non-viewer_mode (0.00s)
panic: open ../../dist/test.html: no such file or directory [recovered]
        panic: open ../../dist/test.html: no such file or directory

goroutine 192 [running]:
testing.tRunner.func1.2({0x1037520e0, 0x140004dfce0})
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/testing/testing.go:1632 +0x1bc
testing.tRunner.func1()
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/testing/testing.go:1635 +0x334
panic({0x1037520e0?, 0x140004dfce0?})
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/runtime/panic.go:785 +0x124
github.com/GoogleCloudPlatform/khi/pkg/testutil.MustPlaceTemporalFile({0x1033d0fb1, 0x14}, {0x0, 0x0})
        /Users/junyaokabe/src/github.com/Okabe-Junya/khi/pkg/testutil/io.go:75 +0xec
github.com/GoogleCloudPlatform/khi/pkg/server.TestKHIServer_EndpointExistsWithConfigs.func1(0x140001b36c0)
        /Users/junyaokabe/src/github.com/Okabe-Junya/khi/pkg/server/server_test.go:775 +0x90
testing.tRunner(0x140001b36c0, 0x140000a2540)
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/testing/testing.go:1690 +0xe4
created by testing.(*T).Run in goroutine 191
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/testing/testing.go:1743 +0x314
FAIL    github.com/GoogleCloudPlatform/khi/pkg/server   5.692s
ok      github.com/GoogleCloudPlatform/khi/pkg/server/config    0.309s
ok      github.com/GoogleCloudPlatform/khi/pkg/server/index     0.866s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp       0.933s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/api   1.110s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/api/accesstoken       1.051s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/api/quotaproject      0.795s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/k8s   0.599s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/log   0.743s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/query/queryutil       0.823s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task  0.388s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/cloud-composer   0.529s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/autoscaler   0.397s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/compute_api  0.561s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/gke_audit    0.910s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/manifestutil       0.827s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/query      0.698s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder/containerstatusrecorder   0.412s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/recorder/endpointslicerecorder     0.766s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/rtype      0.821s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/v2commonlogparse   0.426s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/v2logconvert       0.777s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/v2manifestgenerate 1.222s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_audit/v2timelinegrouping 1.435s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_container        1.502s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_control_plane_component  1.779s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_control_plane_component/componentparser  1.888s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_event    1.512s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/k8s_node     1.355s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/network_api  1.425s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/gke/serialport   1.489s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/multicloud_api   1.104s
ok      github.com/GoogleCloudPlatform/khi/pkg/source/gcp/task/onprem_api       1.558s
ok      github.com/GoogleCloudPlatform/khi/pkg/task     5.485s
ok      github.com/GoogleCloudPlatform/khi/pkg/task/taskid      1.737s
ok      github.com/GoogleCloudPlatform/khi/pkg/testutil 1.495s
ok      github.com/GoogleCloudPlatform/khi/pkg/testutil/gcp     2.926s
ok      github.com/GoogleCloudPlatform/khi/pkg/testutil/log     1.137s [no tests to run]
ok      github.com/GoogleCloudPlatform/khi/pkg/testutil/testlog 0.812s
FAIL

Next Steps

I will:

  • Update the Makefile and CI so that tests with the flag enabled can be easily executed
  • Update the developer documentation

@Okabe-Junya Okabe-Junya marked this pull request as ready for review February 14, 2025 17:12
@kyasbal
Copy link
Member

kyasbal commented Feb 15, 2025

--- FAIL: TestKHIServer_EndpointExistsWithConfigs (0.00s)
    --- FAIL: TestKHIServer_EndpointExistsWithConfigs/custom_server_base_path_on_non-viewer_mode (0.00s)
panic: open ../../dist/test.html: no such file or directory [recovered]
        panic: open ../../dist/test.html: no such file or directory

goroutine 192 [running]:
testing.tRunner.func1.2({0x1037520e0, 0x140004dfce0})
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/testing/testing.go:1632 +0x1bc
testing.tRunner.func1()
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/testing/testing.go:1635 +0x334
panic({0x1037520e0?, 0x140004dfce0?})
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/runtime/panic.go:785 +0x124
github.com/GoogleCloudPlatform/khi/pkg/testutil.MustPlaceTemporalFile({0x1033d0fb1, 0x14}, {0x0, 0x0})
        /Users/junyaokabe/src/github.com/Okabe-Junya/khi/pkg/testutil/io.go:75 +0xec
github.com/GoogleCloudPlatform/khi/pkg/server.TestKHIServer_EndpointExistsWithConfigs.func1(0x140001b36c0)
        /Users/junyaokabe/src/github.com/Okabe-Junya/khi/pkg/server/server_test.go:775 +0x90
testing.tRunner(0x140001b36c0, 0x140000a2540)
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/testing/testing.go:1690 +0xe4
created by testing.(*T).Run in goroutine 191
        /opt/homebrew/Cellar/go/1.23.6/libexec/src/testing/testing.go:1743 +0x314

The fail reason of your attached test result is caused because of the missing built frontend file.
You can fix it by make build-web

Copy link
Member

@kyasbal kyasbal left a comment

Choose a reason for hiding this comment

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

Thank you for proposing this change!

I added several questions and suggestion to fix 👍

@kyasbal kyasbal added the enhancement New feature or request label Feb 15, 2025
@kyasbal
Copy link
Member

kyasbal commented Feb 15, 2025

Please run make add-licenses to add the license header on the new files.
https://github.com/GoogleCloudPlatform/khi/actions/runs/13333576504/job/37263219493?pr=69

Okabe-Junya and others added 4 commits February 18, 2025 17:07
Co-authored-by: kyasbal <kyasbal1994@gmail.com>
Signed-off-by: Junya Okabe <86868255+Okabe-Junya@users.noreply.github.com>
@Okabe-Junya
Copy link
Contributor Author

The fail reason of your attached test result is caused because of the missing built frontend file.
You can fix it by make build-web

Thanks, fixed some errors!!

@Okabe-Junya Okabe-Junya requested a review from kyasbal February 18, 2025 08:45
@Okabe-Junya
Copy link
Contributor Author

Thank you for your review @kyasbal, and sorry for my delay in response
Please take a look again, thank you!!

Copy link
Member

@kyasbal kyasbal left a comment

Choose a reason for hiding this comment

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

Let me hear the opinion about adding*testing.T in the argument of IsValidLogQuery.
When the things may become more complex with the direction, I think we can merge this as is.

@Okabe-Junya
Copy link
Contributor Author

Thank you for your repeated, thorough reviews!!
I have responded to your comments. Please take a look again

@Okabe-Junya Okabe-Junya requested a review from kyasbal February 18, 2025 19:56
@Okabe-Junya
Copy link
Contributor Author

(If needed, I will squash some commits into one)

@kyasbal
Copy link
Member

kyasbal commented Feb 20, 2025

(If needed, I will squash some commits into one)

You don't need it but this repository require PR to be merged as a squashed single commit. Github automatically squash them into a single commit per PR.

@kyasbal
Copy link
Member

kyasbal commented Feb 20, 2025

Now this PR is ready to go!
Thank you @Okabe-Junya for contributing us!

@kyasbal kyasbal merged commit 4d50bb3 into GoogleCloudPlatform:main Feb 20, 2025
6 checks passed
@Okabe-Junya Okabe-Junya deleted the fix-57 branch February 20, 2025 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a flag to skip tests using Cloud Logging API
2 participants