openwhisk icon indicating copy to clipboard operation
openwhisk copied to clipboard

What happens in the Invoker?

Open ZinuoCai opened this issue 5 years ago • 9 comments

I read the invoker's code, but I still cannot understand how the invoker can execute users' fuctions. Furthermore, when I check the invoker's pod' logs, I find something like below. How can other components like ContainerPool, KubernetesClient print their logs in the pod when I cannot find them in the code ?

[2021-01-05T09:24:12.660Z] [INFO] [#tid_sid_invokerWarmup] [ContainerPool] found 0 started and 0 starting; initing 2 pre-warms to desired count: 2 for kind:nodejs:10 mem:256 MB
[2021-01-05T09:24:13.181Z] [INFO] [#tid_sid_invokerWarmup] [KubernetesClient] launching pod wskowdev-invoker-00-1-prewarm-nodejs10 (image:openwhisk/action-nodejs-v10:1.16.0, mem: 256) (timeout: 60s) [marker:invoker_kubeapi.create_start:6253]
[2021-01-05T09:24:13.181Z] [INFO] [#tid_sid_invokerWarmup] [KubernetesClient] launching pod wskowdev-invoker-00-2-prewarm-nodejs10 (image:openwhisk/action-nodejs-v10:1.16.0, mem: 256) (timeout: 60s) [marker:invoker_kubeapi.create_start:6253]
[2021-01-05T09:24:13.232Z] [INFO] [#tid_sid_invokerHealth] [InvokerReactive]  [marker:invoker_activation_start:680360168]
[2021-01-05T09:24:13.243Z] [WARN] [#tid_sid_invokerHealth] [InvokerReactive] revision was not provided for whisk.system/invokerHealthTestAction0
[2021-01-05T09:24:13.492Z] [INFO] [#tid_sid_invokerHealth] [CouchDbRestStore] [GET] 'test_whisks' finding document: 'id: whisk.system/invokerHealthTestAction0' [marker:database_getDocument_start:680360428]
[2021-01-05T09:24:13.524Z] [INFO] [#tid_sid_invokerHealth] [CouchDbRestStore]  [marker:database_getDocument_finish:680360461:33]
[2021-01-05T09:24:13.637Z] [INFO] [#tid_sid_invokerHealth] [KubernetesClient] launching pod wskowdev-invoker-00-3-whisksystem-invokerhealthtestaction0 (image:openwhisk/action-nodejs-v10:1.16.0, mem: 128) (timeout: 60s) [marker:invoker_kubeapi.create_start:680360574]
[2021-01-05T09:24:13.640Z] [INFO] [#tid_sid_invokerHealth] [ContainerPool] containerStart containerState: cold container: None activations: 1 of max 1 action: invokerHealthTestAction0 namespace: whisk.system activationId: 6fc606abe2f242578606abe2f2e257a2 [marker:invoker_containerStart.cold_counter:680360577]
[2021-01-05T09:24:40.910Z] [INFO] [#tid_sid_invokerWarmup] [KubernetesClient]  [marker:invoker_kubeapi.create_finish:33983:27728]
[2021-01-05T09:24:56.226Z] [INFO] [#tid_sid_invokerWarmup] [KubernetesClient]  [marker:invoker_kubeapi.create_finish:49297:43043]
[2021-01-05T09:25:10.816Z] [INFO] [#tid_sid_invokerHealth] [KubernetesClient]  [marker:invoker_kubeapi.create_finish:680417752:57178]
[2021-01-05T09:25:11.393Z] [INFO] [#tid_sid_invokerHealth] [KubernetesContainer] sending initialization to ContainerId(wskowdev-invoker-00-3-whisksystem-invokerhealthtestaction0) ContainerAddress(10.244.2.56,8080) [marker:invoker_activationInit_start:680418330]
[2021-01-05T09:25:11.820Z] [INFO] [#tid_sid_invokerHealth] [KubernetesContainer] initialization result: ok [marker:invoker_activationInit_finish:680418755:422]
[2021-01-05T09:25:11.823Z] [INFO] [#tid_sid_unknown] [ContainerProxy] resending up to 0 from 0 buffered jobs
[2021-01-05T09:25:11.825Z] [INFO] [#tid_sid_invokerHealth] [KubernetesContainer] sending arguments to /whisk.system/invokerHealthTestAction0 at ContainerId(wskowdev-invoker-00-3-whisksystem-invokerhealthtestaction0) ContainerAddress(10.244.2.56,8080) [marker:invoker_activationRun_start:680418762]
[2021-01-05T09:25:11.838Z] [INFO] [#tid_sid_invokerHealth] [KubernetesContainer] running result: ok [marker:invoker_activationRun_finish:680418774:9]
[2021-01-05T09:25:11.847Z] [INFO] [#tid_sid_invokerHealth] [ContainerProxy]  [marker:invoker_collectLogs_start:680418784]
[2021-01-05T09:25:11.967Z] [INFO] [#tid_sid_invokerHealth] [ContainerProxy]  [marker:invoker_collectLogs_finish:680418902:116]

ZinuoCai avatar Jan 05 '21 13:01 ZinuoCai

There are those two in the sources. https://github.com/apache/openwhisk/blob/master/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala#L58 https://github.com/apache/openwhisk/blob/master/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/kubernetes/KubernetesClient.scala#L119

style95 avatar Jan 06 '21 00:01 style95

There are those two in the sources. https://github.com/apache/openwhisk/blob/master/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala#L58 https://github.com/apache/openwhisk/blob/master/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/kubernetes/KubernetesClient.scala#L119

Hey, thanks for your reply. However, my question is not that I cannot find the source code of those two components. I do not understand how to combine these two components in core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala because I do not find any references of ContainerPool or KubernetesClient in the file.

ZinuoCai avatar Jan 06 '21 02:01 ZinuoCai

ContainerPool is created as a member variable of InvokerReactive. https://github.com/apache/openwhisk/blob/master/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/InvokerReactive.scala#L164

OpenWhisk takes advantage of SPI in many places. And KubernetesContainerFactory which depends on KubernetesClient internally, is instantiated via SPI as well. https://github.com/apache/openwhisk/blob/master/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/InvokerReactive.scala#L85

You may find this useful. https://github.com/apache/openwhisk/blob/b00678d30604d0ffb45792fdcd4b61714cfffd1c/docs/spi.md

And I recommend using the slack channel for this kind of question instead of opening a new issue. https://openwhisk.apache.org/slack.html

style95 avatar Jan 06 '21 03:01 style95

Thank you very much! I will check the usage of slack.

ZinuoCai avatar Jan 06 '21 07:01 ZinuoCai

Hello, everyone! I am reading the Invoker's source code. I am a little confused of what ContainerFactoryProvider here refers to. https://github.com/apache/openwhisk/blob/2c621c0733befdadadb5f25f167fe575d1b15739/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/InvokerReactive.scala#L85 In reference.conf, it points to org.apache.openwhisk.core.containerpool.docker.DockerContainerFactoryProvider . But it is not true when I print its class. It shoule be org.apache.openwhisk.core.containerpool.kubernetes.KubernetesContainerFactory  but I do not understand it.

ZinuoCai avatar Jan 08 '21 11:01 ZinuoCai

Are you deploying to kubernetes / using the helm chart? The Kube container factory is the default container factory for k8s.

rabbah avatar Jan 08 '21 13:01 rabbah

Yes, I deployed it to kubernetes using the helm chart. I wonder how the project set the ContainerFactoryProvider to be org.apache.openwhisk.core.containerpool.kubernetes.KubernetesContainerFactory.

ZinuoCai avatar Jan 08 '21 15:01 ZinuoCai

It is configured by the default values.yaml for the helm chart: https://github.com/apache/openwhisk-deploy-kube/blob/6a860c8e0133047e0948539f656f08dc2a08e9dd/helm/openwhisk/values.yaml#L276.

That value of invoker.containerFactory.imp controls a number of features in the Helm chart, but the directly relevant thing is that it adds a command line argument that controls which ContainerFactoryProvider is used. See https://github.com/apache/openwhisk-deploy-kube/blob/6a860c8e0133047e0948539f656f08dc2a08e9dd/helm/openwhisk/templates/_helpers.tpl#L316-#L323

dgrove-oss avatar Jan 08 '21 23:01 dgrove-oss

Thank you very much!

ZinuoCai avatar Jan 09 '21 06:01 ZinuoCai