CN114020255A - Java code tracking type based data acquisition method - Google Patents

Java code tracking type based data acquisition method Download PDF

Info

Publication number
CN114020255A
CN114020255A CN202111336549.4A CN202111336549A CN114020255A CN 114020255 A CN114020255 A CN 114020255A CN 202111336549 A CN202111336549 A CN 202111336549A CN 114020255 A CN114020255 A CN 114020255A
Authority
CN
China
Prior art keywords
spi
interceptor
java
enhancement
jar
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111336549.4A
Other languages
Chinese (zh)
Inventor
赵振洪
宋振一
陈钟浩
管瑞峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Zhijing Information Technology Co ltd
Original Assignee
Shanghai Zhijing Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Zhijing Information Technology Co ltd filed Critical Shanghai Zhijing Information Technology Co ltd
Priority to CN202111336549.4A priority Critical patent/CN114020255A/en
Publication of CN114020255A publication Critical patent/CN114020255A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明公开了一种基于java代码跟踪型的数据采集方法,包括以下步骤:S1定义spi拦截器接口;S2定义spi拦截器调度器,提供@RuntimeType注解入口;S3定义agent入口;S4构建Transformer;S5构建AgentBuilder;S6采用maven‑shade‑plugin插件包成一个javaagent jar;S7修改应用的启动命令,加上java‑javaagent jar包全路径启动参数即可实现基于java代码跟踪型对应用数据的采集。本发明采用java字节码增强技术,在字节码加载时期,对字节码进行了动态增强,解决了AOP动态代理技术的同对象同方法相互调用代理失效问题。

Figure 202111336549

The invention discloses a data collection method based on java code tracking type, comprising the following steps: S1 defines a spi interceptor interface; S2 defines a spi interceptor scheduler, providing an @RuntimeType annotation entry; S3 defines an agent entry; S4 constructs a Transformer; S5 builds AgentBuilder; S6 uses maven‑shade‑plugin to package it into a javaagent jar; S7 modifies the startup command of the application and adds the full path startup parameter of the java‑javaagent jar package to realize the collection of application data based on java code tracking. The invention adopts the java bytecode enhancement technology, dynamically enhances the bytecode during the bytecode loading period, and solves the problem of the mutual invocation of the same object and the same method of the proxy failure problem of the AOP dynamic proxy technology.

Figure 202111336549

Description

