Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add retry_timeout for upstream #2106

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/conf/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@
"minimum": 0,
"type": "integer"
},
"retry_timeout": {
"minimum": 0,
"type": "integer"
},
"scheme": {
"default": "http",
"enum": ["grpc", "grpcs", "http", "https"]
Expand Down Expand Up @@ -1182,6 +1186,10 @@
"minimum": 0,
"type": "integer"
},
"retry_timeout": {
"minimum": 0,
"type": "integer"
},
"scheme": {
"default": "http",
"enum": ["grpc", "grpcs", "http", "https"]
Expand Down Expand Up @@ -1753,6 +1761,10 @@
"minimum": 0,
"type": "integer"
},
"retry_timeout": {
"minimum": 0,
"type": "integer"
},
"scheme": {
"default": "http",
"enum": ["grpc", "grpcs", "http", "https"]
Expand Down Expand Up @@ -2135,6 +2147,10 @@
"minimum": 0,
"type": "integer"
},
"retry_timeout": {
"minimum": 0,
"type": "integer"
},
"scheme": {
"default": "http",
"enum": ["grpc", "grpcs", "http", "https"]
Expand Down Expand Up @@ -4671,6 +4687,10 @@
"minimum": 0,
"type": "integer"
},
"retry_timeout": {
"minimum": 0,
"type": "integer"
},
"scheme": {
"default": "http",
"enum": ["grpc", "grpcs", "http", "https"]
Expand Down
1 change: 1 addition & 0 deletions api/internal/core/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ type UpstreamTLS struct {
type UpstreamDef struct {
Nodes interface{} `json:"nodes,omitempty"`
Retries int `json:"retries,omitempty"`
RetryTimeout int `json:"retry_timeout,omitempty"`
Timeout interface{} `json:"timeout,omitempty"`
Type string `json:"type,omitempty"`
Checks interface{} `json:"checks,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/test/e2enew/upstream/upstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() {
Path: "/apisix/admin/upstreams/u2",
Body: `{
"retries": 1,
"retry_timeout":3,
"timeout": {
"connect":15,
"send":15,
Expand Down
2 changes: 2 additions & 0 deletions docs/en/latest/api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ user login.
| nodes | object | | No |
| pass_host | string | | No |
| retries | long | | No |
| retry_timeout | long | | No |
| service_name | string | | No |
| timeout | object | | No |
| type | string | | No |
Expand All @@ -403,6 +404,7 @@ user login.
| nodes | object | | No |
| pass_host | string | | No |
| retries | long | | No |
| retry_timeout | long | | No |
| service_name | string | | No |
| timeout | object | | No |
| type | string | | No |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-undef */

context('Create Upstream With retry_timeout', () => {
const selector = {
name: '#name',
nodes_0_host: '#nodes_0_host',
nodes_0_port: '#nodes_0_port',
nodes_0_weight: '#nodes_0_weight',
retry_timeout: '#retry_timeout',
input: ':input',
notification: '.ant-notification-notice-message',
nameSelector: '[title=Name]',
upstreamType: '.ant-select-item-option-content',
drawer: '.ant-drawer-content',
monacoScroll: '.monaco-scrollable-element',
description: '#desc',
};
const data = {
upstreamName: 'test_upstream',
description: 'desc_by_autotest',
ip1: '127.0.0.1',
createUpstreamSuccess: 'Create Upstream Successfully',
deleteUpstreamSuccess: 'Delete Upstream Successfully',
port0: '7000',
weight0: '2',
port1: '7001',
weight1: '2',
retry_timeout: '3',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since retry_timeout has been defined, we can use it in the Line60, the same goes for other test data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is only a variable defined in data that can be used, but I don't use it, is that right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you define a variable, it would be better to use it, or this variable is useless here

};
beforeEach(() => {
cy.login();
});
it('should create upstream with retry_timeout (roundrobin)', function () {
cy.visit('/');
cy.contains('Upstream').click();
cy.contains('Create').click();

cy.get(selector.name).type(data.upstreamName);
cy.get(selector.description).type(data.description);

cy.get(selector.nodes_0_host).type(data.ip1);
cy.get(selector.nodes_0_port).clear().type('7000');
cy.get(selector.nodes_0_weight).clear().type(1);
cy.get(selector.retry_timeout).clear().type(data.retry_timeout);
cy.get('#custom_checks_active').click();
cy.get('#checks_active_port').clear();
cy.contains('Next').click();
cy.get(selector.input).should('be.disabled');
cy.contains('Submit').click();
cy.get(selector.notification).should('contain', data.createUpstreamSuccess);
cy.contains(data.createUpstreamSuccess);
cy.url().should('contains', 'upstream/list');
});
it('should view the (roundrobin) upstream with retry_timeout', function () {
cy.visit('/');
cy.contains('Upstream').click();

cy.get(selector.nameSelector).type(data.upstreamName);
cy.contains('Search').click();
cy.contains(data.upstreamName).siblings().contains('View').click();
cy.get('.ant-drawer-content').should('be.visible');

cy.get(selector.monacoScroll).within(() => {
cy.contains(data.retry_timeout).should('exist');
cy.contains('nodes').should('exist');
cy.contains('roundrobin').should('exist');
cy.contains(data.upstreamName).should('exist');
});
});
it('should delete the upstream', function () {
cy.visit('/');
cy.contains('Upstream').click();
cy.contains(data.upstreamName).siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(selector.notification).should('contain', data.deleteUpstreamSuccess);
});
});
2 changes: 2 additions & 0 deletions web/src/components/Upstream/UpstreamForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Timeout from './components/Timeout';
import Type from './components/Type';
import UpstreamSelector from './components/UpstreamSelector';
import Retries from './components/Retries';
import RetryTimeout from './components/RetryTimeout'
import PassHost from './components/PassHost';
import TLSComponent from './components/TLS';
import { convertToRequestData } from './service';
Expand Down Expand Up @@ -290,6 +291,7 @@ const UpstreamForm: React.FC<Props> = forwardRef(

<PassHost form={form} readonly={readonly} />
<Retries readonly={readonly} />
<RetryTimeout readonly={readonly}/>

<Scheme readonly={readonly} />
<Form.Item noStyle shouldUpdate={(prev, next) => prev.scheme !== next.scheme}>
Expand Down
38 changes: 38 additions & 0 deletions web/src/components/Upstream/components/RetryTimeout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { Form, InputNumber } from 'antd';
import { useIntl } from 'umi';

type Props = {
readonly?: boolean;
};

const Component: React.FC<Props> = ({ readonly }) => {
const { formatMessage } = useIntl();
return (
<Form.Item
label={formatMessage({ id: 'component.upstream.fields.retry_timeout' })}
tooltip={formatMessage({ id: 'component.upstream.fields.retry_timeout.tooltip' })}
name="retry_timeout"
>
<InputNumber disabled={readonly} />
</Form.Item>
);
};

export default Component;
4 changes: 4 additions & 0 deletions web/src/components/Upstream/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default {
'component.upstream.fields.retries.tooltip':
'The retry mechanism sends the request to the next upstream node. A value of 0 disables the retry mechanism and leaves the table empty to use the number of available backend nodes.',

'component.upstream.fields.retry_timeout': 'Retry Timeout',
'component.upstream.fields.retry_timeout.tooltip':
'Limit the retry time to avoid spending too much time retrying requests. A value of 0 disables the retry timeout mechanism',

'component.upstream.fields.checks.active.type': 'Type',
'component.upstream.fields.checks.active.type.tooltip':
'Whether to perform active health checks using HTTP or HTTPS, or just attempt a TCP connection.',
Expand Down
4 changes: 4 additions & 0 deletions web/src/components/Upstream/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default {
'component.upstream.fields.retries.tooltip':
'重试机制将请求发到下一个上游节点。值为 0 表示禁用重试机制,留空表示使用可用后端节点的数量。',

'component.upstream.fields.retry_timeout': '重试超时时间',
'component.upstream.fields.retry_timeout.tooltip':
'限制是否继续重试的时间,若之前的请求和重试请求花费太多时间就不再继续重试。`0` 代表不启用重试超时机制。',

'component.upstream.fields.checks.active.type': '类型',
'component.upstream.fields.checks.active.type.tooltip':
'是使用 HTTP 或 HTTPS 进行主动健康检查,还是只尝试 TCP 连接。',
Expand Down
1 change: 1 addition & 0 deletions web/src/components/Upstream/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ declare namespace UpstreamComponent {
type ResponseData = {
nodes?: Node[];
retries?: number;
retry_timeout?: number;
timeout?: Timeout;
tls?: TLS;
type?: string;
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/Upstream/typing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ declare namespace UpstreamModule {
key?: string;
checks?: HealthCheck;
retries?: number;
retry_timeout?: number;
enable_websocket?: boolean;
timeout?: Timeout;
name?: string;
Expand Down