• openresty + gor+minio 集成


    以前有写过简单的容器集成,以下是关于s3集成的,主要是测试数据的捕捉以及回放

    参考流程


    简单说明
    gor 与openresty 部署在一起,为了方便基于supervisord 管理,默认已经开启请求捕捉(80端口),同时supervisord集成了管理,可以通过ui操作是否捕捉
    对于捕捉的数据存储在minio s3中,如果需要回放操作,我们直接可以基于gor tools 将存储的数据回放给需要测试的服务

    环境准备

    • docker-compose 文件
     
    version: "3"
    services: 
      minio: 
        image: minio/minio
        command: server /data
        volumes: 
        - "./data:/data"
        ports: 
        - "9000:9000"
        environment:
          - "MINIO_ACCESS_KEY=minio"
          - "MINIO_SECRET_KEY=minio123"
      api:
        image: dalongrong/openresty-gor:s3
        build: 
          dockerfile: ./Dockerfile-openresty
          context: ./
        privileged: true
        cap_add: 
        - ALL
        volumes:
        - "./supervisor.conf:/etc/supervisord.conf"
        - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
        - "./demoapps:/opt/demoapps"
        - "./capture:/app/capture"
        - "./logs/access-test.log:/usr/local/openresty/nginx/logs/access-test.log"
        ports:
        - "80:80"
        - "8080:8080"
        - "9001:9001"
    • supervisord.conf 配置
    [program:website]
    command = /usr/local/openresty/bin/openresty
    [inet_http_server]
    port = :9001
    [program:gor]
    # 此处需要指定关于s3 的配置
    environment=AWS_ACCESS_KEY_ID="minio",AWS_SECRET_ACCESS_KEY="minio123",AWS_REGION="demo",AWS_ENDPOINT_URL="http://minio:9000",AWS_DEBUG="true"
    stdout_logfile = gor.log, /dev/stdout
    command = gor --input-raw :80  --output-file s3://logs/%Y-%m-%d-%H-%M.gz
    • openresty+gor dockerfile
      添加了时区以及gor+supervisord的集成
     
    FROM openresty/openresty:alpine
    ENV PATH=$PATH:/app
    RUN  /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories
    ENV TZ Asia/Shanghai
    RUN apk add --update --no-cache 
        tzdata && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    COPY --from=dalongrong/gor /app/gor /app/gor
    COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord
    EXPOSE 9001 8080 80
    COPY supervisor.conf /etc/supervisor.conf
    CMD ["/usr/local/bin/supervisord"]
    • 启动
    docker-compose up -d
    • s3 bucket 创建
      需要创建logs(和自己使用gor 的配置有关系)

    测试效果

    • supervisord 管理界面
      我们可以通过此管理界面控制gor 是否进行数据捕捉

    • minio 存储

     

    • 回放

      我使用了本地工具,同时注意需要配置关于s3的信息

     
    export AWS_ACCESS_KEY_ID=minio
    export AWS_REGION=demo
    export AWS_SECRET_ACCESS_KEY=minio123
    export AWS_ENDPOINT_URL=http://127.0.0.1:9000
    export AWS_DEBUG=true
    ./gor-mac --input-file s3://logs/2020-07-20-10-19_13.gz   --output-http "http://localhost" 

    对于回放效果的查看可以通过查看openresty 的log

    类似可以集成的工具

    mountebank(可以mock http,https,tcp,smtp),diffy (请求比较,主要是http)
    hoverfly 一个不错的流量处理工具,nginx 的mirrror也是一个不错的选择

    说明

    以上只是一个简单的集成试用,实际如果我们需要基于捕捉的数据进行业务操作回放,还有好多事情需要做

    参考资料

    https://github.com/buger/goreplay
    https://github.com/opendiffy/diffy
    https://github.com/bbyars/mountebank
    https://github.com/spectolabs/hoverfly
    https://github.com/rongfengliang/openresty_rewrite_static/tree/gor

  • 相关阅读:
    git commit之后,想撤销commit
    centOS7下ifconfig提示command not found
    图数据库 — neo4j (二)
    XQuery的 value() 方法、 exist() 方法 和 nodes() 方法
    SQL存储过程-新增和修改,参数Xml数据类型
    项目管理软件之易度1.5,禅道2.0,redmine1.2(附redmine1.2的安装)
    测试性能工具
    存储过程
    人生三支点:健康,职业,自由
    生活网站推荐
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/13344164.html
Copyright © 2020-2023  润新知