OpenFunction / samples

Function samples (Go, Node.js, Java, etc.)
Apache License 2.0
32 stars 48 forks source link

couldn't find output binding serving-fv9tm-bindings-httpz-m5cbd #132

Closed uestczz closed 1 year ago

uestczz commented 1 year ago

I'm trying the sample named with-output-binding, and function-front.yaml may confuse me. so I make my yaml based on the readme. k8s v1.26.0 openfunction/openfunction:v1.1.1 my serving config is as below: ‘‘‘ apiVersion: core.openfunction.io/v1beta2 serving: scaleOptions: minReplicas: 0 maxReplicas: 5 outputs:

and my code is as below: req := CorpIDToOpenReq{ CorpID: "xxxxxxx", } data, _ := json.Marshal(req) bytes, err := ctx.Send("httpz", data) if err != nil { return ctx.ReturnOnInternalError(), err } Then a error raised: 2023/09/07 02:04:14 httpz 2023/09/07 02:04:14 {httpz serving-fv9tm-bindings-httpz-m5cbd bindings.http map[] post} 2023/09/07 02:04:14 httpy 2023/09/07 02:04:14 {httpy serving-fv9tm-bindings-httpy-v2t64 bindings.http map[] get} 2023/09/07 02:04:14 [123 10 9 34 110 34 58 32 49 10 125] 2023/09/07 02:04:15 error invoking binding serving-fv9tm-bindings-httpz-m5cbd/post: rpc error: code = Internal desc = error when invoke output binding serving-fv9tm-bindings-httpz-m5cbd: couldn't find output binding serving-fv9tm-bindings-httpz-m5cbd

I print the output map, there's a key named httpz. and I want to invode a nodapr httpendpoint. so what's wrong with my code.

wanjunlei commented 1 year ago

Run the following command and paste the result.

kubectl get servings serving-fv9tm -n < namespace > -oyaml
kubectl get components -A
uestczz commented 1 year ago

@wanjunlei i update my function, so the name may changes. 2023/09/07 06:04:56 httpz 2023/09/07 06:04:56 {httpz serving-2xtn4-bindings-httpz-47wjs bindings.http map[] post} 2023/09/07 06:04:56 httpy 2023/09/07 06:04:56 {httpy serving-2xtn4-bindings-httpy-694tj bindings.http map[] get} 2023/09/07 06:04:56 [123 10 9 34 110 34 58 32 49 10 125] 2023/09/07 06:04:57 error invoking binding serving-2xtn4-bindings-httpz-47wjs/post: rpc error: code = Internal desc = error when invoke output binding serving-2xtn4-bindings-httpz-47wjs: couldn't find output binding serving-2xtn4-bindings-httpz-47wjs