Java code tracking type based data acquisition method
Technical Field
The invention relates to the technical field of data acquisition, in particular to a java code tracking type-based data acquisition method.
Background
With the rapid development of enterprises, related businesses will become increasingly complex, and accordingly, a technical team is required to refine more micro-services to meet the increasingly complex requirements. Meanwhile, the problems of request statistics, link topology, application dependency, failure diagnosis efficiency and the like of each application need to be faced, so that a set of monitoring components needs to be developed, implanted into the application, collect data during program operation, and restore the program operation condition.
Based on the requirements, the AOP section-oriented programming idea can be adopted, and the interception of the operation method is realized through dynamic proxy in the program operation period, so that the effect of acquiring program operation data is achieved.
However, in the AOP dynamic proxy technology, the proxy object is dynamically generated based on the original java object during the operation period to achieve the effect of intercepting the operation method. Under the condition that different methods of the same java object are mutually called, the interception effect is invalid because the dynamic proxy object is not called, and the running data of the acquisition program is lost.
Disclosure of Invention
The invention aims to provide a java code tracking type-based data acquisition method, which aims to solve the problems that the interception effect is invalid and the operation data of an acquisition program is lost due to the fact that dynamic proxy object calling is not performed in the background technology.
In order to achieve the purpose, the invention provides the following technical scheme:
a java code tracking type based data acquisition method comprises the following steps:
s1: defining a spi interceptor interface: defining a uniform spi interceptor interface by adopting an spi plug-in mechanism, and realizing different spi interceptor interfaces by different enhancement logics;
s2: defining a spi interceptor scheduler, providing an @ RuntimeType annotation entry;
s3: defining an agent entry: in the agent's domain method, loading the class realized by the spi interceptor through the ServiceLoader, and circulating each spi interceptor to realize the class;
s4: constructing a Transformer: injecting the spi interceptor into an interceptor scheduler, and then injecting the spi interceptor into a Transformer;
s5: constructing an AgentBuilder, and injecting a Transformer into the AgentBuilder to realize request statistics enhancement, link topology enhancement and remote call enhancement;
s6: packing a java-shadow-plugin into a java jar;
s7: and modifying the application starting command, and adding the java-java agent jar package full-path starting parameters to acquire the application data based on the java code tracking type.
Furthermore, in step S1, for defining a uniform dynamic code enhancement spi interceptor interface, pre-execution, post-execution, exception handling, class matching, and method matching are provided.
Further, the specific steps in S2 are: and injecting the spi interceptor into the scheduler, and in an execution method of the scheduler, identifying the @ RuntimeType annotation by a java reflection technology and combining a front-end execution interception method and a rear-end execution interception method of the spi interceptor to realize front-end and rear-end enhancement of the target bytecode.
Further, the specific method in S6 is: and (3) adopting a maven-shade-plug-in, and designating the pre-class as a pre-main full path of S3, thereby realizing packaging the current engineering code into a javaagent jar.
Furthermore, the java-java agent jar package full path startup parameters in S7 include java-java agent:/data/agent.
Compared with the prior art, the invention has the beneficial effects that:
the invention provides a java code tracking type-based data acquisition method, which adopts a java byte code enhancement technology to dynamically enhance byte codes in the byte code loading period, solves the problem of agent failure caused by mutual calling of the same object and the same method of an AOP dynamic agent technology, has no invasion and no perception to an application developer, and completes application data acquisition on the premise of not modifying any application code.
Drawings
FIG. 1 is a flow chart of the method of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, an embodiment of the present invention provides a java code tracking type-based data acquisition method, including the following steps:
the first step is as follows: defining a spi interceptor interface: defining a uniform spi interceptor interface by adopting an spi plug-in mechanism, and realizing different spi interceptor interfaces by different enhancement logics; wherein, for defining a uniform dynamic code enhancement spi interceptor interface, pre-execution, post-execution, exception handling, class matching and method matching are provided in a matching way;
the second step is that: defining a spi interceptor scheduler, providing an @ RuntimeType annotation entry;
the third step: defining an agent entry: in the agent's domain method, loading the class realized by the spi interceptor through the ServiceLoader, and circulating each spi interceptor to realize the class; specifically, an spi interceptor is injected into the scheduler, and in an execution method of the scheduler, a java reflection technology is used for identifying @ RuntimeType annotation and combining a front-end execution interception method and a rear-end execution interception method of the spi interceptor, so that front-end and rear-end enhancement of a target byte code is realized;
the fourth step: constructing a Transformer: injecting the spi interceptor into an interceptor scheduler, and then injecting the spi interceptor into a Transformer;
the fifth step: constructing an AgentBuilder, and injecting a Transformer into the AgentBuilder to realize request statistics enhancement, link topology enhancement and remote call enhancement;
and a sixth step: packing a java-shadow-plugin into a java jar; the method specifically comprises the steps that a maven-shadow-plug-in is adopted, a pre-class is designated as a pre-main full path of S3, and therefore the current engineering code is packaged into a java jar;
the seventh step: the method comprises the steps that a start command of application is modified, and java-java jar package full-path start parameters are added to achieve collection of application data based on a java code tracking type; the java-java agent jar package full path starting parameter comprises java-java agent:/data/agent.
The working principle is as follows: the invention provides a java code tracking type-based data acquisition method, which adopts a technical means to dynamically enhance java byte codes, and generally has more than single enhancement logic for the dynamic enhancement of the java byte codes, such as request statistics enhancement, link topology enhancement, remote call enhancement and the like, so that the embodiment of the invention adopts a spi plug-in mechanism to define a uniform spi interceptor interface, and different enhancement logics realize different spi interceptor interfaces.
Defining a uniform dynamic code enhanced spi interceptor interface, and providing methods such as pre-execution, post-execution, exception handling, class matching, method matching and the like; in the agent's premier method, loading all spi interceptor implementation classes through a ServiceLoader, circulating each spi interceptor implementation class, constructing a corresponding Transformer, injecting the spi interceptor into the Transformer, then constructing an AgentBuilder, and injecting the Transformer into the AgentBuilder; it should be noted that, in the method, an interceptor scheduler needs to be defined, and the spi interceptor is injected into the scheduler, and in the execution method of the scheduler, the @ RuntimeType annotation is identified by the java reflection technology, and the method of pre-execution interception and post-execution interception of the spi interceptor are combined, so as to implement pre-and post-enhancement of the target bytecode.
Meanwhile, it is also noted that in the method of the present invention, because the responsibilities of different interceptors are different, and the classes and methods that they need to intercept are also different, when constructing the Transformer and the AgentBuilder, only the assigned classes and methods of the interceptors will be matched, and no interception will be performed on other classes and methods, thereby implementing an overall framework for dynamically increasing java byte codes, according to this framework, the present invention can implement spi interceptors such as request statistics enhancement, link topology enhancement, remote invocation enhancement, etc. according to the actual requirements, and complete a java code tracking type based data acquisition monitoring component; the specific method comprises the following steps: adopting a maven-shade-plug-in, and designating the pre-class as a pre-main full path, thus realizing packaging the current engineering code into a java jar; modifying the starting command of the application, and adding the full path starting parameters of the java-java agent jar package, such as: java-java agent/data/agent.jar-jar app.jar, and the method can be used for realizing application data acquisition based on java code tracking.
In summary, the following steps: the invention provides a java code tracking type-based data acquisition method, which adopts a java byte code enhancement technology to dynamically enhance byte codes in the byte code loading period, solves the problem of agent failure caused by mutual calling of the same object and the same method of an AOP dynamic agent technology, has no invasion and no perception to an application developer, and completes application data acquisition on the premise of not modifying any application code.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art should be able to cover the technical solutions and the inventive concepts of the present invention within the technical scope of the present invention.

