Service Isolation Design

  1. Linkis now performs load balancing based on the ribbon when it forwards services in the Gateway, but in some cases, there are some important business tasks that want to achieve service level isolation, if the service is based on the ribbon There will be problems in equilibrium. For example, tenant A wants his tasks to be routed to a specific Linkis-CG-Entrance service, so that when other instances are abnormal, the Entrance of service A will not be affected. In addition, tenants and isolation of support services can also quickly isolate an abnormal service and support scenarios such as grayscale upgrades.
  1. Support forwarding the service according to the routing label by parsing the label of the request
  2. Tag Registration and Modification of Support Services

    This feature adds two modules, linkis-mg-gateway and instance-label, which are mainly modified points, designed to add the forwarding logic of Gateway, and instance-label to support services and labels register.

    The overall technical architecture mainly modifies the point. The RestFul request needs to carry label parameter information such as routing label, and then the corresponding label will be parsed when the Gateway forwards to complete the route forwarding of the interface. The whole is shown in the figure below arc

A few notes:

  1. If there are multiple corresponding services marked with the same roteLabel, it will be forwarded randomly
  2. If the corresponding routeLabel does not have a corresponding service, the interface fails directly
  3. If the interface does not have a routeLabel, based on the original forwarding logic, it will not route to the service marked with a specific label

    This feature is mainly to complete the Restful tenant isolation and forwarding function. The modules designed by the function point are as follows:

Component nameFirst-level moduleSecond-level moduleFunction point
LinkisMGGatewayParse the route label in the restful request parameters, and complete the forwarding function of the interface according to the route label
LinkisPSInstanceLabelInstanceLabel service, completes the association between services and labels

[Input] The input is the restful request requesting Gatway, and only the request with the roure label to be used in the parameter will be processed. [Processing process] The Gateway will determine whether the request has a corresponding RouteLabel, and if it exists, it will be forwarded based on the RouteLabel. The call sequence diagram is as follows:

Time

  1. DROP TABLE IF EXISTS `linkis_ps_instance_label`;
  2. CREATE TABLE `linkis_ps_instance_label` (
  3. `id` int(20) NOT NULL AUTO_INCREMENT,
  4. `label_key` varchar(32) COLLATE utf8_bin NOT NULL COMMENT 'string key',
  5. `label_value` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'string value',
  6. `label_feature` varchar(16) COLLATE utf8_bin NOT NULL COMMENT 'store the feature of label, but it may be redundant',
  7. `label_value_size` int(20) NOT NULL COMMENT 'size of key -> value map',
  8. `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update unix timestamp',
  9. `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update unix timestamp',
  10. PRIMARY KEY (`id`),
  11. UNIQUE KEY `label_key_value` (`label_key`,`label_value`)
  12. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
  13. DROP TABLE IF EXISTS `linkis_ps_instance_info`;
  14. CREATE TABLE `linkis_ps_instance_info` (
  15. `id` int(11) NOT NULL AUTO_INCREMENT,
  16. `instance` varchar(128) COLLATE utf8_bin DEFAULT NULL COMMENT 'structure like ${host|machine}:${port}',
  17. `name` varchar(128) COLLATE utf8_bin DEFAULT NULL COMMENT 'equal application name in registry',
  18. `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'update unix timestamp',
  19. `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'create unix timestamp',
  20. PRIMARY KEY (`id`),
  21. UNIQUE KEY `instance` (`instance`)
  22. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
  23. DROP TABLE IF EXISTS `linkis_ps_instance_label_relation`;
  24. CREATE TABLE `linkis_ps_instance_label_relation` (
  25. `id` int(20) NOT NULL AUTO_INCREMENT,
  26. `label_id` int(20) DEFAULT NULL COMMENT 'id reference linkis_ps_instance_label -> id',
  27. `service_instance` varchar(128) NOT NULL COLLATE utf8_bin COMMENT 'structure like ${host|machine}:${port}',
  28. `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'update unix timestamp',
  29. `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'create unix timestamp',
  30. PRIMARY KEY (`id`)
  31. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
  1. echo "spring.eureka.instance.metadata-map.route=et1" >> $LINKIS_CONF_DIR/linkis-cg-entrance.properties
  2. sh $LINKIS_HOME/sbin/linkis-damemon.sh restart cg-entrance

Time

submit task:

  1. url:/api/v1/entrance/submit
  2. {
  3. "executionContent": {"code": "echo 1", "runType": "shell"},
  4. "params": {"variable": {}, "configuration": {}},
  5. "source": {"scriptPath": "ip"},
  6. "labels": {
  7. "engineType": "shell-1",
  8. "userCreator": "peacewong-IDE",
  9. "route": "et1"
  10. }
  11. }

will be routed to a fixed service:

  1. {
  2. "method": "/api/entrance/submit",
  3. "status": 0,
  4. "message": "OK",
  5. "data": {
  6. "taskID": 45158,
  7. "execID": "exec_id018030linkis-cg-entrancelocalhost:9205IDE_peacewong_shell_0"
  8. }
  9. }

or linkis-cli:

  1. sh bin/linkis-cli -submitUser hadoop -engineType shell-1 -codeType shell -code "whoami" -labelMap route=et1 --gatewayUrl http://127.0.0.1:9101

submit task:

  1. url:/api/v1/entrance/submit
  2. {
  3. "executionContent": {"code": "echo 1", "runType": "shell"},
  4. "params": {"variable": {}, "configuration": {}},
  5. "source": {"scriptPath": "ip"},
  6. "labels": {
  7. "engineType": "shell-1",
  8. "userCreator": "peacewong-IDE",
  9. "route": "et1"
  10. }
  11. }

will get the error

  1. {
  2. "method": "/api/rest_j/v1/entrance/submit",
  3. "status": 1,
  4. "message": "GatewayErrorException: errCode: 11011 ,desc: Cannot route to the corresponding service, URL: /api/rest_j/v1/entrance/submit RouteLabel: [{\"stringValue\":\"et2\",\" labelKey\":\"route\",\"feature\":null,\"modifiable\":true,\"featureKey\":\"feature\",\"empty\":false}] ,ip: localhost ,port: 9101 ,serviceKind: linkis-mg-gateway",
  5. "data": {
  6. "data": "{\r\n \"executionContent\": {\"code\": \"echo 1\", \"runType\": \"shell\"},\r\n \"params \": {\"variable\": {}, \"configuration\": {}},\r\n \"source\": {\"scriptPath\": \"ip\"},\r\ n \"labels\": {\r\n \"engineType\": \"shell-1\",\r\n \"userCreator\": \"peacewong-IDE\",\r\n \" route\": \"et2\"\r\n }\r\n}"
  7. }
  8. }

submit task:

  1. url:/api/v1/entrance/submit
  2. {
  3. "executionContent": {"code": "echo 1", "runType": "shell"},
  4. "params": {"variable": {}, "configuration": {}},
  5. "source": {"scriptPath": "ip"},
  6. "labels": {
  7. "engineType": "shell-1",
  8. "userCreator": "peacewong-IDE"
  9. }
  10. }
  1. will route to untagged entranceservices
  2. {
  3. "method": "/api/entrance/submit",
  4. "status": 0,
  5. "message": "OK",
  6. "data": {
  7. "taskID": 45159,
  8. "execID": "exec_id018018linkis-cg-entrancelocalhost2:9205IDE_peacewong_shell_0"
  9. }
  10. }

No security issues are involved, restful requires login authentication

It has little impact on Gateway forwarding performance, and caches the corresponding label and instance data

not involving

not involving