OpenFunction / samples

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

nodejs sample build fail #134

Open uestczz opened 1 year ago

uestczz commented 1 year ago
k logs builder-zx7hr-buildrun-mb8g2-vk45c-pod -c step-create
===> DETECTING
3 of 4 buildpacks participating
openfunction.nodejs.npm                 0.6.0
openfunction.nodejs.functions-framework 0.6.0
google.utils.label                      0.0.1
===> ANALYZING
Previous image with name "uestczshen/sample-node-esm-func:v1" not found
===> RESTORING
===> BUILDING
=== Node.js - NPM (openfunction.nodejs.npm@0.6.0) ===
Generating package-lock.json.
WARNING: *** Improve build performance by generating and committing package-lock.json.
--------------------------------------------------------------------------------
Running "npm install --package-lock-only --quiet"
npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/cloudevents (over 300000ms)

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/cnb/.npm/_logs/2023-09-13T10_37_47_535Z-debug.log
Done "npm install --package-lock-only --quiet" (52m7.6884s)
Failure: (ID: b0ba1f57) npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/cloudevents (over 300000ms)

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/cnb/.npm/_logs/2023-09-13T10_37_47_535Z-debug.log
ERROR: failed to build: exit status 1

maybe I should set the npm source https://registry.npm.taobao.org, but how to?

function.yaml

apiVersion: core.openfunction.io/v1beta2
kind: Function
metadata:
  name: node-sample
spec:
  version: "v1.0.0"
  image: "uestczshen/sample-node-esm-func:v1"
  imageCredentials:
    name: push-secret
  build:
    builder: "openfunction/builder-node:latest"
    env:
      FUNC_NAME: "helloESM"
      FUNC_TYPE: "http"
    srcRepo:
      url: "https://github.com/OpenFunction/samples.git"
      sourceSubPath: "functions/knative/hello-world-node/esm"
      revision: "main"
  serving:
    template:
      containers:
        - name: function
          imagePullPolicy: IfNotPresent 
    triggers:
      http:
        port: 8080
benjaminhuo commented 1 year ago

@webup Would you give some lights on this? :)

uestczz commented 1 year ago

@benjaminhuo I add .npmrc to the folder

registry=https://registry.npmmirror.com
strict-peer-dependencies=false

then it runs okay. but I encounter another error, dapr sidecar start error when I invoke the function by external address. my binding is the same with my go function, and my go function runs okay.

k logs -f serving-5hgj8-ksvc-n8f55-v100-deployment-7c477c7db6-t949d
E0914 11:06:58.813469  128400 memcache.go:255] couldn't get resource list for external.metrics.k8s.io/v1beta1: Got empty response for: external.metrics.k8s.io/v1beta1
Defaulted container "function" out of: function, queue-proxy
2023-09-14T03:06:29.725Z common:options ℹ️ Context loaded: {"name":"node-bind-http","version":"v1.0.0","outputs":{"httpz":{"uri":"httpz","componentName":"serving-5hgj8-bindings-httpz-zz5lp","componentType":"bindings.http","operation":"post"},"httpy":{"uri":"httpy","componentName":"serving-5hgj8-bindings-httpy-smzs4","componentType":"bindings.http","operation":"get"}},"runtime":"Knative","port":"8080"}
Data received: { corpid: 'ww4128618519222cad' }
2023-09-14T03:06:29.931Z INFO [HTTPClient, HTTPClient] Awaiting Sidecar to be Started

[
  {
    status: 'rejected',
    reason: Error: DAPR_SIDECAR_COULD_NOT_BE_STARTED
        at Function.<anonymous> (/workspace/source/node/http_invoke/node_modules/@dapr/dapr/implementation/Client/DaprClient.js:154:27)
        at Generator.next (<anonymous>)
        at fulfilled (/workspace/source/node/http_invoke/node_modules/@dapr/dapr/implementation/Client/DaprClient.js:36:58)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
  }
]

my function.yaml is:

apiVersion: core.openfunction.io/v1beta2
kind: Function
metadata:
  name: node-bind-http
