Slice log uploading method, device, readable storage medium and electronic device
By using aspect programs in business applications to obtain API attribute information and aggregating it in the cache before uploading it when conditions are met, the problem of large-scale log generation and uploading in a short period of time in business applications is solved, and the computing, bandwidth and storage pressures are reduced.
Patent Information
- Application Number
- CN202310093320.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-17
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2043-01-17
AI Technical Summary
Calling a large number of APIs in a short period of time in business applications results in a large number of slice logs being generated and uploaded, causing excessive computing, bandwidth, and storage pressure on the client and server.
After obtaining the API attribute information through the aspect program, it is aggregated and stored in the cache. When the preset conditions are met, it is uploaded to the aspect server to reduce the number of logs generated and uploaded.
This reduces the number of slice logs generated and uploaded, and reduces the computing, bandwidth, and storage pressure on the client and server.
Smart Images

Figure CN116320030B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of security aspects, and more specifically to a method, device, readable storage medium, and electronic device for uploading aspect logs. Background Art
[0002] Security aspects use aspect-oriented programming (AOP) to inject the aspect program (also known as logic enhancement function) into the corresponding pointcut, without modifying the business application.
[0003] During the operation of a business application, the aspect program injected into the business application can monitor the API (Application Programming Interface) called by the business application, and generate aspect logs based on the attribute information of the API called by the monitored business application and upload them to the aspect server.
[0004] However, in some scenarios, business applications may call a large number of APIs in a short period of time. This will cause a large number of aspect logs to be uploaded in a short period of time, which will put great pressure on the traffic and storage of the client and server. Summary of the Invention
[0005] One of the purposes of the present invention is to provide a method for uploading aspect logs, which aggregates the attribute information of the API obtained through the aspect program and stores it in the cache. When the preset upload conditions are met, it is uploaded to the aspect server, thereby reducing the number of aspect logs generated and uploaded, thereby reducing the computing, bandwidth and storage pressure on the client and server.
[0006] Based on the above objectives, the present invention provides a method for uploading aspect logs, wherein an aspect program is pre-injected into a business application, and the method comprises the following steps:
[0007] During the operation of the business application, the attribute information of the API called by the business application is obtained through the pre-injected aspect program;
[0008] Determine whether there is attribute information identical to the attribute information in the cache;
[0009] If so, updating the number of API calls corresponding to the attribute information stored in the cache;
[0010] Otherwise, the attribute information is stored in the cache, and the number of API calls corresponding to the attribute information stored in the cache is initialized;
[0011] When the preset upload conditions are met, the attribute information of each API stored in the cache and the corresponding call count are uploaded to the aspect server.
[0012] Furthermore, in some implementations, obtaining attribute information of the API called by the business application specifically includes:
[0013] Obtain the class name, method name, privacy permission code, parameter information, return value information, page ID information of the business application, ID information of the module to which the function that calls the API belongs, call stack, calling thread name, name of the business application, unique device identifier, status information of the business application, and configuration version.
[0014] Furthermore, in some implementations, determining whether attribute information identical to the attribute information exists in the cache specifically includes:
[0015] Calculate the hash value of the attribute information and compare the hash value with the hash values of all attribute information in the cache. If the same hash value exists, the attribute information identical to the attribute information exists in the cache. Otherwise, the attribute information identical to the attribute information does not exist in the cache.
[0016] Furthermore, in some implementations, satisfying the preset upload conditions specifically includes:
[0017] The sum of the number of API calls corresponding to each attribute information stored in the cache exceeds a preset threshold or the time since the information in the cache was last uploaded to the aspect server exceeds a preset time.
[0018] Furthermore, in some embodiments, after uploading the attribute information of each API and the corresponding call count stored in the cache to the aspect server, the method further includes:
[0019] The cache is cleared, and then the attribute information of the API called by the business application program is continued to be obtained through the aspect program.
[0020] Another object of the present invention is to provide a slice log uploading device, which aggregates the attribute information of the API obtained through the slice program and stores it in the cache. When the preset upload conditions are met, it is uploaded to the slice server, thereby reducing the number of slice logs generated and uploaded, thereby reducing the computing, bandwidth and storage pressure on the client and server.
[0021] Based on the above purpose, another aspect of the present invention provides a device for uploading aspect logs, wherein an aspect program is pre-injected into a business application, and the device includes:
[0022] An acquisition module is configured to acquire attribute information of an API called by the business application through a pre-injected aspect program during the operation of the business application;
[0023] A judgment module configured to judge whether there is attribute information identical to the attribute information in the cache;
[0024] an updating module, configured to update the number of API calls corresponding to the attribute information stored in the cache when the judgment result of the judging module is yes;
[0025] a storage module configured to store the attribute information in the cache and initialize the number of API calls corresponding to the attribute information stored in the cache when the judgment result of the judgment module is negative;
[0026] The upload module is configured to upload the attribute information of each API and the corresponding call count stored in the cache to the aspect server when a preset upload condition is met.
[0027] Furthermore, in some implementations, obtaining attribute information of the API called by the business application specifically includes:
[0028] Obtain the class name, device name, privacy permission code, parameter information, return value information, page ID information of the business application, ID information of the module to which the function that calls the API belongs, call stack, calling thread name, name of the business application, unique device identifier, status information and configuration version of the business application.
[0029] Furthermore, in some implementations, determining whether attribute information identical to the attribute information exists in the cache specifically includes:
[0030] Calculate the hash value of the attribute information and compare the hash value with the hash values of all attribute information in the cache. If the same hash value exists, the attribute information identical to the attribute information exists in the cache. Otherwise, the attribute information identical to the attribute information does not exist in the cache.
[0031] Furthermore, in some implementations, satisfying the preset upload conditions specifically includes:
[0032] The sum of the number of API calls corresponding to each attribute information stored in the cache exceeds a preset threshold or the time since the information in the cache was last uploaded to the aspect server exceeds a preset time.
[0033] Furthermore, in some embodiments, the device further comprises a clearing module, wherein the clearing module is configured to:
[0034] After the attribute information of each API stored in the cache and the corresponding call count are uploaded to the aspect server, the cache is cleared, and then the attribute information of the API called by the business application is continuously obtained through the aspect program.
[0035] Another object of the present invention is to provide a readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the steps of the slice log uploading method described above.
[0036] Another object of the present invention is to provide an electronic device, which includes a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it performs the steps of the slice log uploading method as described above.
[0037] The aspect log uploading method and device of the present invention, after obtaining the attribute information of the API through the aspect program, aggregates the same attribute information and stores it in the cache as the aspect log to be uploaded. When the preset upload conditions are met, the aspect log to be uploaded in the cache is uploaded to the aspect server, thereby reducing the number of aspect logs generated and uploaded, thereby reducing the computing, bandwidth and storage pressure on the client and server. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 This is a flowchart of a method for uploading slice logs according to an embodiment of the present invention;
[0039] Figure 2 FIG. 4 is a structural block diagram of a slice log uploading device according to another embodiment of the present invention. DETAILED DESCRIPTION
[0040] The preferred embodiments of the present invention are given below in conjunction with the accompanying drawings and described in detail.
[0041] Security aspects use aspect-oriented programming (AOP) to dynamically add or modify security aspect programs within the business application's runtime logic without modifying the application. This allows the security aspect program to be decoupled from the business application while simultaneously implementing the security aspect, thus avoiding development iteration issues caused by high coupling.
[0042] The aspect program mentioned here is an enhancement program that implements security aspect services based on business operation logic. By using aspect-oriented programming, the aspect program can be injected into the corresponding point of the business application. The aspect program is triggered during the execution of the business application to implement the required security aspect business functions.
[0043] When a business application executes its business operations, it typically does so by calling methods. Therefore, any method in the business application can be used as an entry point for an aspect program, known as a pointcut. The aspect program can then be injected into the corresponding pointcut. This allows the business application to execute the injected aspect program when it reaches the pointcut, i.e., when it calls the business application method corresponding to the pointcut.
[0044] Typically, the code responsible for injecting aspect programs into pointcuts is highly reusable. Therefore, the program implementing this process is often abstracted into a service module, the aspect base. The aspect base retrieves the aspect programs to be deployed and the pointcuts into which the aspect programs should be injected in the business application from the server providing the security aspect service. After the application container is started, it is activated and injects the corresponding aspect programs into the pointcuts of the business application.
[0045] Business applications can be business applications that provide business services on the service platform's servers. Business services can be services provided by the service platform's servers to users, such as query services and payment services. Business services can also be services provided by a server on the service platform to other servers, such as settlement services.
[0046] Of course, as can be seen from the above description, in order to decouple the security aspect business program from the business application, this specification adopts an aspect-oriented programming approach so that the security aspect business program and the business application are intertwined during business execution, but are parallel to each other and can be maintained independently. Therefore, unlike the business provider of the business application, the third party providing the security aspect business can manage the content involved in the security aspect business through the server, such as the configuration of the security aspect business management and control strategy, the version iteration of the aspect program, the deployment rule configuration of the aspect program, etc. Of course, the provider of the security aspect business can be a third party or a business provider.
[0047] When managing the content involved in security aspect services, the server can record various configuration information through configuration files, such as the configuration of various policies and the deployment rules of aspect programs. This allows the aspect base to complete the deployment of aspect programs based on the configuration files, or the server can implement security aspect services based on the configuration files.
[0048] In actual applications, the business provider usually has a computer room with several physical machines or physical servers, and uses physical machines to provide the physical resources required by business applications. Of course, a business application may not require all the physical resources of the entire physical machine, so multiple virtual hosts (virtual hosting) are generally run on a physical machine through virtualization technology. Each virtual host is independent of each other and each enjoys part of the physical resources of the physical machine. Then, application containers can be deployed in the virtual host and business applications can be run through the application container. Application containers usually contain physical resources allocated to the application container, such as CPU, memory, etc., as well as the operating environment provided to the application container, such as the operating system (OS) or other operating environment data, such as the container's serial number (SN), assigned IP (Influential Property), application name, tenant, environment variables, etc.). Business applications can be deployed in application containers to execute business.
[0049] In the scenario where business is executed based on security aspects, the service provider or a third-party server providing security aspect services can provide a server to manage the content involved in the security aspect business, deploy the aspect base in the application container, and inject the aspect program into the business application in the business application container through the aspect base to provide security aspect business support for the service provider's application container.
[0050] Therefore, the aspect base can be pre-deployed in the service provider's application container. Generally, when the application container is started, the operating system provided to the application container is invoked and the pre-deployed aspect base is run. The aspect base then obtains the aspect program and the pointcuts of the business application from the server and injects the aspect program into the pointcut of the business application in the application container. Furthermore, the aspect base can also obtain the aspect program and the pointcuts of the business application from the server during the execution of the business application and inject the aspect program into the pointcut of the business application in the application container.
[0051] Of course, how the aspect base obtains the information required to deploy the aspect program from the server can be configured as needed. For example, it can actively pull the required information from the server based on the configuration file, or the server can actively send the required information to the aspect base.
[0052] After the aspect program is injected into the point of entry of the business application, the aspect program can be triggered during the execution of the business application to implement the corresponding security aspect business function.
[0053] Business applications are typically installed on devices, such as smartphones and tablets, and comprise multiple functional modules to implement various business functions. During the operation of a business application, each module typically calls system APIs on the device to implement various business functions. For example, a smartphone includes various hardware components (such as Bluetooth, microphones, and cameras). These components are driven by the smartphone's operating system (e.g., Android or iOS). The operating system exposes the APIs used to access these hardware components to the business application (i.e., the app). Each module within the business application contains functions for calling these APIs. When the business application runs into these functions, these functions call the corresponding APIs, which then activate the corresponding hardware, such as turning on Bluetooth, the microphone, or the camera on the smartphone. In certain scenarios, it is often necessary to monitor the API calls made by business applications to mitigate risks. Therefore, the functions that call each API in each module within the business application can be used as cutpoints. Aspect programs can be injected into these cutpoints to obtain attribute information about the APIs called by these functions, such as input and output parameters. For example, the operating system's API includes a large number of privacy APIs, such as APIs that use Bluetooth, APIs that use microphones, APIs that use cameras, etc. In privacy compliance scenarios, aspect programs can be injected into all functions that call privacy APIs in each functional module of the business application. When the business application runs into these functions, the aspect program can obtain the point information at each point, that is, the attribute information of each API called by the function at each point. This information will form a aspect log and be uploaded to the aspect server, thereby discovering the risk of illegal calls to privacy APIs.
[0054] However, aspect logs are usually uploaded in real time, that is, one log is generated and uploaded at a time. A business application may call a large number of APIs in a short period of time, and may call the same privacy API. In this way, in a short period of time, the security aspect will generate a large number of aspect logs and upload them to the aspect server in real time. These aspect logs may include multiple identical log messages (log messages generated by calling the same privacy API belong to the same log message). If this business application also has a large daily active volume, then a large number of aspect logs will be uploaded to the aspect server in a short period of time, which will put a lot of pressure on the computing, bandwidth and storage of the client and server.
[0055] To solve the above problems, the present invention provides a slice log uploading method. After obtaining the API attribute information through the slice program, the obtained API attribute information is first aggregated and stored in the cache, that is, the attribute information of the same API is merged into one, and the number of API calls is recorded. Then, after meeting the preset upload conditions, the aggregated information (including the API attribute information and the corresponding API call number) is uploaded to the slice server as a slice log, thereby reducing the log volume and upload volume, thereby reducing the computing, bandwidth and storage pressure on the client and server.
[0056] like Figure 1 As shown, an embodiment of the present invention provides a method for uploading aspect logs. An aspect program is pre-injected into a business application. The method includes the following steps:
[0057] 100: During the operation of the business application, the attribute information of the API called by the business application is obtained through the pre-injected aspect program.
[0058] In some embodiments, aspect programs can be injected into business applications via a pre-deployed aspect base. For example, after a business application is launched, the aspect base can retrieve the aspect configuration from the aspect server and then inject the aspect program at each tangent point of the business application based on the aspect configuration. Each tangent point is a function in each functional module of the business application that calls an API. The type of API can be selected based on different application scenarios. For example, in a privacy compliance scenario, the API can be a privacy API.
[0059] After the aspect program is injected, during the operation of the business application, when it reaches each cutoff point, the aspect program at each cutoff point can obtain the cutoff point information at each cutoff point, that is, the attribute information of the API called by the function used to call the API in each functional module of the business application. In some embodiments, the attribute information of the API can be obtained according to a preset data collection template. That is, the aspect program obtains the attribute information of the API according to the data collection template, so that the attribute information obtained by the aspect program each time has the same format, which facilitates the aggregation of attribute information of the same API.
[0060] In some embodiments, the data collection template for API attribute information is shown in Table 1:
[0061] Table 1: Data collection template
[0062]
[0063] According to Table 1 above, whenever a business application runs to a function for calling an API corresponding to a certain tangent point, the aspect program at that tangent point will collect the tangent point information at that tangent point (i.e., the attribute information of the API), including the class name, method name, privacy permission code, parameter information, return value information, page ID information, module ID information, call stack, calling thread name, application (i.e., APP) name, device unique identifier, status information, and configuration version of the function that calls the API. Since the attribute information of the API obtained is in the same format, when the APP runs the function that calls the API corresponding to the same tangent point at different times, the attribute information of the API it produces is exactly the same.
[0064] In some embodiments, the aspect program can also obtain the startTimestamp (start timestamp) and endTimestamp (end timestamp), where the start timestamp indicates the start time of the API call by the function that calls the API (i.e., the start time of the API call by the functional module to which the function belongs), and the end timestamp indicates the end time of the API call by the function that calls the API (i.e., the end time of the API call by the functional module to which the function belongs). The start timestamp and the end timestamp can be used to obtain the specific time period in which a functional module of the APP calls a certain API, and the number of times each functional module of the APP calls each API in a certain time period can also be obtained. The start timestamp and the end timestamp can also be uploaded to the aspect server as aspect logs to facilitate subsequent statistical analysis by the aspect server.
[0065] In some embodiments, the value of the privacy permission code can be mapped based on the class name and method name of the function that calls the API, and is used to represent different types of privacy permissions. The privacy permission code mapping table is shown in Table 2:
[0066] Table 2: Privacy permission code mapping table
[0067]
[0068]
[0069]
[0070]
[0071]
[0072] The aspect program can obtain the corresponding privacy permission code by calling the class name and method name of the API function according to Table 2. The values of other attribute information besides the class name, method name, and privacy permission code can be obtained and calculated by the aspect program calling the API provided by the operating system.
[0073] 200: Determine whether the cache contains the same attribute information as the obtained API attribute information.
[0074] 300: If yes, update the number of API calls corresponding to the attribute information stored in the cache.
[0075] 400: Otherwise, the obtained API attribute information is stored in the cache, and the number of API calls corresponding to the attribute information stored in the cache is initialized.
[0076] Since the attribute information of the API is obtained according to the data collection template, when the business application runs to the function that calls the API corresponding to the same tangent point at different times, the attribute information obtained by the aspect program is the same attribute information. In the prior art, after the aspect program obtains a piece of attribute information, the aspect base will upload it to the aspect server as an aspect log. In this way, the same attribute information generated at different times will all be uploaded to the aspect server. For example, a functional module of a business application may call the same API thousands of times within 30 seconds. Then the business application will run the function that calls the API at the corresponding tangent point thousands of times within 30 seconds. The aspect program will obtain thousands of identical attribute information. These thousands of identical attribute information will all be uploaded to the aspect server, causing repeated uploads and increasing the traffic and storage pressure of the aspect server.
[0077] Therefore, in some embodiments of the present invention, after the aspect program obtains the attribute information of the API, it is not uploaded to the aspect server first. Instead, it is aggregated and then stored in the cache. After the preset upload conditions are met, it is uploaded. Aggregation means that the same attribute information is merged into one piece of attribute information, and the number of pieces of the same attribute information is used as the number of API calls corresponding to the attribute information. The attribute information and the number of API calls corresponding to the attribute information are then used as the aspect log to be uploaded. After the upload conditions are met, the aspect log to be uploaded can be uploaded to the aspect server.
[0078] Specifically, each time the aspect program obtains a piece of attribute information, it determines whether there is attribute information identical to the attribute information in the cache. If so, it means that the API has been called by the function corresponding to the cut point before, and it is only necessary to update the API call count, without having to store the attribute information in the cache again. Otherwise, it means that the APIE has not been called by the function corresponding to the cut point before, and it is necessary to store the attribute information in the cache and initialize the corresponding API call count. In some embodiments, updating the API call count means adding 1 to the API call count, and initializing the API call count means setting the API call count to 1.
[0079] In some embodiments, determining whether there is attribute information identical to the attribute information in the cache specifically includes:
[0080] Calculate the hash value of the attribute information and compare it with the hash values of all attribute information in the cache. If the same hash value exists, it means that the same attribute information exists in the cache (attribute information corresponding to the same hash value is the same attribute information). Otherwise, it means that the same attribute information does not exist.
[0081] Specifically, after the aspect program obtains the attribute information, it can first format it into a string, and then calculate the hash value of the string. Subsequently, the cache dictionary object can be queried based on the hash value to see if there is a related record. If there is a related record, it means that the same attribute information exists in the cache, and the number of calls to the attribute information in the cache corresponding to the hash value can be increased by 1. Otherwise, it means that the same attribute information does not exist in the cache, and the attribute information can be stored in the cache (the corresponding hash value will exist in the cache dictionary object), and its number of calls is initialized to 1.
[0082] 500: When the preset upload conditions are met, the attribute information of each API stored in the cache and the corresponding call count are uploaded to the aspect server.
[0083] In some embodiments, the preset upload condition can be whether the sum of the number of API calls corresponding to each attribute information stored in the cache exceeds a preset threshold (for example, 1000 times) or the time since the last upload of the cached aspect log to be uploaded (that is, the attribute information of each API stored in the cache and the corresponding number of calls) to the aspect server exceeds a preset time (for example, 30 seconds). When the sum of the number of API calls corresponding to each attribute information stored in the cache exceeds the preset threshold or the time since the last upload of the information in the cache to the aspect server exceeds the preset time, it means that the upload condition is met, and the cached aspect log to be uploaded can be uploaded to the aspect server through the aspect base. In this way, the aspect log is no longer uploaded in real time, but is aggregated first and then uploaded, thereby reducing the amount of upload each time, thereby reducing the computing, bandwidth and storage pressure on the client and server. In a specific embodiment, the upload method of the present invention can reduce the log upload and storage volume by 53% compared to the real-time upload method.
[0084] In some embodiments, after the aspect logs to be uploaded in the cache are uploaded to the aspect server, the cache can be cleared and then step 100 is re-executed to perform the next attribute information collection and upload.
[0085] In some embodiments, it is possible to upload aspect logs in batches. For example, after the business application is started and running, when it runs to an API that needs to be monitored, the attribute information of the API can be obtained through the aspect program, and the starting timestamp is obtained as the current time. Then, according to steps 100-500, the aspect logs to be uploaded in the cache are uploaded to the aspect server, and the time when the preset upload conditions are met is obtained as the end time. At this time, the first batch of uploads is completed, and the upload time period of the first batch is from the current time to the end time. After the upload of the first batch is completed, the cache can be cleared, and then the above steps can be repeated to obtain and upload the next batch of aspect logs. When the business application exits, the above preset upload conditions may not be met. At this time, all the aspect logs to be uploaded in the cache can also be uploaded to the aspect server as the last batch of uploads. In this way, the aspect logs can be uploaded to the aspect server in batches, greatly reducing its computing, bandwidth and storage pressure. In a certain upload batch, after step 400, it can be determined whether the preset upload conditions are met. If so, the upload batch is completed. If not, steps 100-400 are re-executed until the upload conditions are met and the upload batch is completed.
[0086] Taking the preset time of 30 seconds and the preset threshold of 1000 times as an example, when the sum of the API calls in the cache within 30 seconds does not exceed 1000 times, the time of the batch is 30 seconds. When the sum of the API calls in the cache within 30 seconds exceeds 1000 times, the time of the batch will be less than 30 seconds. That is to say, the time of each batch will not exceed 30 seconds and the sum of the API calls will not exceed 1000 times. This can ensure that the number of aspect logs uploaded each time will not exceed 1000 (when there is the same attribute information, the number of aspect logs uploaded will be less than 1000), and the upload time of adjacent batches will not be too long apart (at least one aspect log will be uploaded every 30 seconds). This will not generate a large number of aspect logs in a short period of time, nor will it affect the upload of aspect logs due to the long upload time interval between batches, resulting in the aspect server being unable to receive aspect logs in time.
[0087] The aspect log uploading method of an embodiment of the present invention, after obtaining the attribute information of the API through the aspect program, aggregates the same attribute information and stores it in the cache as the aspect log to be uploaded. When the preset upload conditions are met, the aspect log to be uploaded in the cache is uploaded to the aspect server, thereby reducing the number of aspect logs generated and uploaded, thereby reducing the computing, bandwidth and storage pressure on the client and server.
[0088] like Figure 2As shown, another embodiment of the present invention provides a slice log uploading device, in which a slice program is pre-injected into the business application, and the device includes an acquisition module 10, a judgment module 20, an update module 30, a storage module 40 and an upload module 50 that communicate with each other.
[0089] The acquisition module 10 is configured to acquire the attribute information of the API called by the business application through a pre-injected aspect program during the operation of the business application.
[0090] In some embodiments, aspect programs can be injected into business applications via a pre-deployed aspect base. For example, after a business application is launched, the aspect base can retrieve the aspect configuration from the aspect server and then inject the aspect program at each tangent point of the business application based on the aspect configuration. Each tangent point is a function in each functional module of the business application that calls an API. The type of API can be selected based on different application scenarios. For example, in a privacy compliance scenario, the API can be a privacy API.
[0091] After the aspect program is injected, during the operation of the business application, when it reaches each cutoff point, the aspect program at each cutoff point can obtain the cutoff point information at each cutoff point, that is, the attribute information of the API called by the function used to call the API in each functional module of the business application. In some embodiments, the attribute information of the API can be obtained according to a preset data collection template. That is, the aspect program obtains the attribute information of the API according to the data collection template, so that the attribute information obtained by the aspect program each time has the same format, which facilitates the aggregation of attribute information of the same API. The data collection template can be seen in Table 1.
[0092] In some embodiments, the aspect program can also obtain the startTimestamp (start timestamp) and endTimestamp (end timestamp), where the start timestamp indicates the start time of the API call by the function that calls the API (i.e., the start time of the API call by the functional module to which the function belongs), and the end timestamp indicates the end time of the API call by the function that calls the API (i.e., the end time of the API call by the functional module to which the function belongs). The start timestamp and the end timestamp can be used to obtain the specific time period in which a functional module of the APP calls a certain API, and the number of times each functional module of the APP calls each API in a certain time period can also be obtained. The start timestamp and the end timestamp can also be uploaded to the aspect server as aspect logs to facilitate subsequent statistical analysis by the aspect server.
[0093] In some embodiments, the value of the privacy permission code can be mapped based on the class name and method name of the function calling the API to represent different types of privacy permissions. The privacy permission code mapping table can be found in Table 2.
[0094] The judgment module 20 is configured to judge whether there is attribute information in the cache that is the same as the acquired attribute information of the API.
[0095] The updating module 30 is configured to update the number of API calls corresponding to the attribute information stored in the cache when the judgment result of the judging module 20 is yes.
[0096] The storage module 40 is configured to store the acquired attribute information of the API in a cache when the judgment result of the judgment module 20 is no, and initialize the number of API calls corresponding to the attribute information stored in the cache.
[0097] In some embodiments of the present invention, after the aspect program obtains the attribute information of the API, it is not uploaded to the aspect server first. Instead, it is aggregated and then stored in the cache. After the preset upload conditions are met, it is uploaded. Aggregation means that the same attribute information is merged into one piece of attribute information, and the number of pieces of the same attribute information is used as the number of API calls corresponding to the attribute information. The attribute information and the number of API calls corresponding to the attribute information are then used as the aspect log to be uploaded. After the upload conditions are met, the aspect log to be uploaded can be uploaded to the aspect server.
[0098] Specifically, each time the aspect program obtains a piece of attribute information, it determines whether there is attribute information identical to the attribute information in the cache. If so, it means that the API has been called by the function corresponding to the cut point before, and it is only necessary to update the API call count, without having to store the attribute information in the cache again. Otherwise, it means that the APIE has not been called by the function corresponding to the cut point before, and it is necessary to store the attribute information in the cache and initialize the corresponding API call count. In some embodiments, updating the API call count means adding 1 to the API call count, and initializing the API call count means setting the API call count to 1.
[0099] In some embodiments, determining whether there is attribute information identical to the attribute information in the cache specifically includes:
[0100] Calculate the hash value of the attribute information and compare it with the hash values of all attribute information in the cache. If the same hash value exists, it means that the same attribute information exists in the cache (attribute information corresponding to the same hash value is the same attribute information). Otherwise, it means that the same attribute information does not exist.
[0101] Specifically, after the aspect program obtains the attribute information, it can first format it into a string, and then calculate the hash value of the string. Subsequently, the cache dictionary object can be queried based on the hash value to see if there is a related record. If there is a related record, it means that the same attribute information exists in the cache, and the number of calls to the attribute information in the cache corresponding to the hash value can be increased by 1. Otherwise, it means that the same attribute information does not exist in the cache, and the attribute information can be stored in the cache (the corresponding hash value will exist in the cache dictionary object), and its number of calls is initialized to 1.
[0102] The uploading module 50 is configured to upload the attribute information of each API and the corresponding call count stored in the cache to the aspect server when a preset upload condition is met.
[0103] In some embodiments, the preset upload condition can be whether the sum of the number of API calls corresponding to each attribute information stored in the cache exceeds a preset threshold (for example, 1000 times) or the time since the last upload of the cached aspect log to be uploaded (that is, the attribute information of each API stored in the cache and the corresponding number of calls) to the aspect server exceeds a preset time (for example, 30 seconds). When the sum of the number of API calls corresponding to each attribute information stored in the cache exceeds the preset threshold or the time since the last upload of the information in the cache to the aspect server exceeds the preset time, it means that the upload condition is met, and the cached aspect log to be uploaded can be uploaded to the aspect server through the aspect base. In this way, the aspect log is no longer uploaded in real time, but is aggregated first and then uploaded, thereby reducing the amount of upload each time, thereby reducing the computing, bandwidth and storage pressure on the client and server. In a specific embodiment, the upload method of the present invention can reduce the log upload and storage volume by 53% compared to the real-time upload method.
[0104] In some embodiments, the aspect log uploading device also includes a clearing module, which is configured to clear the cache after the aspect log to be uploaded in the cache is uploaded to the aspect server, and then re-acquire the API attribute information through the acquisition module 10 to perform the next attribute information collection and upload.
[0105] In some embodiments, the aspect logs can be uploaded in batches. For example, after the business application is started and running, when it runs to an API that needs to be monitored, the attribute information of the API can be obtained through the aspect program, and the starting timestamp can be obtained as the current time. Then, through the judgment module 20, the update module 30, the storage module 40 and the upload module 50, the aspect logs to be uploaded in the cache are uploaded to the aspect server, and the time when the preset upload conditions are met is obtained as the end time. At this time, the first batch of uploads is completed, and the upload time period of the first batch is from the current time to the end time. After the upload of the first batch is completed, the cache can be cleared, and then the above process can be repeated to obtain and upload the next batch of aspect logs. When the business application exits, the upload conditions may not be met. At this time, all the aspect logs to be uploaded in the cache can also be uploaded to the aspect server as the last batch of uploads. In this way, the aspect logs can be uploaded to the aspect server in batches, greatly reducing its computing, bandwidth and storage pressure. In a certain upload batch, after the judgment module 20 completes the judgment and the update module 30 and the storage module 40 perform corresponding operations based on the judgment results, they both need to determine whether the preset upload conditions are met. If so, the upload batch is completed. If not, the attribute information is continued to be obtained through the acquisition module 10 until the upload conditions are met and the upload batch ends.
[0106] The aspect log uploading device of an embodiment of the present invention, after obtaining the attribute information of the API through the aspect program, aggregates the same attribute information and stores it in the cache as the aspect log to be uploaded. When the preset upload conditions are met, the aspect log to be uploaded in the cache is uploaded to the aspect server, thereby reducing the number of aspect logs generated and uploaded, thereby reducing the computing, bandwidth and storage pressure on the client and server.
[0107] Yet another embodiment of the present invention provides a readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute the steps of the method in the above embodiment of the present invention.
[0108] Another embodiment of the present invention provides an electronic device, which includes a memory and a processor. The memory stores executable code. When the processor executes the executable code, it performs the steps of the method in the above embodiment of the present invention.
[0109] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0110] For the convenience of description, the above device is described as being divided into various units according to their functions. Of course, when implementing the present invention, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0111] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0112] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0113] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0114] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0115] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0116] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0117] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0118] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0119] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0120] The present invention may be described in the general context of computer-executable instructions, such as program modules, executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. The present invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media, including storage devices.
[0121] The various embodiments of the present invention are described in a progressive manner. Similar portions between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiment is generally similar to the method embodiment, so its description is relatively simple. For relevant portions, refer to the description of the method embodiment.
[0122] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of the present invention. Various modifications are possible. In other words, any simple, equivalent changes and modifications made in accordance with the claims and description of the present invention are within the scope of protection of the patent claims. Anything not fully described in this invention constitutes conventional technology.
Claims
1. A method for uploading aspect logs, wherein an aspect program is pre-injected into a business application, and the method comprises the following steps: During the operation of the business application, the attribute information of the API called by the business application is obtained through the pre-injected aspect program; Determine whether there is attribute information identical to the attribute information in the cache; If so, updating the number of API calls corresponding to the attribute information stored in the cache; Otherwise, the attribute information is stored in the cache, and the number of API calls corresponding to the attribute information stored in the cache is initialized; When the preset upload conditions are met, the attribute information of each API stored in the cache and the corresponding call count are uploaded to the aspect server; The preset upload conditions are met as follows: the sum of the number of API calls corresponding to each attribute information stored in the cache exceeds a preset threshold or the time from the last time the information in the cache was uploaded to the aspect server exceeds a preset time.
2. According to the aspect log uploading method of claim 1, obtaining attribute information of the API called by the business application program specifically comprises: Obtain the class name, method name, privacy permission code, parameter information, return value information, page ID information of the business application, ID information of the module to which the function that calls the API belongs, call stack, calling thread name, name of the business application, unique device identifier, status information and configuration version of the business application.
3. According to the aspect log uploading method of claim 1, determining whether attribute information identical to the attribute information exists in the cache specifically comprises: Calculate the hash value of the attribute information and compare the hash value with the hash values of all attribute information in the cache. If the same hash value exists, the attribute information identical to the attribute information exists in the cache. Otherwise, the attribute information identical to the attribute information does not exist in the cache.
4. The aspect log uploading method according to claim 1, after uploading the attribute information and corresponding call counts of each API stored in the cache to the aspect server, further comprising: The cache is cleared, and then the attribute information of the API called by the business application program is continued to be obtained through the aspect program.
5. A device for uploading aspect logs, wherein an aspect program is pre-injected into a business application, the device comprising: An acquisition module is configured to acquire attribute information of an API called by the business application through a pre-injected aspect program during the operation of the business application; A judgment module configured to judge whether there is attribute information identical to the attribute information in the cache; an updating module, configured to update the number of API calls corresponding to the attribute information stored in the cache when the judgment result of the judging module is yes; a storage module configured to store the attribute information in the cache and initialize the number of API calls corresponding to the attribute information stored in the cache when the judgment result of the judgment module is negative; An upload module configured to upload the attribute information and corresponding call counts of each API stored in the cache to the aspect server when a preset upload condition is met; The preset upload conditions are met as follows: the sum of the number of API calls corresponding to each attribute information stored in the cache exceeds a preset threshold or the time from the last time the information in the cache was uploaded to the aspect server exceeds a preset time.
6. The device for uploading a slice log according to claim 5, wherein the step of obtaining attribute information of the API called by the business application program comprises: Obtain the class name, device name, privacy permission code, parameter information, return value information, page ID information of the business application, ID information of the module to which the function that calls the API belongs, call stack, calling thread name, name of the business application, unique device identifier, status information and configuration version of the business application.
7. The device for uploading a slice log according to claim 5, wherein determining whether attribute information identical to the attribute information exists in the cache specifically comprises: Calculate the hash value of the attribute information and compare the hash value with the hash values of all attribute information in the cache. If the same hash value exists, the attribute information identical to the attribute information exists in the cache. Otherwise, the attribute information identical to the attribute information does not exist in the cache.
8. The device for uploading slice logs according to claim 5, further comprising a clearing module, wherein the clearing module is configured to: After the attribute information of each API stored in the cache and the corresponding call count are uploaded to the aspect server, the cache is cleared, and then the attribute information of the API called by the business application is continuously obtained through the aspect program.
9. A readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the steps of the slice log uploading method according to any one of claims 1 to 4.
10. An electronic device comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it performs the steps of the slice log uploading method according to any one of claims 1 to 4.
Citation Information
Patent Citations
A mobile game big data source layer pasting realization method and device
CN109815198A
Exception determination method and device for application programming interface API
CN110673973A