npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arextest/arex-node-agent

v0.0.3-beta.16

Published

Arex node agent

Downloads

1,299

Readme

背景

arex nodejs-agent 实现

环境

  1. js
  2. monkey patch
  3. rollup 打包
  4. ctrip npm 部署
  5. npm
  6. node v18
  7. semver

v1 内容

  • 支持入口为express的api
  • 支持http wrap
  • 支持knex db wrap
  • 支持上下文录制回放交互
  • 预留arex api mock

项目结构

  • 模块agent: nodeagent实现逻辑
  • 模块app: 目标应用
  • 模块app/instrumentation.js: 启动中间件

启动node-agent

  • 自定义中间件启动器,按需配置中间件 参考 app/instrumentation node --require ./instrumentation.js index.js
  • 通过arex-runner启动agent
    1. 环境变量指定appid,host
    2. 平台配置更多中间件
    3. app/Dockerfile CMD ["node", "--require", "--require @arextest/arex-node-agent/dist/runner.js", "index.js"]
  • 调试本地agent debug: DEBUG=@arextest:* node --require ./instrumentation_local.js index.js

实现

  • 代理流程
  1. 初始化配置
  2. 代理一个入口函数 生成上下文context,store
  3. 装载入口函数
  4. 装载函数调用的io,自定义装载等
    • 加载context
    • 录制/回放
    • 存储/加载
    • 结束
  5. 线程结束
    • 卸载patch

案例 - express 请求一个 updateUser 接口

录制操作

  1. Express 中间件
    • 创建recordId
    • 调用client.saveRecord
    • 保存updateUser请求的request, response信息
  2. service 被测代码逻辑
    • 调用client.saveRecord
    • 保存service.updateUserName 的request, response信息

回放操作

  1. Express 中间件
    • 适配回放标识 arex-record-id
    • 创建replayId
    • 调用client.queryRecord
    • 查询并提交updateUser请求的request,response信息
  2. service 被测代码逻辑
    • 调用client.queryRecord
    • 查询service.updateUserName 的request, response信息
    • 替换方法的返回结果

发布

v1.0.6

  1. 提取静态字段
  2. 修复option读取失败 v1.0.10
  3. 支持mysql2

参考

  1. 演练场 /jagong/node-agent-payload/-/tree/main/node_arex_agent
  2. npm 发布流程
  • 申请权限
  • npm login --registry https://registry.npmjs.org
  • npm publish --registry https://registry.npmjs.org --access=public
  1. mock http :Nock 或 Sinon 等库来进行请求拦截和模拟响应