Disclosure of Invention
The present invention is directed to solving at least one of the problems of the prior art. Therefore, the invention provides a flow access control method, flow access control equipment and a storage medium. The flow control can be realized by using the script language, and the script file can be dynamically configured and updated by the flow-limiting control platform, so that the flow control of the scene is more accurate, a plurality of flow controls sdk are not required to be maintained, and the pressure of developers is reduced.
In a first aspect of the present invention, there is provided a flow access control method for a flow restrictor, comprising the steps of:
receiving access flow with an access request, wherein the access flow is sent by a service calling terminal and hijacked and forwarded by a flow agent;
judging whether the access request is available according to a current limiting rule in a current script file, and if the access request is unavailable, returning an unavailable result to the flow agent; if the flow agent is available, returning an available result to the flow agent; the current script file is the latest script file called by the current limiter from a flow control rule storage service, the flow control rule storage service is configured by a current limiting control platform and is used for storing an executable script file configured by the current limiting control platform, and the script file contains corresponding current limiting rules.
According to the embodiment of the invention, at least the following technical effects are achieved:
in the method, the current limiter can call the latest script file from the flow control rule storage service at any time, and flow control is carried out according to the current limiting rule, wherein the flow control rule storage service is configured by the current limiting control platform and is used for storing the executable script file configured by the current limiting control platform according to the actual situation, and the script file contains the current limiting rule configured by the current limiting control platform according to the actual situation. The method uses the script language to realize the flow control, does not need to be translated into various realization languages, reduces the maintenance cost, and can dynamically configure and update the script file by the flow limiting control platform, so that the flow control of the scene is more accurate; the method does not need to maintain various fluid controllers sdk, and can greatly reduce the pressure of developers.
According to some embodiments of the invention, further comprising the step of: and calling the latest script file stored in the flow control rule storage service at regular time, if the latest script file is different from the current script file, taking the latest script file as the current script file of the flow restrictor, and controlling the flow through the flow limit rule in the current script file.
According to some embodiments of the invention, the script file is a Lua script file.
In a second aspect of the present invention, a traffic access control method is provided, which is used for a current-limiting control platform, and includes the following steps:
configuring a flow control rule storage service, wherein the flow control rule storage service is used for storing an executable script file configured by the flow limiting control platform, and the script file comprises a corresponding flow limiting rule; the latest script file in the flow control rule storage service is called by the flow restrictor, and the flow restriction rule in the latest script file is used for flow control by the flow restrictor.
According to the embodiment of the invention, at least the following technical effects are achieved:
in the method, a flow control rule storage service capable of storing executable script files is configured through a flow limiting control platform, wherein the script files contain flow limiting rules configured by the flow limiting control platform according to actual conditions, and a current limiter can call the latest script file from the flow control rule storage service at any time and control flow according to the flow limiting rules. The method uses the script language to realize the flow control, does not need to be translated into various realization languages, reduces the maintenance cost, and can dynamically configure and update the script file by the flow limiting control platform, so that the flow control of the scene is more accurate; the method does not need to maintain various fluid controllers sdk, and can greatly reduce the pressure of developers.
According to some embodiments of the invention, further comprising the step of: and acquiring corresponding current limiting information from the current limiter and displaying the current limiting information.
According to some embodiments of the invention, the script file is a Lua script file.
In a third aspect of the present invention, there is provided a traffic access control method, which is used for a traffic broker, and includes the following steps:
the hijacking service calling end sends access flow with an access request and forwards the access flow to the current limiter;
receiving results returned by the current limiter; the current limiter is used for judging whether the access request is available according to a current limiting rule in the current script file, and if the access request is unavailable, an unavailable result is returned; if the current time is available, returning an available result; the current script file is the latest script file called by the current limiter from a flow control rule storage service, the flow control rule storage service is configured by a current limiting control platform and is used for storing an executable script file configured by the current limiting control platform, and the script file contains corresponding current limiting rules;
if the unavailable result returned by the current limiter is received, returning the unavailable result to the service calling end, and ending the access process; and if an available result returned by the current limiter is received, forwarding the access flow to the multi-tenant management service.
According to the embodiment of the invention, at least the following technical effects are achieved:
in the method, the flow is firstly hijacked by the agent to access the flow and sent to the flow limiter; secondly, a result returned by the current limiter is received, and an unavailable result is returned to the service calling end or access flow is forwarded to the multi-tenant management service according to the returned result; the flow control platform is provided with a flow control rule storage service capable of storing executable script files, the script files comprise flow limiting rules configured by the flow control platform according to actual conditions, and the flow restrictor can call the latest script file from the flow control rule storage service at any time and control flow according to the flow limiting rules. The method uses the script language to realize the flow control, does not need to be translated into various realization languages, reduces the maintenance cost, and can dynamically configure and update the script file by the flow limiting control platform, so that the flow control of the scene is more accurate; the method does not need to maintain various fluid controllers sdk, and can greatly reduce the pressure of developers.
According to some embodiments of the invention, further comprising the step of:
receiving an access result returned by the multi-tenant management service;
sending the access result to the service calling end, and ending the access process
In a fourth aspect of the present invention, there is provided a traffic access control device, including: at least one control processor and a memory for communicative connection with the at least one control processor; the memory stores instructions executable by the at least one control processor to enable the at least one control processor to perform a traffic access control method according to the first aspect of the invention, or to perform a traffic access control method according to the second aspect of the invention, or to perform a traffic access control method according to the third aspect of the invention.
In a fifth aspect of the present invention, there is provided a computer-readable storage medium storing computer-executable instructions for causing a computer to perform the traffic access control method according to the first aspect of the present invention, or perform the traffic access control method according to the second aspect of the present invention, or perform the traffic access control method according to the third aspect of the present invention.
Additional aspects and advantages of the invention will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the invention.
Detailed Description
Reference will now be made in detail to embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the accompanying drawings are illustrative only for the purpose of explaining the present invention, and are not to be construed as limiting the present invention.
Before describing the embodiments of the present application, the related terms referred to in the present application will be explained.
And the service calling end is a source of the multi-tenant access flow.
The current limiter loads a current limiting rule, records the upper limit of the allowed access times per second of a certain interface in a log printing mode; and recording the number of allowed accesses, the number of denied accesses and other detailed information at the current moment in real time, and calculating whether a certain access is allowed or denied in real time through the information.
And the multi-tenant management service is used for responding to the access flow and feeding back the access result.
And the flow agent is used for accessing the flow of the multi-tenant, intercepting the access flow, forwarding the access flow to the flow restrictor for flow control, sending the access flow to the multi-tenant management service after the flow restrictor passes the access flow, and sending the feedback access result of the multi-tenant management service to the service calling end.
And the flow limiting control platform is used for configuring a flow control rule storage service, configuring a flow limiting rule according to the flow condition in the actual production process, storing the configured flow limiting rule in the flow control rule storage service, and waiting for the call of the flow limiter.
And the flow control rule storage service is configured by the current limiting control platform and is used for storing the current limiting rule configured by the current limiting control platform and waiting for the call of the current limiter.
In order to solve the technical problems described in the background art, the present invention provides the following groups of embodiments:
a first embodiment;
referring to fig. 1, there is provided a traffic access control method for a scenario of SAAS multi-tenant traffic access control, the method including the steps of:
s101, the flow restrictor receives access flow with an access request, the access flow is sent by a service calling end, hijacked by a flow agent and forwarded to the flow restrictor.
In this step, firstly, the service calling end initiates an access request to the multi-tenant management service, the flow proxy hijacks the access flow and forwards the access flow to the current limiter, and the current limiter judges whether to allow the access flow to access or not according to the current limiting rule.
S102, the current limiter judges whether the access request is available according to a current limiting rule in the current script file, and if the access request is unavailable, an unavailable result is returned to the flow proxy; if the flow agent is available, returning an available result to the flow agent; the current script file is the latest script file called by the current limiter from the flow control rule storage service, the flow control rule storage service is configured for the flow limiting control platform and is used for storing executable script files configured for the flow limiting control platform, and the script files contain corresponding flow limiting rules.
In this step, the current limiter judges the access request according to the current limiting rule in the current script file, and returns an unavailable result to the flow proxy if the current limiting rule does not allow the access request to pass; if the current flow limiting rule allows the access request to pass through, an available result is returned to the flow agent.
Referring to fig. 2, several sets of flow limiting rules are shown below:
the first one is: and matching the POST request of the/v 1/ratelimiit/test 2 interface under the http path, wherein the header of the http contains X-H3-Engineer code and the http request with the value of C000157 (tenant number) is matched, and a token bucket algorithm is adopted for limiting the correct matching, and the access frequency is limited to 2 times per second.
A second bar: and matching the HTTP requests of the/v 1/ratelimit/test3 interface under the http path, wherein the header of the http contains X-H3-Engineer code and the value of the HTTP requests needs to be C000175 (tenant number), and if the HTTP requests are matched correctly, limiting the access times to 1 time per second by adopting a sliding window algorithm.
And a third: and matching all the requests of the/v 1/ratelimit interface under the http path, and adopting a token bucket algorithm to limit the access times to 1 time per second if the requests are matched correctly.
In this implementation, the unavailable result is marked on the returned http status code, e.g., the returned 429 status code indicates that the request was denied. If no 429 status code is returned, the request is allowed.
In this embodiment, the traffic broker uses google open source component isio implementation, and within the isio, it uses Envoy (Envoy is an open source traffic control component and provides plug-in development) component to perform traffic brokering. The following provides a set of examples of the process of hijacking access traffic from the traffic broker to the restrictor until the processing restrictor returns the access result:
(1) the traffic broker hijacks the http request using the envoyFilter (the plug-in is loaded by the Envoy to realize hijacking the access traffic to the restrictor), wherein the EnvoyFilter internally configures the IP address and the port number of the restrictor.
(2) For a hijacked http request, it is forwarded to the restrictor.
(3) And obtaining a result returned by the current limiter, if the returned result is equal to 429, indicating that the request is rejected, directly returning 429 an error code to the service calling terminal, and not sending the request to the multi-tenant management service, otherwise, allowing the request, and enabling the access flow to enter the multi-tenant management service.
In this embodiment, the current script file in the current limiter is the latest script file stored in the called flow control rule storage service, and the current script file includes the corresponding current limiting rule. The flow control platform configures a flow control rule storage service first, and the flow control rule storage service is used for storing executable script files. As an optional implementation manner, the flow-limiting control platform converts a flow-limiting rule pre-configured according to an actual flow situation into a script file with a corresponding script language through a Freemarker, then stores the converted script file in a flow-control rule storage service, and waits for the invocation of a flow limiter; wherein freemaker is a tool that is based on template files and current limiting rules and used to generate output text (HTML, email, configuration files, source code, etc.). The current limiter calls the latest script file stored by the flow control rule storage service, and then the current limiting rule in the script file is used as the current limiting rule of the current limiter based on the language interpreter of the current limiter, so that the current flow control is realized.
In the method, a flow control platform first configures a flow control rule storage service capable of storing an executable script file, where the script file includes a flow limit rule configured by the flow control platform according to an actual situation, and a flow restrictor can call a latest script file from the flow control rule storage service at any time and perform flow control according to the flow limit rule. The method uses the script language to realize the flow control, does not need to be translated into various realization languages, reduces the maintenance cost, and can dynamically configure and update the script file by the flow limiting control platform, so that the flow control of the scene is more accurate; the method does not need to maintain various fluid controllers sdk, and can greatly reduce the pressure of developers.
It should be noted that, in the present embodiment and the subsequent embodiments, a scenario of SAAS multi-tenant traffic access control is taken as an example, but the method of the present embodiment is not only applicable to SAAS multi-tenant flow control management, but also applicable to flow control management of general services. Therefore, taking the scenario of SAAS multi-tenant traffic access control as an example, the scope of protection of the present application cannot be limited.
As an optional implementation, the method further comprises the following steps:
and the current limiter periodically calls the latest script file stored in the flow control rule storage service, and if the latest script file is different from the current script file, the latest script file is used as the current script file of the current limiter, and flow control is performed through the flow limiting rule in the current script file.
In this embodiment, the current limiter is a latest script file stored in the flow control rule storage service by timing calling, and a specific time is not set here and can be selected according to actual conditions. Referring to fig. 3, in this embodiment, each script file has a corresponding version number as an identification, and the current limiter locally records the version number of the current script file. The current limiter can compare the current script file with the latest version number of the script file in the called flow control rule storage service, and when the two version numbers are consistent, the current limiter does not need to be replaced; and when the two version numbers are not consistent, the current limiter takes the current limiting rule in the latest script file stored in the flow control rule storage service as the current limiting rule of the current limiter.
As an alternative embodiment, the script file is a Lua script file. And the current limiting control platform generates a Lua script file by using a preset template file and a corresponding current limiting rule through a Freemarker. Of course, the script file may also be a python script file, etc.
A second embodiment;
referring to fig. 4, a traffic access control method is provided, which is used in a scenario of SAAS multi-tenant traffic access control, and includes the following steps:
s201, configuring a flow control rule storage service by a flow control platform, wherein the flow control rule storage service is used for storing an executable script file configured by the flow control platform, and the script file comprises a corresponding flow control rule; the latest script file in the flow control rule storage service is called by the flow restrictor, and the flow restriction rule in the latest script file is used for flow control by the flow restrictor.
In this step, the flow limiting control platform first configures a flow control rule storage service, then converts the flow limiting rules actively configured according to the actual conditions of the current flow into corresponding executable script files, and stores the executable script files in the flow control rule storage service, and the flow limiter calls the latest script file stored in the flow control rule storage service, and uses the current flow limiting rules in the current script file for flow control by using the latest script file as the current script file.
Since the process of calling the latest script file by the current limiter is described in the first embodiment, it is not described herein.
In the method, a flow control platform first configures a flow control rule storage service capable of storing an executable script file, where the script file includes a flow limit rule configured by the flow control platform according to an actual situation, and a flow restrictor can call a latest script file from the flow control rule storage service at any time and perform flow control according to the flow limit rule. The method uses the script language to realize the flow control, does not need to be translated into various realization languages, reduces the maintenance cost, and can dynamically configure and update the script file by the flow limiting control platform, so that the flow control of the scene is more accurate; the method does not need to maintain various fluid controllers sdk, and can greatly reduce the pressure of developers.
As an optional implementation manner, the method further comprises the step that the current limiting control platform acquires corresponding current limiting information from the current limiter and displays the current limiting information.
Generally, the current limiter records current limiting information such as an upper limit of the number of allowed accesses per second, the number of allowed accesses at the present time, the number of denied accesses, and the like of a certain interface by means of a printed log. In this embodiment, the current limit control platform checks and displays the current limit information of the service through the log system. Therefore, real-time monitoring of service personnel can be facilitated.
As an optional implementation manner, the script file generates a Lua script file for a FreeMarker according to a preset template file and a corresponding current limiting rule. Of course, the script file may also be a python script file, etc.
A third embodiment;
referring to fig. 5, there is provided a traffic access control method for a scenario of SAAS multi-tenant traffic access control, including the following steps:
s301, the flow agent hijacking service calling end sends access flow with an access request, and forwards the access flow to the flow limiter.
S302, the flow agent receives a result returned by the current limiter; the current limiter is used for judging whether the access request is available according to a current limiting rule in the current script file, and if the access request is unavailable, an unavailable result is returned; if the current time is available, returning an available result; the current script file is the latest script file called by the current limiter from the flow control rule storage service, the flow control rule storage service is configured for the flow limiting control platform and is used for storing executable script files configured for the flow limiting control platform, and the script files contain corresponding flow limiting rules.
S303, if an unavailable result returned by the current limiter is received, returning the unavailable result to the service calling end, and ending the access process; and if an available result returned by the current limiter is received, forwarding the access flow to the multi-tenant management service.
The traffic broker uses the Envoy component for traffic brokering, which will not be described in detail here since the first embodiment has been described in detail.
In the method, a flow agent first hijacks access flow to a current limiter; and secondly, receiving a result returned by the current limiter, and selecting to return an unavailable result to the service calling end or forward the access flow to the multi-tenant management service according to the returned result. The flow control platform is provided with a flow control rule storage service capable of storing executable script files, the script files comprise flow limiting rules configured by the flow control platform according to actual conditions, and the flow restrictor can call the latest script file from the flow control rule storage service at any time and control flow according to the flow limiting rules. The method uses the script language to realize the flow control, does not need to be translated into various realization languages, reduces the maintenance cost, and can dynamically configure and update the script file by the flow limiting control platform, so that the flow control of the scene is more accurate; the method does not need to maintain various fluid controllers sdk, and can greatly reduce the pressure of developers.
Referring to fig. 6, as an alternative embodiment, the method further includes the steps of:
s304, the flow agent receives the access result returned by the multi-tenant management service.
S305, the flow agent sends the access result to the service calling end, and the access flow is finished.
A fourth embodiment;
referring to fig. 7 and 8, a traffic access control method is provided, which is used in a scenario of SAAS multi-tenant traffic access control, and includes the steps of:
s401, configuring a flow control rule storage service by the flow control platform, wherein the flow control rule storage service is used for storing an executable Lua script file configured by the flow control platform, and the Lua script file comprises corresponding flow limit rules.
Wherein each Lua script file has a corresponding version number. And the current limiting control platform generates a Lua script file by using a preset template file and a corresponding current limiting rule through a Freemarker.
S402, the service calling terminal sends access flow with the access request.
And S403, hijacking the access flow by the flow agent, and sending the access flow to the flow limiter.
S404, the current limiter judges whether the access request is available according to the current limiting rule in the current script file, if the access request is unavailable, an unavailable result is returned to the flow proxy, and the step S405 is executed; if the access request is available, the available result is returned to the traffic broker, and the process proceeds to step S406.
The current limiter calls the latest script file stored by the flow control rule storage service at regular time, and then the current limiting rule in the script file is used as the current limiting rule of the current limiter for flow control.
In this step, if the access request is not available, then a 429 status code is returned to indicate that the request is denied; if an access request is available, then no 429 status code is returned and the request is allowed. The current limiter regularly calls the latest script file stored in the flow control rule storage service, compares the version number of the current script file with the version number of the latest script file in the called flow control rule storage service, and does not need to be replaced when the two version numbers are consistent; and when the two version numbers are not consistent, the current limiter takes the current limiting rule in the latest script file stored in the flow control rule storage service as the current limiting rule of the current limiter.
And S405, the flow agent returns the unavailable result to the service calling end according to the unavailable result, and the access flow is finished.
S406, the flow agent transmits the access flow to the management server according to the available result.
And S407, the management server returns an access result to the flow agent according to the access request.
S408, the flow agent returns the access result to the service calling end, and the access flow is finished.
The present embodiment has the following advantages:
the method has wide application range, is not only suitable for SAAS multi-tenant flow control management, but also suitable for flow control management of general services.
The method realizes complete separation from the service, and the flow control can be realized without any perception of service personnel, so that the service personnel can have more energy to concentrate on service development.
The flow control is realized by using the Lua script language, the configuration can be dynamically updated, the service is not perceived, and the flow control is more accurate.
And the multiple fluid controls sdk are not required to be maintained, so that the psychological burden of the middle station developer is reduced.
A fifth embodiment;
referring to fig. 9, a traffic access control device is provided, which may be any type of smart terminal, such as a cell phone, a tablet, a personal computer, etc. Specifically, the apparatus includes: one or more control processors and memory, here exemplified by a control processor. The control processor and the memory may be connected by a bus or other means, here exemplified by a connection via a bus.
The memory, which is a non-transitory computer readable storage medium, may be used to store non-transitory software programs, non-transitory computer executable programs, and modules, such as program instructions/modules corresponding to the traffic access control device in the embodiments of the present invention. The control processor implements the traffic access control method of the above method embodiments by running non-transitory software programs, instructions, and modules stored in memory.
The memory may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the memory may include high speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, the memory optionally includes memory located remotely from the control processor, and these remote memories may be connected to the traffic access control device over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The one or more modules are stored in the memory and, when executed by the one or more control processors, perform the traffic access control methods of the first to fourth embodiments described above.
An embodiment of the present invention further provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and the computer-executable instructions are executed by one or more control processors to perform the traffic access control methods in the first to fourth embodiments.
Through the above description of the embodiments, those skilled in the art can clearly understand that the embodiments can be implemented by software plus a general hardware platform. Those skilled in the art will appreciate that all or part of the processes in the methods for implementing the embodiments described above can be implemented by hardware related to instructions of a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes in the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read Only Memory (ROM), a Random Access Memory (RAM), or the like.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an illustrative embodiment," "an example," "a specific example," or "some examples" or the like mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
While embodiments of the invention have been shown and described, it will be understood by those of ordinary skill in the art that: various changes, modifications, substitutions and alterations can be made to the embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the claims and their equivalents.