kubectl get servings.core.openfunction.io serving-2xtn4 -oyaml `apiVersion: core.openfunction.io/v1beta2 kind: Serving metadata: creationTimestamp: "2023-09-07T03:25:22Z" generateName: serving- generation: 1 labels: openfunction.io/function: go-bind-http name: serving-2xtn4 namespace: default ownerReferences:

kubectl get components -A NAMESPACE NAME AGE default pubsub 78d default serving-2xtn4-bindings-httpy-694tj 155m default serving-2xtn4-bindings-httpz-47wjs 155m default statestore 78d

uestczz commented 1 year ago

@wanjunlei do you have wechat group, or online meeting? I read the code of function "parseContext" in the repo functions-framework-go. but it just unmarshal the env data. so how are the outputs in yaml transformed to data in env.

wanjunlei commented 1 year ago

you can join our discord channel

uestczz commented 1 year ago

@wanjunlei so could you please help me solve my problem? and I paste the result of your cmd.

wanjunlei commented 1 year ago

You need to add httpz to the spec.bindings like the spec.bindings.httpy

uestczz commented 1 year ago

@wanjunlei there's also the same problem with httpy. 2023/09/07 07:55:57 error invoking binding serving-2xtn4-bindings-httpy-694tj/get: rpc error: code = Internal desc = error when invoke output binding serving-2xtn4-bindings-httpy-694tj: couldn't find output binding serving-2xtn4-bindings-httpy-694tj

the specs of httpz and httpy are the same.

spec:
  bindings:
    httpy:
      ignoreErrors: false
      initTimeout: ""
      metadata:
      - name: url
        secretKeyRef:
          key: ""
          name: ""
        value: http://10.0.0.127:30417/corp_customer/customer/info
      - name: direction
        secretKeyRef:
          key: ""
          name: ""
        value: output
      type: bindings.http
      version: v1
    httpz:
      ignoreErrors: false
      initTimeout: ""
      metadata:
      - name: url
        secretKeyRef:
          key: ""
          name: ""
        value: http://10.0.0.127:14121/workwxsdk/proxy/service/corpid_to_opencorpid
      - name: direction
        secretKeyRef:
          key: ""
          name: ""
        value: output
      type: bindings.http
      version: v1
  image: uestczshen/go-bind-http:v1@sha256:b620b7bffbccc2ba077937f6edca46f383e91ea5010e02cca2b7280afb4898fa
  imageCredentials:
    name: push-secret
  outputs:
  - dapr:
      name: httpz
      operation: post
      type: bindings.http
  - dapr:
      name: httpy
      operation: get
      type: bindings.http
  scaleOptions:
    maxReplicas: 5
    minReplicas: 0
  template:
    containers:
    - imagePullPolicy: IfNotPresent
      name: function
      resources: {}
  triggers:
    http:
      port: 8080
      route:
        gatewayRef:
          name: openfunction
          namespace: openfunction
  version: v1.0.0
wanjunlei commented 1 year ago

I think this error is related to the dapr component, OpenFunction has created the dapr component but the component doesn't seem to be ready yet, please check first.

uestczz commented 1 year ago

@wanjunlei how to check it. openfunction is composed of dapr. I decide to use openfunction in production environment. any company has used it?

dapr components -k
  NAMESPACE  NAME                                TYPE           VERSION  SCOPES                CREATED              AGE
  default    pubsub                              pubsub.redis   v1                             2023-06-20 14:54.40  79d
  default    serving-2xtn4-bindings-httpy-694tj  bindings.http  v1       go-bind-http-default  2023-09-07 11:25.22  5h
  default    serving-2xtn4-bindings-httpz-47wjs  bindings.http  v1       go-bind-http-default  2023-09-07 11:25.22  5h
  default    statestore                          state.redis    v1                             2023-06-20 14:54.39  79d
wanjunlei commented 1 year ago

you can try this

dapr invoke --app-id serving-2xtn4-bindings-httpy-694tj --verb GET
uestczz commented 1 year ago

dapr invoke is only used for self-hosted, and invoke. my sample is binding.

dapr -h
invoke         Invoke a method on a given Dapr application. Supported platforms: Self-hosted
dapr list
  APP ID                HTTP PORT  GRPC PORT  APP PORT  COMMAND  AGE  CREATED              DAPRD PID  CLI PID  APP PID  RUN TEMPLATE PATH
  nodeapp               3500       50001      3000               6d   2023-09-06 17:18.15  13012      0        0
  go-bind-http-default  3500       50001      8080               1h   2023-09-12 15:47.14  135265     0        0
dapr components -k
  NAMESPACE  NAME                                TYPE           VERSION  SCOPES                CREATED              AGE
  default    pubsub                              pubsub.redis   v1                             2023-06-20 14:54.40  84d
  default    serving-wb7q9-bindings-httpz-pdk85  bindings.http  v1       go-bind-http-default  2023-09-12 15:47.10  1h
  default    statestore                          state.redis    v1                             2023-06-20 14:54.39  84d
k get components.dapr.io serving-wb7q9-bindings-httpz-pdk85 -oyaml
apiVersion: dapr.io/v1alpha1
auth:
  secretStore: ""
kind: Component
metadata:
  creationTimestamp: "2023-09-12T07:47:10Z"
  generateName: serving-wb7q9-bindings-httpz-
  generation: 1
  labels:
    openfunction.io/managed: "true"
    openfunction.io/serving: serving-wb7q9
  name: serving-wb7q9-bindings-httpz-pdk85
  namespace: default
  ownerReferences:
  - apiVersion: core.openfunction.io/v1beta2
    blockOwnerDeletion: true
    controller: true
    kind: Serving
    name: serving-wb7q9
    uid: f02a12ea-5336-493e-8e92-6ca8eb8148c1
  resourceVersion: "87303681"
  uid: a04fe7ea-ec76-4be2-bb21-ad3ffe8e7143
scopes:
- go-bind-http-default
spec:
  ignoreErrors: false
  initTimeout: ""
  metadata:
  - name: url
    secretKeyRef:
      key: ""
      name: ""
    value: http://10.0.0.127:14121/workwxsdk/proxy/service/corpid_to_opencorpid
  - name: direction
    secretKeyRef:
      key: ""
      name: ""
    value: output
  type: bindings.http
  version: v1

so there's a component definition named serving-wb7q9-bindings-httpz-pdk85.

but I use curl, the same error occur.

curl -H "Content-Type: application/json" -H "dapr-app-id: go-bind-http-default" -X POST -d "{ \"operation\": \"post\" }" 'http://10.98.248.56:3500/v1.0/bindings/serving-wb7q9-bindings-httpz-pdk85'
{"errorCode":"ERR_INVOKE_OUTPUT_BINDING","message":"error when invoke output binding serving-wb7q9-bindings-httpz-pdk85: couldn't find output binding serving-wb7q9-bindings-httpz-pdk85"}

10.98.248.56 is the endpoint of svc go-bind-http-default. it points to a proxy. so dapr doesn't load the definition of my component. And can you give some suggestions? @wanjunlei

wanjunlei commented 1 year ago

Please check the dapr controller logs first, maybe there is some helpful information.

uestczz commented 1 year ago

@wanjunlei I found some errors from dapr-operator. there's something wrong with anothor component. so maybe daprd for this func failed when creating.

time="2023-09-12T14:44:41.679825271Z" level=warning msg="error processing component statestore secrets from pod default/serving-x99b7-proxy-deployment-v100-hm4td-5cb7c476f7-9t7t8: Secret \"redis\" not found" instance=dapr-operator-789c564b58-l6j72 scope=dapr.operator.api type=log ver=1.8.3
wanjunlei commented 1 year ago

@wanjunlei I found some errors from dapr-operator. there's something wrong with anothor component. so maybe daprd for this func failed when creating.

time="2023-09-12T14:44:41.679825271Z" level=warning msg="error processing component statestore secrets from pod default/serving-x99b7-proxy-deployment-v100-hm4td-5cb7c476f7-9t7t8: Secret \"redis\" not found" instance=dapr-operator-789c564b58-l6j72 scope=dapr.operator.api type=log ver=1.8.3

I think this log has nothing to do with the error above, maybe you can enable the debug log to get more information.

uestczz commented 1 year ago

@wanjunlei I delete the state store dapr component. dapr becomes okay. but now my function has no address. I don't know why.

k get functions.core.openfunction.io
NAME           BUILDSTATE   SERVINGSTATE   BUILDER         SERVING         ADDRESS   AGE
go-bind-http   Succeeded    Starting       builder-2tx5q   serving-5xltt             9h
wanjunlei commented 1 year ago

The function serving is starting, maybe there is some error about knative.

Run this command to check the status

kubectl get ksvc

uestczz commented 1 year ago

@wanjunlei
Yes, there's something wrong with the ep of ksvc. k describe ksvc serving-5xltt-ksvc-g9msk

Status:
  Address:
    URL:  http://serving-5xltt-ksvc-g9msk.default.svc.cluster.local
  Conditions:
    Last Transition Time:        2023-09-12T16:45:27Z
    Status:                      True
    Type:                        ConfigurationsReady
    Last Transition Time:        2023-09-12T16:45:27Z
    Message:                     Waiting for Envoys to receive Endpoints data.
    Reason:                      EndpointsNotReady
    Status:                      Unknown
    Type:                        Ready
    Last Transition Time:        2023-09-12T16:45:27Z
    Message:                     Waiting for Envoys to receive Endpoints data.
    Reason:                      EndpointsNotReady
    Status:                      Unknown
    Type:                        RoutesReady
  Latest Created Revision Name:  serving-5xltt-ksvc-g9msk-v100
  Latest Ready Revision Name:    serving-5xltt-ksvc-g9msk-v100
  Observed Generation:           1
  Traffic:
    Latest Revision:  true
    Percent:          100
    Revision Name:    serving-5xltt-ksvc-g9msk-v100
  URL:                http://serving-5xltt-ksvc-g9msk.default.example.com
Events:               <none>
NAME                                      READY   STATUS    RESTARTS     AGE
activator-868664b95c-fxdrh                0/1     Pending   0            10h
autoscaler-58fcfc959f-llh2r               1/1     Running   0            10h
controller-cc5fcb856-z8fxx                1/1     Running   0            10h
domain-mapping-75d8b69c46-fjdzw           1/1     Running   0            10h
domainmapping-webhook-6bd559cc49-dkvhj    1/1     Running   1 (9h ago)   10h
net-contour-controller-6685dfcf6c-rrtfn   1/1     Running   0            10h
webhook-69fd7f47f6-lkktn                  1/1     Running   1 (9h ago)   10h

maybe because the activator is pending