@adobe/helix-status

中文文档
10.1.5发布于 2024/12/07Apache-2.0ES Module近 30 天下载 5878

Report status for OpenWhisk Microservices for Uptime checks with Pingdom or New Relic

原始使用文档
文档目录10 节
  1. Status
  2. Problem
  3. Solution
  4. Installation
  5. Usage
  6. Usage with Probot
  7. Request Options
  8. Custom Status Check Function
  9. Request Options with Dynamic Values
  10. Deploying Helix Status

Helix Status

Report status for OpenWhisk Microservices for New Relic (and others) Uptime (HTTP) checks

Status

codecov CircleCI GitHub license GitHub issues LGTM Code Quality Grade: JavaScript semantic-release

Problem

You have a microservice that is deployed as an OpenWhisk HTTP action or even a number of these microservices and you want to establish monitoring of service uptime using New Relic.

In case the service is down, you want to quickly understand if it is a problem with

  • the OpenWhisk runtime, which may be unreachable or overloaded
  • one of your backend API providers which might be unreachable
  • your own service which could be broken (for instance due to a deployment change)

Finally, you know that there are New Relic Synthetics but you do not want to keep repeating the same code for returning a status check in each of your micro services.

Solution

helix-status is a library that allows you to wrap your own actions to get a standardized monitoring response

Installation

$ npm install -S @adobe/helix-status

Usage

In the entry point of your action, add

const { helixStatus } = require('@adobe/helix-status');

to the top of your file and override the module.exports.main with:

module.exports.main = helixStatus(main);

All GET /_status_check/healthcheck.json requests to your service will now respond with an XML response similar to below:

{
  "status": "OK",
  "version": "1.5.4",
  "response_time": 6,
  "process": {}
}

You can also specify a list of checks to run by passing second argument to wrap:

module.exports.main = helixStatus(main, { example: 'http://www.example.com'})

you will then see results like this:

{
  "status": "OK",
  "version": "1.5.4",
  "response_time": 249,
  "process": {
    "activation": "7ef3047190924313b3047190923313e9"
  },
  "example": 247
}

It is a good idea to use URLs that are representative of the API endpoints your service is calling in normal operation as checks.

Usage with Probot

If you are using Probot for instance through Serverless Probot on OpenWhisk, the usage is slightly different:

// import the probot status app
const { probotStatus } = require('@adobe/helix-status');

probot
  .withApp(yourApp)
  .withApp(probotStatus()) //add a status check app 

probotStatus() accepts the same checks object that has been described above, so you can pass an array of URL checks.

Usage with New Relic Synthetics

New Relic Synthetics is a service that is similar to Pingdom. It can be used with helix-status by creating an API Check script like this:

const assert = require('assert');

// replace the URL with your check URL
$http.get('https://adobeioruntime.net/api/v1/web/helix/helix-services/status@v3/_status_check/heathcheck.json',
  // Callback
  function (err, response, body) {
    assert.equal(response.statusCode, 200, 'Expected a 200 OK response');
    const health = JSON.parse(body);
    assert.equal(health.status, 'OK', 'Expected an OK health check status');
    for (const v in health) {
      if (['status', 'process', 'version'].indexOf(v)===-1) {
        $util.insights.set(v, parseInt(health[v]));
      }
    }
    for (const h in ['x-openwhisk-activation-id', 'x-request-id', 'x-version']) {
      $util.insights.set(h, response.headers[h]);
    }
  }
);

Advanced Checks

By default, helix-status will take a map of URLs and make a GET request for each URL provided. In some scenarios, you need to provide additional detail to craft the request and helix-status supports three types of advanced checks for that:

Request Options

If you need to adjust things like request method (from GET to POST) or set request headers (e.g. Accept), instead of providing a URL as string, you can provide a request options object, according to the request/request documentation.

Make sure not to forget the uri.

module.exports.main = wrap(main, 
  { example: {
    uri: 'http://www.example.com',
    method: 'POST',
    headers: {
      accept: 'application/json'
    }
  }});

Custom Status Check Function

For more advanced use cases, you can provide a function in your checks. This function will be executed with the params of your OpenWhisk function when requested with the status check or health check URLs.

Keep in mind that the check function should execute reasonably fast, but it can be async.

module.exports.main = wrap(main, 
  { example: function(params) => params.foo === params.bar });

Request Options with Dynamic Values

A combination of the two techniques above is the usage of request options with Dynamic Values. This can be used if you need to populate properties of the request object or request headers with values provided in the params of the execution.

A typical example would be making a call to an API that requires an API key, where the API key would be stored in the default parameters of the OpenWhisk action.

To achieve this, provide a request options object as described in Request Options, but note that values both of the options and the options.headers object can be functions. Each property that is a function will be replaced with the value that function returns when called with the action's parameters.

module.exports.main = wrap(main, 
  { example: {
    uri: 'http://www.example.com',
    method: 'POST',
    headers: {
      accept: 'application/json',
      authorization: params => `Bearer ${params.EXAMPLE_API_TOKEN}`
    }
  }});

The example above shows how to extract the EXAMPLE_API_TOKEN value from the action's (default) parameters and applies it to the Authorization header.

Status Codes

The health check reports following HTTP status codes:

  • 200 (OK): all health checks performed successfully
  • 504 (Gateway Timeout): the health check took too long to execute
  • 502 (Gateway Error): the health check got an error response from the checked URL
  • 500 (Server Error): the generic check function did not execute successfully

Development

Deploying Helix Status

Deploying Helix Status requires the wsk command line client, authenticated to a namespace of your choice. For Project Helix, we use the helix namespace.

All commits to main that pass the testing will be deployed automatically. All commits to branches that will pass the testing will get committed as /helix-services/status@ci<num> and tagged with the CI build number.

版本与发布记录

@adobe/helix-status 共发布 95 个版本,首次发布于 2019/08/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
10.1.5latest2024/12/071.9 年前
10.1.42024/12/051.9 年前
10.1.32024/09/222 年前
10.1.22024/06/072 年前
10.1.12024/06/072 年前
10.1.02024/06/042 年前

关于 @adobe/helix-status 的常见问题

@adobe/helix-status 是什么?

Report status for OpenWhisk Microservices for Uptime checks with Pingdom or New Relic

如何安装 @adobe/helix-status?

在项目目录运行 npm install @adobe/helix-status,或使用 pnpm add / yarn add / bun add。

@adobe/helix-status 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adobe__helix-status 是否存在。

@adobe/helix-status 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adobe/helix-status 可以商用吗?

@adobe/helix-status 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/helix-status 的下载量有多少?

根据 npm 官方下载统计,@adobe/helix-status 在 2026/10/05 – 2026/11/03 这 30 天内被下载 5,878 次,日均约 196 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/helix-status 还在维护吗?

最新版本 10.1.5 发布于 2024/12/07(1.9 年前);至今共发布 95 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/08/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。