spec:
  version: "v1.0.0"
  image: uestczshen/node-bind-http:v1
  imageCredentials:
    name: push-secret
  build:
    builder: openfunction/builder-node:v2-16.13
    env:
      FUNC_NAME: "tryKnativeAsync"
    srcRepo:
      url: "https://gitlab.xiaoduoai.com/zhangzhuo/openfunction-test.git"
      sourceSubPath: "node/http_invoke"
      revision: "master"
  serving:
    scaleOptions:
      minReplicas: 0
      maxReplicas: 2
    annotations:
      # Dapr annotations: https://docs.dapr.io/reference/arguments-annotations-overview/
      # default to "info"
      dapr.io/log-level: debug
      # default to "true"
      dapr.io/log-as-json: 'false'
    params:
      # default to FUNC_NAME value
      FUNCTION_TARGET: tryKnativeAsync
      # default to http
      FUNCTION_SIGNATURE_TYPE: openfunction
      DEBUG: common:*,ofn:*
    outputs:
      - dapr:
          name: httpz
          type: bindings.http
          operation: "post"
      - dapr:
          name: httpy
          type: bindings.http
          operation: "get"
    bindings:
      httpz:
        type: bindings.http
        version: v1
        metadata:
          - name: url
            value: "http://10.0.0.127:14121/workwxsdk/proxy/service/corpid_to_opencorpid"
          - name: direction
            value: "output"
      httpy:
        type: bindings.http
        version: v1
        metadata:
          - name : url
            value: "http://10.0.0.127:30417/corp_customer/customer/info"
          - name: direction
            value: "output"
    template:
      containers:
        - name: function
          imagePullPolicy: IfNotPresent
    triggers:
      http:
        port: 8080

my js code:

export const tryKnativeAsync = async (ctx, data) => {
    console.log('Data received: %o', data);
    let res = await ctx.send(data, "httpz");

    console.log(res)
    // Request data is also accessible via "ctx.req"
    ctx.res.send(res);
  };

and at last my package.json is:

{
    "main": "index.mjs",
    "scripts": {
      "start": "functions-framework --target=tryKnativeAsync"
    },
    "dependencies": {
      "@openfunction/functions-framework": "^0.5.0"
    }
}

I can invode the binding through endpoints of node-bind-http-default-dapr service:

dapr components -k
  NAMESPACE  NAME                                TYPE           VERSION  SCOPES                  CREATED              AGE
  default    serving-mjj5g-bindings-httpy-btlfd  bindings.http  v1       node-bind-http-default  2023-09-14 11:33.36  1m
  default    serving-mjj5g-bindings-httpz-fkjnw  bindings.http  v1       node-bind-http-default  2023-09-14 11:33.36  1m

k get ep node-bind-http-default-dapr
external.metrics.k8s.io/v1beta1: Got empty response for: external.metrics.k8s.io/v1beta1
NAME                          ENDPOINTS                                                            AGE
node-bind-http-default-dapr   10.98.248.12:9090,10.98.248.12:50002,10.98.248.12:3500 + 1 more...   67s

curl -H "Content-Type: application/json" -H "dapr-app-id: node-bind-http-default" -X POST -d "{ \"operation\": \"post\" }" 'http://10.98.248.12:3500/v1.0/bindings/serving-mjj5g-bindings-httpz-fkjnw'
{"code":40058,"message":"workwx error[40058:invalid Request Parameter, hint: [1694662762365203524488982], from ip: 182.151.205.9, more info at https://open.work.weixin.qq.com/devtool/query?e=40058]","data":null}

can you give some suggestions?

uestczz commented 1 year ago

I can invoke the node-bind-http-default-dapr service:

k get ep node-bind-http-default-dapr
NAME                          ENDPOINTS                                                            AGE
node-bind-http-default-dapr   10.98.248.12:9090,10.98.248.12:50002,10.98.248.12:3500 + 1 more...   67s

dapr components -k
  NAMESPACE  NAME                                TYPE           VERSION  SCOPES                  CREATED              AGE
  default    serving-mjj5g-bindings-httpy-btlfd  bindings.http  v1       node-bind-http-default  2023-09-14 11:33.36  1m
  default    serving-mjj5g-bindings-httpz-fkjnw  bindings.http  v1       node-bind-http-default  2023-09-14 11:33.36  1m

curl -H "Content-Type: application/json" -H "dapr-app-id: node-bind-http-default" -X POST -d "{ \"operation\": \"post\" }" 'http://10.98.248.12:3500/v1.0/bindings/serving-mjj5g-bindings-httpz-fkjnw'
{"code":40058,"message":"workwx error[40058:invalid Request Parameter, hint: [1694662762365203524488982], from ip: 182.151.205.9, more info at https://open.work.weixin.qq.com/devtool/query?e=40058]","data":null}
uestczz commented 1 year ago

I think there's sth wrong with my openfunction edittion v0.6.0. I find samples:v0.6.0 has no node-output-binding sample. so it may be the reason. but I use helm, and the latest version in helm is v0.6.0. should I upgrade by another way? @benjaminhuo

uestczz commented 1 year ago

okay, I found the chart repo. So I will follow the readme doc first. So must I upgrade step by step? 0.6 -> .07, 0.7->0.8, 0.8->1.0