Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

add gRPC UnaryServerInterceptor for kubeapps-apis #3780

Merged
satya-dillikar merged 4 commits into
vmware-tanzu:masterfrom
satya-dillikar:unary
Dec 1, 2021
Merged

add gRPC UnaryServerInterceptor for kubeapps-apis #3780
satya-dillikar merged 4 commits into
vmware-tanzu:masterfrom
satya-dillikar:unary

Conversation

@satya-dillikar
Copy link
Copy Markdown
Contributor

@satya-dillikar satya-dillikar commented Nov 18, 2021

Description of the change

Use an interceptor to automatically log every RPC call to the kubeapps-apis server.

Benefits

intercepting all RPC calls in one location.

Possible drawbacks

The kubectl logs for pod/kubeapps-internal-kubeappsapis will be flooded with more events.

Applicable issues

This tries to address #3385

Additional information

N/A

@satya-dillikar
Copy link
Copy Markdown
Contributor Author

A sample log file here
kubectl logs -n kubeapps pod/kubeapps-internal-kubeappsapis-5869f6c487-gxktf
I1118 19:30:52.278182 1 root.go:52] kubeapps-apis has been configured with: core.ServeOptions{Port:50051, PluginDirs:[]string{"/plugins/helm"}, ClustersConfigPath:"/config/clusters.conf", PluginConfigPath:"/config/kubeapps-apis/plugins.conf", PinnipedProxyURL:"http://kubeapps-internal-pinniped-proxy.kubeapps:3333", UnsafeLocalDevKubeconfig:false}
I1118 19:30:52.759995 1 server.go:157] +helm using custom packages config with {3 3 3}
I1118 19:30:52.762544 1 plugins.go:146] Successfully registered plugin "/plugins/helm/helm-packages-v1alpha1-plugin.so"
I1118 19:30:52.764710 1 packages.go:57] Registered name:"helm.packages" version:"v1alpha1" for core.packaging.v1alpha1 aggregation.
I1118 19:30:52.765215 1 server.go:160] Starting server on :50051
I1118 19:31:01.156003 1 server.go:47] LogRequest - 2.638µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:31:11.152659 1 server.go:47] LogRequest - 3.14µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:31:21.130793 1 server.go:47] LogRequest - 2.308µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:31:31.130114 1 server.go:47] LogRequest - 1.616µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:31:41.130452 1 server.go:47] LogRequest - 2.924µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:31:51.108535 1 server.go:47] LogRequest - 2.384µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:31:51.108555 1 server.go:47] LogRequest - 1.78µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:01.107678 1 server.go:47] LogRequest - 39.828µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:01.108071 1 server.go:47] LogRequest - 974ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:11.108355 1 server.go:47] LogRequest - 2.505µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:11.108437 1 server.go:47] LogRequest - 622ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:21.086404 1 server.go:47] LogRequest - 2.313µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:21.086484 1 server.go:47] LogRequest - 617ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:31.086747 1 server.go:47] LogRequest - 2.6µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:31.086983 1 server.go:47] LogRequest - 752ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:41.086209 1 server.go:47] LogRequest - 2.057µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:41.086272 1 server.go:47] LogRequest - 425ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:51.064718 1 server.go:47] LogRequest - 1.697µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:32:51.065323 1 server.go:47] LogRequest - 939ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:01.063962 1 server.go:47] LogRequest - 1.878µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:01.064182 1 server.go:47] LogRequest - 547ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:11.064607 1 server.go:47] LogRequest - 1.974µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:11.064610 1 server.go:47] LogRequest - 1.332µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:21.042775 1 server.go:47] LogRequest - 2.162µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:21.042866 1 server.go:47] LogRequest - 1.067µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:31.043262 1 server.go:47] LogRequest - 2.14µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:31.043305 1 server.go:47] LogRequest - 315ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:41.043567 1 server.go:47] LogRequest - 1.961µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:41.043683 1 server.go:47] LogRequest - 485ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:51.050031 1 server.go:47] LogRequest - 2.075µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:33:51.050098 1 server.go:47] LogRequest - 1.799µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:01.050299 1 server.go:47] LogRequest - 2.537µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:01.050837 1 server.go:47] LogRequest - 1.417µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:11.049916 1 server.go:47] LogRequest - 2.347µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:11.050123 1 server.go:47] LogRequest - 1.09µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:11.871224 1 packages.go:180] +core GetInstalledPackageSummaries (cluster="default", namespace="default")
I1118 19:34:11.871324 1 server.go:657] +helm GetInstalledPackageSummaries (cluster="default", namespace="default")
I1118 19:34:11.962787 1 server.go:47] LogRequest - 91.578101ms OK /kubeappsapis.core.packages.v1alpha1.PackagesService/GetInstalledPackageSummaries
I1118 19:34:21.044957 1 server.go:47] LogRequest - 107.206µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:21.045157 1 server.go:47] LogRequest - 2.857µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:31.044208 1 server.go:47] LogRequest - 2.385µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:31.044247 1 server.go:47] LogRequest - 357ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:41.044677 1 server.go:47] LogRequest - 2.084µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:41.044717 1 server.go:47] LogRequest - 308ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:51.026222 1 server.go:47] LogRequest - 2.751µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:34:51.026576 1 server.go:47] LogRequest - 1.638µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:01.025015 1 server.go:47] LogRequest - 1.606µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:01.025082 1 server.go:47] LogRequest - 503ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:11.026092 1 server.go:47] LogRequest - 2.319µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:11.026388 1 server.go:47] LogRequest - 1.031µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:21.004871 1 server.go:47] LogRequest - 2.582µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:21.004987 1 server.go:47] LogRequest - 649ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:31.004227 1 server.go:47] LogRequest - 1.915µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:31.004227 1 server.go:47] LogRequest - 1.904µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:41.004245 1 server.go:47] LogRequest - 1.805µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:41.004311 1 server.go:47] LogRequest - 1.07µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:50.982783 1 server.go:47] LogRequest - 2.284µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:50.982815 1 server.go:47] LogRequest - 1.11µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:35:59.935613 1 packages.go:67] +core GetAvailablePackageSummaries (cluster="default", namespace="default")
I1118 19:35:59.935731 1 packages.go:88] Items now: 0/0
I1118 19:35:59.935737 1 packages.go:90] Should enter
I1118 19:35:59.935769 1 server.go:242] +helm GetAvailablePackageSummaries (cluster="default", namespace="default")
I1118 19:36:00.788692 1 server.go:47] LogRequest - 853.094499ms OK /kubeappsapis.core.packages.v1alpha1.PackagesService/GetAvailablePackageSummaries
I1118 19:36:00.982971 1 server.go:47] LogRequest - 1.599µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:00.983015 1 server.go:47] LogRequest - 873ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:10.982932 1 server.go:47] LogRequest - 1.797µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:10.983042 1 server.go:47] LogRequest - 1.819µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:20.961670 1 server.go:47] LogRequest - 2.413µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:20.961797 1 server.go:47] LogRequest - 777ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:30.961939 1 server.go:47] LogRequest - 2.376µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:30.962692 1 server.go:47] LogRequest - 1.416µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:40.961338 1 server.go:47] LogRequest - 1.695µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:40.961620 1 server.go:47] LogRequest - 1.209µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:50.939681 1 server.go:47] LogRequest - 2.979µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:50.940038 1 server.go:47] LogRequest - 186.872µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:36:58.136797 1 packages.go:67] +core GetAvailablePackageSummaries (cluster="kubeapps", namespace="kubeapps")
I1118 19:36:58.136829 1 packages.go:88] Items now: 0/0
I1118 19:36:58.136834 1 packages.go:90] Should enter
I1118 19:36:58.136925 1 server.go:242] +helm GetAvailablePackageSummaries (cluster="kubeapps", namespace="kubeapps")
I1118 19:36:58.954072 1 server.go:47] LogRequest - 817.296616ms OK /kubeappsapis.core.packages.v1alpha1.PackagesService/GetAvailablePackageSummaries
I1118 19:37:00.939970 1 server.go:47] LogRequest - 1.905µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:00.940129 1 server.go:47] LogRequest - 627ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:10.939093 1 server.go:47] LogRequest - 1.931µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:10.939131 1 server.go:47] LogRequest - 295ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:20.918740 1 server.go:47] LogRequest - 1.686µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:20.919098 1 server.go:47] LogRequest - 1.155µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:29.137270 1 server.go:242] +helm GetAvailablePackageSummaries (cluster="", namespace="")
I1118 19:37:29.137365 1 server.go:47] LogRequest - 103.924µs Unimplemented /kubeappsapis.plugins.helm.packages.v1alpha1.HelmPackagesService/GetAvailablePackageSummaries
I1118 19:37:30.918506 1 server.go:47] LogRequest - 2.506µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:30.918583 1 server.go:47] LogRequest - 636ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:40.918213 1 server.go:47] LogRequest - 1.755µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:40.918286 1 server.go:47] LogRequest - 584ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:50.897809 1 server.go:47] LogRequest - 2.083µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:37:50.897827 1 server.go:47] LogRequest - 1.44µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:00.897675 1 server.go:47] LogRequest - 2.691µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:00.898391 1 server.go:47] LogRequest - 1.055µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:10.896764 1 server.go:47] LogRequest - 1.881µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:10.896848 1 server.go:47] LogRequest - 1.243µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:13.628693 1 server.go:242] +helm GetAvailablePackageSummaries (cluster="default", namespace="default")
I1118 19:38:14.593839 1 server.go:47] LogRequest - 965.187457ms OK /kubeappsapis.plugins.helm.packages.v1alpha1.HelmPackagesService/GetAvailablePackageSummaries
I1118 19:38:20.876341 1 server.go:47] LogRequest - 1.807µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:20.876434 1 server.go:47] LogRequest - 487ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:30.875823 1 server.go:47] LogRequest - 2.266µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:30.875868 1 server.go:47] LogRequest - 467ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:40.875468 1 server.go:47] LogRequest - 1.811µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:40.875664 1 server.go:47] LogRequest - 1.313µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:50.853822 1 server.go:47] LogRequest - 1.909µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:38:50.854010 1 server.go:47] LogRequest - 706ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:00.854616 1 server.go:47] LogRequest - 1.751µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:00.854707 1 server.go:47] LogRequest - 1.16µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:10.854550 1 server.go:47] LogRequest - 2.263µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:10.854708 1 server.go:47] LogRequest - 1.698µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:20.832906 1 server.go:47] LogRequest - 2.834µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:20.832989 1 server.go:47] LogRequest - 1.542µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:30.833787 1 server.go:47] LogRequest - 2.185µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:30.833890 1 server.go:47] LogRequest - 635ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:40.833248 1 server.go:47] LogRequest - 2.266µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:40.833353 1 server.go:47] LogRequest - 996ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:50.812635 1 server.go:47] LogRequest - 2.337µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:39:50.812655 1 server.go:47] LogRequest - 1.426µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:00.812236 1 server.go:47] LogRequest - 1.959µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:00.812315 1 server.go:47] LogRequest - 660ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:10.812242 1 server.go:47] LogRequest - 2.41µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:10.812338 1 server.go:47] LogRequest - 799ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:20.790336 1 server.go:47] LogRequest - 2.134µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:20.790369 1 server.go:47] LogRequest - 1.394µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:30.790968 1 server.go:47] LogRequest - 2.225µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:30.791352 1 server.go:47] LogRequest - 1.316µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:40.790931 1 server.go:47] LogRequest - 2.567µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:40.790983 1 server.go:47] LogRequest - 2.061µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:50.769878 1 server.go:47] LogRequest - 615ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:40:50.769749 1 server.go:47] LogRequest - 2.16µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:00.768797 1 server.go:47] LogRequest - 2.048µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:00.768881 1 server.go:47] LogRequest - 695ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:10.769203 1 server.go:47] LogRequest - 2.425µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:10.769260 1 server.go:47] LogRequest - 1.159µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:20.748038 1 server.go:47] LogRequest - 2.127µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:20.748369 1 server.go:47] LogRequest - 1.331µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:30.748564 1 server.go:47] LogRequest - 2.671µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:30.748779 1 server.go:47] LogRequest - 1.631µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:40.748014 1 server.go:47] LogRequest - 2.369µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:40.748421 1 server.go:47] LogRequest - 1.147µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:50.726395 1 server.go:47] LogRequest - 1.985µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:41:50.726501 1 server.go:47] LogRequest - 1.084µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:00.726780 1 server.go:47] LogRequest - 2.463µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:00.726879 1 server.go:47] LogRequest - 843ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:10.725286 1 server.go:47] LogRequest - 2.151µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:10.725964 1 server.go:47] LogRequest - 1.021µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:20.704760 1 server.go:47] LogRequest - 2.842µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:20.704985 1 server.go:47] LogRequest - 1.949µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:30.706032 1 server.go:47] LogRequest - 2.445µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:30.706032 1 server.go:47] LogRequest - 2.695µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:40.705311 1 server.go:47] LogRequest - 1.983µs OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins
I1118 19:42:40.705361 1 server.go:47] LogRequest - 346ns OK /kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins

