GithubHelp home page GithubHelp logo

abtest's Introduction

Feature

  • 灰度

    • 将多个灰度规则组合成一条灰度策略,支持无限扩展。参见com.springframework.toolkit.abtest.AbTestFactory.AbTestFacade
  • 分流

    • 支持取模、哈希取模、随机取模等分流设置,支持自定义分流方法。参见com.springframework.toolkit.abtest.div.DivMethods

Quick Start

Step1: 配置灰度分流规则

  • 策略1

    • 当且仅当 渠道source IN ["2","21"] 和 城市city IN ["1", "5"]时,命中灰度规则;分流 50%
  • 策略2

    • 当且仅当 渠道source IN ["1"] 和 城市city IN ["3"]时,命中灰度规则;分流 100%
[
  {
    "layer": {
      "id": "layer1",
      "data": "something1"
    },
    "grayRules": [
      {
        "name": "source",
        "enabled": true,
        "include": [
          "2",
          "21"
        ],
        "exclude": [],
        "global": false
      },
      {
        "name": "city",
        "enabled": true,
        "include": [
          "1",
          "5"
        ],
        "exclude": [],
        "global": false
      }
    ],
    "divRule": {
      "percent": 50
    }
  },
  {
    "layer": {
      "id": "layer2",
      "data": "something2"
    },
    "grayRules": [
      {
        "name": "source",
        "enabled": true,
        "include": [
          "1"
        ],
        "exclude": [],
        "global": false
      },
      {
        "name": "city",
        "enabled": true,
        "include": [
          "3"
        ],
        "exclude": [],
        "global": false
      }
    ],
    "divRule": {
      "percent": 100
    }
  }
]

Step2: 读取配置、校验规则

// 当前请求上下文
String source = "2";
String cityId = "3";
String uid = "abc123"; 

  
// 1、加载配置文件: 可以从配置中心或存储读取
String conf = "[{\"layer\":{\"id\":\"layer1\",\"data\":\"something1\"},\"grayRules\":[{\"name\":\"source\"," +
                "\"enabled\":true,\"include\":[\"2\",\"21\"],\"exclude\":[],\"global\":false},{\"name\":\"city\"," +
                "\"enabled\":true,\"include\":[\"1\",\"5\"],\"exclude\":[],\"global\":false}]," +
                "\"divRule\":{\"percent\":50}},{\"layer\":{\"id\":\"layer2\",\"data\":\"something2\"}," +
                "\"grayRules\":[{\"name\":\"source\",\"enabled\":true,\"include\":[\"1\"],\"exclude\":[]," +
                "\"global\":false},{\"name\":\"city\",\"enabled\":true,\"include\":[\"3\"],\"exclude\":[]," +
                "\"global\":false}],\"divRule\":{\"percent\":100}}]";
                
  
AbTestFactory.AbTestFacade facade = AbTestFactory.build(conf);  

  
// 2、链式校验是否命中灰度规则和分流规则
DivResult result = facade.hitGray(GrayPoints.source(source))
                         .peek(System.out::println)
                         .hitGray(GrayPoints.city(cityId))
                         .peek(System.out::println)
                         .hitDiv(DivMethods.hashMod(uid)); // 按hash(uid) % 100 分流

if (result.isHit()) {
    // do something
}                              

abtest's People

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.