Git Product home page Git Product logo

mrdulin / nodejs-gcp Goto Github PK

View Code? Open in Web Editor NEW
10.0 5.0 2.0 12.13 MB

Node.js and GCP In Action - Node.js和GCP实战

License: MIT License

TypeScript 16.19% Shell 3.62% JavaScript 71.15% HTML 2.91% CSS 0.21% Dockerfile 0.65% Makefile 0.16% Pug 5.11%
gcp gcp-cloud-functions gcp-pubsub gcp-storage google-cloud-platform google-cloud-functions google-app-engine google-cloud-pubsub google-cloud-sql google-compute-engine google-kubernetes-engine

nodejs-gcp's Introduction

nodejs-gcp's People

Contributors

dependabot[bot] avatar mrdulin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nodejs-gcp's Issues

Retry cloud function specific times using google-pubsub and send last retry error message to deadletter topic

需求:当cloud function调用第三方api出现异常时,使用google-pubsub重新尝试调用该cloud function,尝试调用指定的次数,并将每一次出现的异常error及相关数据发送到google-pubsubdeadletter topic

Here is version 1 logs:

image

Here is version 2 logs:

image

参考:

https://medium.com/google-cloud/dead-letter-queues-simple-implementation-strategy-for-cloud-pub-sub-80adf4a4a800

ApiError: The combination of locationConstraint and storageClass you provided is not supported for your project

创建cloud storagebucket时报错:

ApiError: The combination of locationConstraint and storageClass you provided is not supported for your project

原因是location参数设置错误,错误的代码:

async function main() {
  const buckets = await getBuckets();
  logger.info(JSON.stringify(buckets));
  const bucketName = 'nodejs-gcp';
  await createBucket(bucketName, {
    regional: true,
    location: 'ASIA'
  });
}

修改后的代码:

async function main() {
  const buckets = await getBuckets();
  logger.info(JSON.stringify(buckets));
  const bucketName = 'nodejs-gcp';
  await createBucket(bucketName, {
    regional: true,
    location: 'asia-east1'
  });
}

GCP控制台查看:

image

nodejs的客户端代码的location设置的是上图中红线区域中的值。

ERROR: (gcloud.beta.functions.deploy) argument --entry-point

执行:

gcloud beta functions deploy --entry-point=./index.js --trigger-resource ${TOPIC} --trigger-event google.pubsub.topic.publish

报错:

ERROR: (gcloud.beta.functions.deploy) argument --entry-point: Invalid value './index.js': Entry point name must contain only Latin letters (lower- or upper-case), digits, dot (.) and underscore (_), and must be at most 128 characters long. It can neither begin nor end with a dot (.), nor contain two consecutive dots (..).
Usage: gcloud beta functions deploy NAME [optional flags]
  optional flags may be  --clear-labels | --entry-point | --help | --memory |
                         --region | --remove-labels | --retry | --source |
                         --stage-bucket | --timeout | --trigger-bucket |
                         --trigger-event | --trigger-http | --trigger-resource |
                         --trigger-topic | --update-labels

For detailed information on this command and its flags, run:
  gcloud beta functions deploy --help

GAE部署时只能使用8080端口

GAE的配置文件app.yaml中无法通过env_variables设置PORT为非8080端口

访问GAE应用的日志:

image

通过日志输出看到,尽管程序是运行起来了,但是在浏览器访问路由/时,一直处于pending状态

image

You can define additional environment variables in your app.yaml file, but the above values cannot be overridden.

根据官方文档描述,不能修改PORT端口为非8080端口,PORT环境变量不能被非8080的其他值重写。

部署时正确配置应该如下,或者省略PORTPORT默认为8080

runtime: nodejs8
service: standard-env-work-with-webpack-success
env_variables:
  NODE_ENV: production
  PORT: 8080

参考:

Error: 3 INVALID_ARGUMENT: Log entry with size 555.6K exceeds maximum size of 256.0K

Error: 3 INVALID_ARGUMENT: Log entry with size 555.6K exceeds maximum size of 256.0K
at Object.exports.createStatusError (/app/node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (/app/node_modules/grpc/src/client_interceptors.js:1204:28)
at InterceptingListener._callNext (/app/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/app/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/app/node_modules/grpc/src/client_interceptors.js:845:24)

原因:https://cloud.google.com/logging/quotas

background GCF中使用setTimeout配合pubsub进行重试会导致该GCF超时

需求:定时调用GCF

思路1:在GCF中使用setTimeout作为定时器,使用google pubsub再次publish消息到触发该GCFTOPIC

当设置GCF的超时时间为10秒,通过环境变量指定setTimeout的时间为15秒,会导致GCF超时。

image

GCF超时日志:

image

还有一个问题是,在GCF中使用setTimeout会导致该GCF一直处在执行过程中,这样会导致费用上升,因为GCF的是根据调用次数和执行时间来收费的。

参考:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.