Claims (5)

1.一种基于java代码跟踪型的数据采集方法,其特征在于,包括以下步骤:1. a data collection method based on java code tracking type, is characterized in that, comprises the following steps: S1:定义spi拦截器接口:采用spi插件机制,定义统一的spi拦截器接口,不同的增强逻辑实现不同的spi拦截器接口;S1: Define the spi interceptor interface: use the spi plug-in mechanism to define a unified spi interceptor interface, and different enhancement logics implement different spi interceptor interfaces; S2:定义spi拦截器调度器,提供@RuntimeType注解入口;S2: Define the spi interceptor scheduler and provide the @RuntimeType annotation entry; S3:定义agent入口:在agent的premain方法中,通过ServiceLoader加载spi拦截器实现类,并循环每一个spi拦截器实现类;S3: Define the agent entry: in the premain method of the agent, load the spi interceptor implementation class through ServiceLoader, and loop each spi interceptor implementation class; S4:构建Transformer:将spi拦截器注入到拦截器调度器中,再注入到Transformer中;S4: Build Transformer: inject the spi interceptor into the interceptor scheduler, and then inject it into the Transformer; S5:构建AgentBuilder,将Transformer注入到AgentBuilder中,实现请求统计增强、链路拓扑增强、远程调用增强;S5: Build AgentBuilder, inject Transformer into AgentBuilder, and realize request statistics enhancement, link topology enhancement, and remote call enhancement; S6:采用maven-shade-plugin插件包成一个javaagent jar;S6: use the maven-shade-plugin plug-in package into a javaagent jar; S7:修改应用的启动命令,加上java-javaagent jar包全路径启动参数即可实现基于java代码跟踪型对应用数据的采集。S7: Modify the startup command of the application and add the full path startup parameter of the java-javaagent jar package to realize the collection of application data based on java code tracking. 2.如权利要求1所述的一种基于java代码跟踪型的数据采集方法,其特征在于:S1中为定义统一的动态代码增强spi拦截器接口,配套提供有前置执行、后置执行、异常处理、类匹配、方法匹配。2. a kind of data acquisition method based on java code tracking type as claimed in claim 1, is characterized in that: in S1, the dynamic code enhancement spi interceptor interface that defines unity, is provided with pre-execution, post-execution, Exception handling, class matching, method matching. 3.如权利要求1所述的一种基于java代码跟踪型的数据采集方法,其特征在于:S2中具体步骤为:将spi拦截器注入到该调度器中,在调度器的执行方法中,通过java反射技术识别@RuntimeType注解结合spi拦截器的前置和后置执行拦截方法,实现对目标字节码的前置和后置增强。3. a kind of data acquisition method based on java code tracking type as claimed in claim 1, it is characterized in that: concrete steps in S2 are: inject spi interceptor in this scheduler, in the execution method of scheduler, The @RuntimeType annotation is identified by java reflection technology combined with the pre- and post-execution interception methods of the spi interceptor to achieve pre- and post-enhancement of the target bytecode. 4.如权利要求1所述的一种基于java代码跟踪型的数据采集方法,其特征在于:S6中具体方法为:采用maven-shade-plugin插件,指定premain-class为S3的premain全路径,从而实现将当前工程代码打包成一个javaagent jar。4. a kind of data collection method based on java code tracking type as claimed in claim 1, is characterized in that: in S6, concrete method is: adopt maven-shade-plugin plug-in, specify premain-class as the premain full path of S3, In this way, the current project code is packaged into a javaagent jar. 5.如权利要求1所述的一种基于java代码跟踪型的数据采集方法,其特征在于:S7中java-javaagent jar包全路径启动参数包括java-javaagent:/data/agent.jar-jarapp.jar。5. a kind of data collection method based on java code tracking type as claimed in claim 1 is characterized in that: in S7, the full path startup parameter of java-javaagent jar package comprises java-javaagent:/data/agent.jar-jarapp. jar.
CN202111336549.4A 2021-11-12 2021-11-12 Java code tracking type based data acquisition method Pending CN114020255A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111336549.4A CN114020255A (en) 2021-11-12 2021-11-12 Java code tracking type based data acquisition method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111336549.4A CN114020255A (en) 2021-11-12 2021-11-12 Java code tracking type based data acquisition method