Comment thread cmd/kubeapps-apis/server/server.go Outdated
res, err := handler(ctx, req)
log.Infof("LogRequest - %s %v %s\n",
time.Since(start),
status.Code(err),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just wondering: are we sure err will always exist? I mean, what if it is nil ?

Also: should we move it to another file, or we better do that once we have more interceptors configured?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

status.Code(nil) is OK: https://play.golang.org/p/6JbcUA1jYAX

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Satya. The formatting there for this request logging is perfect. I don't think we should use fmt.Printf for a number of reasons, but I think we can easily use the standard log package. There's a nice answer on stackoverflow that outlines the differences between fmt.Printf and log.Printf , but the main two here are, IMO:

  • logs generally go to stderr. Yes, we could still use the fmt package to do the same, but it wouldn't help with:
  • loggers guarantee that output won't be interleaved, where as fmt does not.

For this reason, I'd recommend doing something very similar to what you've done here, but using the standard log package. Here's an example that I just did to demo: https://go.dev/play/p/eAGBNYQE-59

Comment thread cmd/kubeapps-apis/server/server.go Outdated
// Create the grpc server and register the reflection server (for now, useful for discovery
// using grpcurl) or similar.
grpcSrv := grpc.NewServer()
grpcSrv := grpc.NewServer(grpc.ChainUnaryInterceptor(LogRequest))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although not now, what if we were to add more interceptors? Can we add as many of them as desired (below)? Or do we have to use the ChainUnaryServer ? (just asking, I don't know)

grpc.ChainUnaryInterceptor(LogRequest, myInterceptor1, foo, bar)

Comment thread cmd/kubeapps-apis/server/server.go Outdated
// LogRequest is a gRPC UnaryServerInterceptor that will log the API call
func LogRequest(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (response interface{}, err error) {
start := time.Now()
res, err := handler(ctx, req)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What I find useful here is having a way to also log the request params. I mean, don't like handling req params in each operation handler like:
+core GetAvailablePackageSummaries (cluster="kubeapps", namespace="kubeapps")

What if we add a more verbose tace (like V4) to also log the request params? WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, it'd be nice but I think that's difficult because the request message is different for each RPC call, so we can't just pull out the cluster and namespace, for example. At least, I don't see a way to do so without something very ugly like trying to cast the interface{} to each type of request message. But maybe you've thought of another way Antonio? Hmm, perhaps we could define an interface for a func RequestSummary() that we ensure for each request message and just cast to that... but either way, I think that should be out of scope for this PR (but worth investigating).

Comment thread cmd/kubeapps-apis/server/server.go Outdated
Comment thread cmd/kubeapps-apis/server/server.go Outdated
// LogRequest is a gRPC UnaryServerInterceptor that will log the API call
func LogRequest(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (response interface{}, err error) {
start := time.Now()
res, err := handler(ctx, req)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, it'd be nice but I think that's difficult because the request message is different for each RPC call, so we can't just pull out the cluster and namespace, for example. At least, I don't see a way to do so without something very ugly like trying to cast the interface{} to each type of request message. But maybe you've thought of another way Antonio? Hmm, perhaps we could define an interface for a func RequestSummary() that we ensure for each request message and just cast to that... but either way, I think that should be out of scope for this PR (but worth investigating).

Comment thread cmd/kubeapps-apis/server/server.go Outdated
res, err := handler(ctx, req)
log.Infof("LogRequest - %s %v %s\n",
time.Since(start),
status.Code(err),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

status.Code(nil) is OK: https://play.golang.org/p/6JbcUA1jYAX

@satya-dillikar
Copy link
Copy Markdown
Contributor Author

@antgamdia,

  1. err=nil is fine and works. Thanks to @absoludity for the quick code.
  2. Yes, you can add more interceptors using grpc.ChainUnaryInterceptor()
  3. I like the idea of logging all request params in one place. But casting the interface{} for each type can become cumbersome. Hence it is good practice to just log params in each RPC call.

@absoludity,

  1. We can remove "LogRequest" from each line. Note we are using log.Infof() hence the filename (server.go:47) is coming from the chosen format to log. Let me know if you don't want to use log.Infof() here.

@satya-dillikar
Copy link
Copy Markdown
Contributor Author

@absoludity , Please review and help to close it

Copy link
Copy Markdown
Contributor

@absoludity absoludity left a comment

Choose a reason for hiding this comment

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

@absoludity , Please review and help to close it

See inline. The format looks great, we just need to swap out fmt.Printf as detailed below. +1 to land once that's done.

Once this is landed, we should follow up with a PR which allows some config so that the liveness/readiness checks can be only printed when the verbosity is a certain level (V(4) is what Greg used, which makes sense - debug only). But let's discuss that once this lands.

Comment thread cmd/kubeapps-apis/server/server.go Outdated
res, err := handler(ctx, req)
log.Infof("LogRequest - %s %v %s\n",
time.Since(start),
status.Code(err),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Satya. The formatting there for this request logging is perfect. I don't think we should use fmt.Printf for a number of reasons, but I think we can easily use the standard log package. There's a nice answer on stackoverflow that outlines the differences between fmt.Printf and log.Printf , but the main two here are, IMO:

  • logs generally go to stderr. Yes, we could still use the fmt package to do the same, but it wouldn't help with:
  • loggers guarantee that output won't be interleaved, where as fmt does not.

For this reason, I'd recommend doing something very similar to what you've done here, but using the standard log package. Here's an example that I just did to demo: https://go.dev/play/p/eAGBNYQE-59

Comment thread cmd/kubeapps-apis/server/server.go Outdated
// Create the grpc server and register the reflection server (for now, useful for discovery
// using grpcurl) or similar.
grpcSrv := grpc.NewServer()
grpcSrv := grpc.NewServer(grpc.ChainUnaryInterceptor(LogRequest))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally we'd create the logger here (logger := log.New(...)), but to include it in the LogRequest function (without instantiating it every time), we'll probably need to use a closure. The simplest way would be to just create the logger here, then move the definition of your LogRequest function inline here so it can reference the logger. That way the logger is only created once.

That would be fine and do the job, but if you're more familiar with closures, you could instead create a function that takes the created logger as input and returns the request logger function, CreateRequestLogger(log.Logger) func(context.Context, ...) (interface{}, error) { ... }, which is a bit nicer, if you're used to closures in Go. Fine either way.

@satya-dillikar
Copy link
Copy Markdown
Contributor Author

Done. Updated the logger as requested. see commit

@absoludity
Copy link
Copy Markdown
Contributor

Done. Updated the logger as requested. see commit

Perfect, thanks Satya.

I'm unable to re-trigger CI (since the branch is under your GH account). If you're able to do so by clicking on the "Re-run -> Re-run from failed" on the CI build page, please do so. Otherwise, adding an empty commit and pushing again will retrigger the whole build.

@migmartri
Copy link
Copy Markdown
Contributor

migmartri commented Dec 21, 2021

Hi there!

We are in the process of standardizing on logging practices and found this patch which contains very interesting discussions :)

I have a couple of potentially basic questions though

1 - Why did you discard the use of logrus or of the existing logrus interceptor?
2 - What's the reasoning behind using both the std library log package and klog?
3 - The patch seems to include a change that update exist statements such as log.Fatalf("failed to serve: %v", err) to klog, what's the reason of that swap when the log package is still available? Do log levels apply to Fatalf?

Thank you so much, Kubeapps and you all rock! :)

@satya-dillikar
Copy link
Copy Markdown
Contributor Author

  1. This change is specific to kubeapps-apis. Kubeapps-apis server and plugins are using klog only. Hence, we stick with klog and did not explore logrus.
  2. Why klog is better than log is outside of this PR scope. Please refer klog for more datapoints.
  3. We just renamed the package module to be more specific
    See the diff.
    -log "k8s.io/klog/v2"
    +klogv2 "k8s.io/klog/v2"

HTH,
Satya

@migmartri
Copy link
Copy Markdown
Contributor

migmartri commented Dec 22, 2021

Thanks Satya, that makes sense, in any case my question wasn't "Why klog is better than log" but why do you keep using standard librarylog when you are also using klog

@absoludity
Copy link
Copy Markdown
Contributor

Thanks Satya, that makes sense, in any case my question wasn't "Why klog is better than log" but why do you keep using standard librarylog when you are also using klog

I don't remember all the context, but I think it was because klog assumes that you are always calling it from an actual call-site, including the file/line (with the default settings). So using it in an interceptor, where you are adding a generic log statement for many call-sites, results in every one being logged with useless info of the interceptor call-site. Not sure if that was the whole reason.

@migmartri
Copy link
Copy Markdown
Contributor

That makes sense, thanks for the context, I'll give it a try on our end since we might be actually running into what you just mentioned and didn't notice :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants