GeezerVison is showing github.com — Merge pull request #23 from uavorg/master · windgoogle/uavstack@25a197d
File treeExpand file treeCollapse file tree Open diff view settings com.creditease.uav.base/src/main/java/com/creditease/agent/profile/api com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm com.creditease.uav.monitorframework/src/main/java/com/creditease/uav
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: com.creditease.uav.base/src/main/java/com/creditease/agent/profile/api/StandardProfileModeler.java +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -900,6 +900,12 @@ private void getSpringMVCURLs(String springMVCBaseUrl, Map<String, Set<String>> | 900 | 900 | if (annoWebService != null) { | 901 | 901 |
| 902 | 902 | resourceClassRelativePaths = (List<String>) annoWebService.get("value"); | | 903 | + /** | | 904 | + * NOTE: RequestMapping can setup a path by 'value' or 'path' | | 905 | + */ | | 906 | + if (resourceClassRelativePaths == null) { | | 907 | + resourceClassRelativePaths = (List<String>) annoWebService.get("path"); | | 908 | + } | 903 | 909 | } | 904 | 910 |
| 905 | 911 | /** | @@ -968,6 +974,11 @@ private void getSpringMVCURLs(String springMVCBaseUrl, Map<String, Set<String>> | 968 | 974 |
| 969 | 975 | List<String> methodRelativePaths = (List<String>) pathAnnoInfo.get("value"); | 970 | 976 |
| | 977 | + // try to get info from filed 'path' | | 978 | + if (methodRelativePaths == null) { | | 979 | + methodRelativePaths = (List<String>) pathAnnoInfo.get("path"); | | 980 | + } | | 981 | + | 971 | 982 | // FIX NPE | 972 | 983 | if (methodRelativePaths == null) { | 973 | 984 | compServicesURLs.add(serviceURL); | |
Collapse file Copy file name to clipboardExpand all lines: com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/RewriteIvcOutputStream.java +34-8Lines changed: 34 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 | package com.creditease.uav.apm; | 22 | 22 |
| 23 | 23 | import java.io.IOException; | 24 | | -import java.util.concurrent.atomic.AtomicBoolean; | 25 | 24 |
| 26 | 25 | import javax.servlet.ServletOutputStream; | 27 | 26 |
| | 27 | +import com.creditease.agent.helpers.DataConvertHelper; | 28 | 28 | import com.creditease.agent.helpers.StringHelper; | 29 | 29 |
| 30 | 30 | public class RewriteIvcOutputStream extends ServletOutputStream { | 31 | 31 |
| | 32 | + private static final int bodyLength = DataConvertHelper | | 33 | + .toInt(System.getProperty("com.creditease.uav.ivcdat.rpc.body"), 2000); | | 34 | + | 32 | 35 | private ServletOutputStream outputStream; | 33 | 36 |
| 34 | 37 | private StringBuilder builder = new StringBuilder(); | 35 | 38 |
| 36 | | - private AtomicBoolean isWrited = new AtomicBoolean(); | | 39 | + private Boolean isWrited = false; | 37 | 40 |
| 38 | 41 | private String encoding; | 39 | 42 |
| @@ -50,29 +53,34 @@ public RewriteIvcOutputStream(ServletOutputStream outputStream, String encoding) | 50 | 53 | public void write(byte[] b, int off, int len) throws IOException { | 51 | 54 |
| 52 | 55 | this.outputStream.write(b, off, len); | 53 | | - if (!isWrited.get()) { | 54 | | - builder.append(new String(b, encoding)); | | 56 | + if (!isWrited) { | | 57 | + int remainderLength = getRemainderLength(b.length); | | 58 | + if (remainderLength > 0) { | | 59 | + builder.append(new String(b, off, remainderLength, encoding)); | | 60 | + } | 55 | 61 | } | 56 | 62 | } | 57 | 63 |
| 58 | 64 | @Override | 59 | 65 | public void flush() throws IOException { | 60 | 66 |
| 61 | 67 | this.outputStream.flush(); | 62 | | - isWrited.set(true); | 63 | 68 | } | 64 | 69 |
| 65 | 70 | @Override | 66 | 71 | public void close() throws IOException { | 67 | 72 |
| 68 | 73 | this.outputStream.close(); | 69 | | - isWrited.set(true); | | 74 | + isWrited = true; | 70 | 75 | } | 71 | 76 |
| 72 | 77 | @Override | 73 | 78 | public void write(int b) throws IOException { | 74 | 79 |
| 75 | 80 | this.outputStream.write(b); | | 81 | + if (!isWrited && this.builder.length() < bodyLength) { | | 82 | + builder.append((char) b); | | 83 | + } | 76 | 84 | } | 77 | 85 |
| 78 | 86 | public StringBuilder getContent() { | @@ -86,12 +94,30 @@ public StringBuilder getContent() { | 86 | 94 | public void clearBodyContent() { | 87 | 95 |
| 88 | 96 | this.builder.delete(0, this.builder.length()); | 89 | | - isWrited.set(true); | | 97 | + isWrited = true; | 90 | 98 | } | 91 | 99 |
| 92 | 100 | @Override | 93 | 101 | public void write(byte[] b) throws IOException { | 94 | 102 |
| 95 | 103 | this.outputStream.write(b); | | 104 | + if (!isWrited) { | | 105 | + int remainderLength = getRemainderLength(b.length); | | 106 | + if (remainderLength > 0) { | | 107 | + builder.append(new String(b, 0, remainderLength, encoding)); | | 108 | + } | | 109 | + } | | 110 | + } | | 111 | + | | 112 | + private int getRemainderLength(int length) { | | 113 | + | | 114 | + if (bodyLength <= this.builder.length()) { | | 115 | + return 0; | | 116 | + } | | 117 | + int remainderLength = bodyLength - this.builder.length(); | | 118 | + /** | | 119 | + * simply consider 1 character cost 2 bytes, it's not accurate. | | 120 | + */ | | 121 | + return (2 * remainderLength) < length ? (2 * remainderLength) : length; | 96 | 122 | } | 97 | | -} | | 123 | +} |
Collapse file Copy file name to clipboard +132Lines changed: 132 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/*- | | 2 | + * << | | 3 | + * UAVStack | | 4 | + * == | | 5 | + * Copyright (C) 2016 - 2018 UAVStack | | 6 | + * == | | 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); | | 8 | + * you may not use this file except in compliance with the License. | | 9 | + * You may obtain a copy of the License at | | 10 | + * | | 11 | + * http://www.apache.org/licenses/LICENSE-2.0 | | 12 | + * | | 13 | + * Unless required by applicable law or agreed to in writing, software | | 14 | + * distributed under the License is distributed on an "AS IS" BASIS, | | 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 16 | + * See the License for the specific language governing permissions and | | 17 | + * limitations under the License. | | 18 | + * >> | | 19 | + */ | | 20 | +package com.creditease.uav.apm; | | 21 | + | | 22 | +import java.io.PrintWriter; | | 23 | + | | 24 | +import com.creditease.agent.helpers.DataConvertHelper; | | 25 | + | | 26 | +public class RewriteIvcPrintWriter extends PrintWriter { | | 27 | + | | 28 | + private static final int bodyLength = DataConvertHelper | | 29 | + .toInt(System.getProperty("com.creditease.uav.ivcdat.rpc.body"), 2000); | | 30 | + | | 31 | + private PrintWriter out; | | 32 | + | | 33 | + private StringBuilder builder = new StringBuilder(); | | 34 | + | | 35 | + private Boolean isWrited = false; | | 36 | + | | 37 | + public RewriteIvcPrintWriter(PrintWriter out) { | | 38 | + | | 39 | + super(out); | | 40 | + this.out = out; | | 41 | + } | | 42 | + | | 43 | + public StringBuilder getContent() { | | 44 | + | | 45 | + return this.builder; | | 46 | + } | | 47 | + | | 48 | + public void clearBodyContent() { | | 49 | + | | 50 | + this.builder.delete(0, this.builder.length()); | | 51 | + isWrited = true; | | 52 | + } | | 53 | + | | 54 | + @Override | | 55 | + public void flush() { | | 56 | + | | 57 | + super.flush(); | | 58 | + } | | 59 | + | | 60 | + @Override | | 61 | + public void close() { | | 62 | + | | 63 | + super.close(); | | 64 | + isWrited = true; | | 65 | + } | | 66 | + | | 67 | + @Override | | 68 | + public void write(int c) { | | 69 | + | | 70 | + out.write(c); | | 71 | + if (!isWrited && this.builder.length() < bodyLength) { | | 72 | + this.builder.append((char) c); | | 73 | + } | | 74 | + } | | 75 | + | | 76 | + @Override | | 77 | + public void write(char[] buf, int off, int len) { | | 78 | + | | 79 | + out.write(buf, off, len); | | 80 | + if (!isWrited) { | | 81 | + int remainderLength = getRemainderLength(len); | | 82 | + if (remainderLength > 0) { | | 83 | + this.builder.append(buf, off, remainderLength); | | 84 | + } | | 85 | + } | | 86 | + } | | 87 | + | | 88 | + @Override | | 89 | + public void write(char[] buf) { | | 90 | + | | 91 | + out.write(buf); | | 92 | + if (!isWrited) { | | 93 | + int remainderLength = getRemainderLength(buf.length); | | 94 | + if (remainderLength > 0) { | | 95 | + this.builder.append(buf, 0, remainderLength); | | 96 | + } | | 97 | + } | | 98 | + } | | 99 | + | | 100 | + @Override | | 101 | + public void write(String s, int off, int len) { | | 102 | + | | 103 | + out.write(s, off, len); | | 104 | + if (!isWrited) { | | 105 | + int remainderLength = getRemainderLength(len); | | 106 | + if (remainderLength > 0) { | | 107 | + this.builder.append(s, off, remainderLength); | | 108 | + } | | 109 | + } | | 110 | + } | | 111 | + | | 112 | + @Override | | 113 | + public void write(String s) { | | 114 | + | | 115 | + out.write(s); | | 116 | + if (!isWrited) { | | 117 | + int remainderLength = getRemainderLength(s.length()); | | 118 | + if (remainderLength > 0) { | | 119 | + this.builder.append(s, 0, remainderLength); | | 120 | + } | | 121 | + } | | 122 | + } | | 123 | + | | 124 | + private int getRemainderLength(int length) { | | 125 | + | | 126 | + if (bodyLength <= this.builder.length()) { | | 127 | + return 0; | | 128 | + } | | 129 | + int remainderLength = bodyLength - this.builder.length(); | | 130 | + return remainderLength < length ? remainderLength : length; | | 131 | + } | | 132 | +} |
Collapse file Copy file name to clipboardExpand all lines: com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/RewriteIvcResponseWrapper.java +38-18Lines changed: 38 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 |
| 30 | 30 | public class RewriteIvcResponseWrapper extends HttpServletResponseWrapper { | 31 | 31 |
| 32 | | - private ServletOutputStream outputStream; | 33 | | - | 34 | 32 | private RewriteIvcOutputStream rewriteOutStream; | 35 | 33 |
| 36 | | - private StringBuilder builder; | | 34 | + private RewriteIvcPrintWriter rewritePrintWriter; | | 35 | + | | 36 | + private StringBuilder builder = new StringBuilder(); | 37 | 37 |
| 38 | 38 | private String tag; | 39 | 39 |
| @@ -43,16 +43,6 @@ public RewriteIvcResponseWrapper(HttpServletResponse response, String tag) { | 43 | 43 | super(response); | 44 | 44 | this.tag = tag; | 45 | 45 | this.response = response; | 46 | | - try { | 47 | | - this.outputStream = response.getOutputStream(); | 48 | | - // 由于tomcat等实现类会记录是否调用了getOutputStream方法,故此处进行这种操作 | 49 | | - response.reset(); | 50 | | - } | 51 | | - catch (IOException e) { | 52 | | - // 出现异常时则将异常信息放入 | 53 | | - builder.append(e.toString()); | 54 | | - } | 55 | | - this.rewriteOutStream = new RewriteIvcOutputStream(outputStream, response.getCharacterEncoding()); | 56 | 46 | } | 57 | 47 |
| 58 | 48 | public String getTag() { | @@ -63,27 +53,48 @@ public String getTag() { | 63 | 53 | @Override | 64 | 54 | public ServletOutputStream getOutputStream() throws IOException { | 65 | 55 |
| | 56 | + if (this.rewriteOutStream == null) { | | 57 | + try { | | 58 | + this.rewriteOutStream = new RewriteIvcOutputStream(response.getOutputStream(), | | 59 | + response.getCharacterEncoding()); | | 60 | + } | | 61 | + catch (IOException e) { | | 62 | + // 出现异常时则将异常信息放入 | | 63 | + builder.append(e.toString()); | | 64 | + throw e; | | 65 | + } | | 66 | + } | | 67 | + | 66 | 68 | return this.rewriteOutStream; | 67 | 69 | } | 68 | 70 |
| 69 | 71 | public StringBuilder getContent() { | 70 | 72 |
| 71 | | - if (this.builder == null) { | | 73 | + if (rewriteOutStream != null) { | 72 | 74 | return this.rewriteOutStream.getContent(); | 73 | 75 | } | 74 | | - else { | | 76 | + else if (rewritePrintWriter != null) { | | 77 | + return this.rewritePrintWriter.getContent(); | | 78 | + } | | 79 | + else if (this.builder != null) { | 75 | 80 | return this.builder; | 76 | 81 | } | | 82 | + | | 83 | + return new StringBuilder(); | | 84 | + | 77 | 85 | } | 78 | 86 |
| 79 | 87 | /** | 80 | 88 | * 清空池,方便回收 | 81 | 89 | */ | 82 | 90 | public void clearBodyContent() { | 83 | 91 |
| 84 | | - if (this.builder == null) { | | 92 | + if (rewriteOutStream != null) { | 85 | 93 | this.rewriteOutStream.clearBodyContent(); | 86 | 94 | } | | 95 | + else if (rewritePrintWriter != null) { | | 96 | + this.rewritePrintWriter.clearBodyContent(); | | 97 | + } | 87 | 98 | else { | 88 | 99 | this.builder.delete(0, this.builder.length()); | 89 | 100 | } | @@ -92,7 +103,16 @@ public void clearBodyContent() { | 92 | 103 | @Override | 93 | 104 | public PrintWriter getWriter() throws IOException { | 94 | 105 |
| 95 | | - return this.response.getWriter(); | | 106 | + if (this.rewritePrintWriter == null) { | | 107 | + try { | | 108 | + this.rewritePrintWriter = new RewriteIvcPrintWriter(this.response.getWriter()); | | 109 | + } | | 110 | + catch (IOException e) { | | 111 | + builder.append(e.toString()); | | 112 | + throw e; | | 113 | + } | | 114 | + } | | 115 | + return rewritePrintWriter; | 96 | 116 | } | 97 | 117 |
| 98 | | -} | | 118 | +} |
Collapse file Copy file name to clipboardExpand all lines: com.creditease.uav.monitorframework/src/main/java/com/creditease/uav/profiling/handlers/ComponentProfileHandler.java +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2605,6 +2605,12 @@ private void addAppFrkServiceMapBinding(ProfileServiceMapMgr smgr, String appid, | 2605 | 2605 | if (classAnno != null) { | 2606 | 2606 |
| 2607 | 2607 | value = classAnno.get(classPathAnnoAttrName); | | 2608 | + /** | | 2609 | + * SpringMVC RequestMapping can setup a path by 'value' or 'path' | | 2610 | + */ | | 2611 | + if (value == null) { | | 2612 | + value = classAnno.get("path"); | | 2613 | + } | 2608 | 2614 | } | 2609 | 2615 | else if (classPathAnnoClass.equals("org.springframework.web.bind.annotation.RequestMapping")) { | 2610 | 2616 | /** | @@ -2683,6 +2689,13 @@ else if (classPathAnnoClass.equals("org.springframework.web.bind.annotation.Requ | 2683 | 2689 |
| 2684 | 2690 | Object pvalue = methodPathAnno.get("value"); | 2685 | 2691 |
| | 2692 | + /** | | 2693 | + * SpringMVC RequestMapping can setup a path by 'value' or 'path' | | 2694 | + */ | | 2695 | + if (pvalue == null) { | | 2696 | + pvalue = methodPathAnno.get("path"); | | 2697 | + } | | 2698 | + | 2686 | 2699 | if (pvalue == null) { | 2687 | 2700 | continue; | 2688 | 2701 | } | |
|