Publications (1)

Publication Number Publication Date
CN114020255A true CN114020255A (en) 2022-02-08

Family

ID=80063585

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111336549.4A Pending CN114020255A (en) 2021-11-12 2021-11-12 Java code tracking type based data acquisition method

Country Status (1)

Country Link
CN (1) CN114020255A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114911682A (en) * 2022-05-23 2022-08-16 融创物业服务集团有限公司 Pluggable log monitoring method
CN115022389A (en) * 2022-05-26 2022-09-06 携程旅游网络技术(上海)有限公司 Method, system, electronic device and storage medium for processing full-link information

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090138893A1 (en) * 2007-11-23 2009-05-28 Ketera Technologies Inc. Interceptor Framework Using Java Dynamic Proxies
CN107092488A (en) * 2017-03-31 2017-08-25 武汉斗鱼网络科技有限公司 It is a kind of that application is carried out to bury realization method and system a little without intrusionization
CN108898007A (en) * 2018-06-26 2018-11-27 焦点科技股份有限公司 A kind of safety method based on JavaAgent and dll enhancing Java distribution software
CN112346778A (en) * 2020-10-28 2021-02-09 常州微亿智造科技有限公司 Optimization method for automatically generating byte codes during compiling of Java program

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090138893A1 (en) * 2007-11-23 2009-05-28 Ketera Technologies Inc. Interceptor Framework Using Java Dynamic Proxies
CN107092488A (en) * 2017-03-31 2017-08-25 武汉斗鱼网络科技有限公司 It is a kind of that application is carried out to bury realization method and system a little without intrusionization
CN108898007A (en) * 2018-06-26 2018-11-27 焦点科技股份有限公司 A kind of safety method based on JavaAgent and dll enhancing Java distribution software
CN112346778A (en) * 2020-10-28 2021-02-09 常州微亿智造科技有限公司 Optimization method for automatically generating byte codes during compiling of Java program

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
VIVO互联网技术: "字节码增强:原理与实战", pages 8 - 12, Retrieved from the Internet <URL:https://segmentfault.com/a/1190000037602678> *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114911682A (en) * 2022-05-23 2022-08-16 融创物业服务集团有限公司 Pluggable log monitoring method
CN115022389A (en) * 2022-05-26 2022-09-06 携程旅游网络技术(上海)有限公司 Method, system, electronic device and storage medium for processing full-link information
CN115022389B (en) * 2022-05-26 2024-12-20 携程旅游网络技术(上海)有限公司 Full-link information processing method, system, electronic device and storage medium

Similar Documents

Publication Publication Date Title
TWI648648B (en) Protection method of executable program on android platform
CN107092488B (en) Method and system for realizing non-invasive point burying of application
Baker et al. Runtime aspect weaving through metaprogramming
CN102508668B (en) AOP (Aspect Oriented Programming) implementation method of EJB 3 (Enterprise Java Beans 3) containers based on dynamic stack
Golm et al. MetaXa and the Future of Reflection
CN114020255A (en) Java code tracking type based data acquisition method
Castanos et al. On the benefits and pitfalls of extending a statically typed language JIT compiler for dynamic scripting languages
WO2019136844A1 (en) Aop proxy framework implementation method and system, and storage medium and electronic device
US8549506B2 (en) Resumable methods
CN107577925B (en) Android Application Protection Method Based on Dual ARM Instruction Virtualization
CN110659031A (en) Application program compilation method, device, electronic device and storage medium
CN114595462B (en) Data processing method and device
CN107301347A (en) A kind of method that Hbuilder App calling figures are obtained based on static analysis
Chiba et al. Aspect-oriented programming beyond dependency injection
Luckow et al. HVMTP: a time predictable and portable java virtual machine for hard real-time embedded systems
Palacz et al. Incommunicado: efficient communication for isolates
CN112558976B (en) Self-adaptive function loading method for just-in-time compiling engine
Fuad et al. Transformation of existing programs into autonomic and self-healing entities
US20110321009A1 (en) Implementing encryption via aspect oriented programming
CN113419919B (en) Method for thread monitoring of third party SDK
CN113126969A (en) Interface conversion method and system
CN114816414B (en) A code system, a code execution method, a code compilation method, and a device thereof
CN115270115B (en) Method and system for collecting edge application behavior information
Cheng et al. Sedalvik: A kernel-level android behavior forensic method
CN102375740A (en) Handheld device and method for implementing interoperation of Java component and custom member by same

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination