Skip to content

Commit 6973c0b

Browse files
authored
Merge pull request #58 from intergral/logging
feat(logging): initial implementation of tracepoint logging
2 parents 0931cf8 + c4de31a commit 6973c0b

File tree

34 files changed

+4978
-14
lines changed

34 files changed

+4978
-14
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Listen_for_Docker_debug_connections.xml renamed to .idea/runConfigurations/Connect_to_Remote_Debugger.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Listen_for_debug_connections.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The default license for this project is [AGPL-3.0-only](LICENSE).
99
The following folders and their subfolders are licensed under Apache-2.0:
1010

1111
```
12-
12+
agent-api/src/main/java/com/intergral/deep/agent/api/utils/string
1313
```
1414

1515
The following file or directories and their subdirectories are licensed under their original upstream licenses:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2023 Intergral GmbH
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.intergral.deep.agent.api.logger;
19+
20+
/**
21+
* Tracepoint logger is used to log the result of an injected log message.
22+
*/
23+
public interface ITracepointLogger {
24+
25+
/**
26+
* Log the result of a tracepoint injected log message.
27+
*
28+
* @param logMsg the processed log message
29+
* @param tracepointId the tracepoint id that triggered the log
30+
* @param snapshotId the snapshot id of the generated snapshot from the log
31+
*/
32+
void logTracepoint(final String logMsg, final String tracepointId, final String snapshotId);
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2023 Intergral GmbH
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.intergral.deep.agent.api.logger;
19+
20+
/**
21+
* Log the tracepoint logs to {@link System#out}.
22+
*/
23+
public class StdOutLogger implements ITracepointLogger {
24+
25+
@Override
26+
public void logTracepoint(final String logMsg, final String tracepointId, final String snapshotId) {
27+
final String format = String.format("%s snapshot=%s tracepoint=%s", logMsg, tracepointId, snapshotId);
28+
System.out.println(format);
29+
}
30+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2023 Intergral GmbH
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.intergral.deep.agent.api.logger;
19+
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
/**
24+
* This is the default tracepoint logger that will log to the default Deep logger.
25+
*/
26+
public class TracepointLogger implements ITracepointLogger {
27+
28+
private static final Logger LOGGER = LoggerFactory.getLogger(TracepointLogger.class);
29+
30+
@Override
31+
public void logTracepoint(final String logMsg, final String tracepointId, final String snapshotId) {
32+
final String format = String.format("%s snapshot=%s tracepoint=%s", logMsg, tracepointId, snapshotId);
33+
LOGGER.info(format);
34+
}
35+
}

agent-api/src/main/java/com/intergral/deep/agent/api/plugin/IPlugin.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,19 @@ interface IPluginRegistration extends IRegistration<IPlugin> {
8080
* to use this provider, else {@code false}
8181
*/
8282
boolean isAuthProvider();
83+
84+
/**
85+
* Indicates if this plugin is being used to decorate the resource data.
86+
*
87+
* @return {@code true} if this plugin was used to decorate the resource data, else {@code false}.
88+
*/
89+
boolean isResourceProvider();
90+
91+
/**
92+
* Indicates if this plugin is being used to log tracepoints.
93+
*
94+
* @return {@code true} if this plugin is being used to log the tracepoint logs, else {@code false}.
95+
*/
96+
boolean isTracepointLogger();
8397
}
8498
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache license, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the license for the specific language governing permissions and
15+
* limitations under the license.
16+
*/
17+
18+
package com.intergral.deep.agent.api.utils.string;
19+
20+
import java.util.Arrays;
21+
22+
/**
23+
* A matcher class that can be queried to determine if a character array portion matches.
24+
* <p>
25+
* This class comes complete with various factory methods. If these do not suffice, you can subclass and implement your own matcher.
26+
*
27+
* @since 1.3
28+
*/
29+
abstract class AbstractStringMatcher implements StringMatcher {
30+
31+
/**
32+
* Class used to define a character for matching purposes.
33+
*/
34+
static final class CharMatcher extends AbstractStringMatcher {
35+
36+
/**
37+
* The character to match.
38+
*/
39+
private final char ch;
40+
41+
/**
42+
* Constructor that creates a matcher that matches a single character.
43+
*
44+
* @param ch the character to match
45+
*/
46+
CharMatcher(final char ch) {
47+
super();
48+
this.ch = ch;
49+
}
50+
51+
/**
52+
* Returns whether or not the given character matches.
53+
*
54+
* @param buffer the text content to match against, do not change
55+
* @param pos the starting position for the match, valid for buffer
56+
* @param bufferStart the first active index in the buffer, valid for buffer
57+
* @param bufferEnd the end index of the active buffer, valid for buffer
58+
* @return the number of matching characters, zero for no match
59+
*/
60+
@Override
61+
public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) {
62+
return ch == buffer[pos] ? 1 : 0;
63+
}
64+
}
65+
66+
67+
/**
68+
* Class used to match no characters.
69+
*/
70+
static final class NoMatcher extends AbstractStringMatcher {
71+
72+
/**
73+
* Constructs a new instance of <code>NoMatcher</code>.
74+
*/
75+
NoMatcher() {
76+
super();
77+
}
78+
79+
/**
80+
* Always returns <code>false</code>.
81+
*
82+
* @param buffer the text content to match against, do not change
83+
* @param pos the starting position for the match, valid for buffer
84+
* @param bufferStart the first active index in the buffer, valid for buffer
85+
* @param bufferEnd the end index of the active buffer, valid for buffer
86+
* @return the number of matching characters, zero for no match
87+
*/
88+
@Override
89+
public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) {
90+
return 0;
91+
}
92+
}
93+
94+
/**
95+
* Class used to define a set of characters for matching purposes.
96+
*/
97+
static final class StringMatcher extends AbstractStringMatcher {
98+
99+
/**
100+
* The string to match, as a character array.
101+
*/
102+
private final char[] chars;
103+
104+
/**
105+
* Constructor that creates a matcher from a String.
106+
*
107+
* @param str the string to match, must not be null
108+
*/
109+
StringMatcher(final String str) {
110+
super();
111+
chars = str.toCharArray();
112+
}
113+
114+
/**
115+
* Returns whether or not the given text matches the stored string.
116+
*
117+
* @param buffer the text content to match against, do not change
118+
* @param pos the starting position for the match, valid for buffer
119+
* @param bufferStart the first active index in the buffer, valid for buffer
120+
* @param bufferEnd the end index of the active buffer, valid for buffer
121+
* @return the number of matching characters, zero for no match
122+
*/
123+
@Override
124+
public int isMatch(final char[] buffer, int pos, final int bufferStart, final int bufferEnd) {
125+
final int len = chars.length;
126+
if (pos + len > bufferEnd) {
127+
return 0;
128+
}
129+
for (int i = 0; i < chars.length; i++, pos++) {
130+
if (chars[i] != buffer[pos]) {
131+
return 0;
132+
}
133+
}
134+
return len;
135+
}
136+
137+
@Override
138+
public String toString() {
139+
return super.toString() + ' ' + Arrays.toString(chars);
140+
}
141+
142+
}
143+
144+
145+
/**
146+
* Constructor.
147+
*/
148+
protected AbstractStringMatcher() {
149+
super();
150+
}
151+
152+
/**
153+
* Returns the number of matching characters, zero for no match.
154+
* <p>
155+
* This method is called to check for a match. The parameter <code>pos</code> represents the current position to be checked in the string
156+
* <code>buffer</code> (a character array which must not be changed). The API guarantees that
157+
* <code>pos</code> is a valid index for <code>buffer</code>.
158+
* <p>
159+
* The matching code may check one character or many. It may check characters preceding <code>pos</code> as well as those after.
160+
* <p>
161+
* It must return zero for no match, or a positive number if a match was found. The number indicates the number of characters that
162+
* matched.
163+
*
164+
* @param buffer the text content to match against, do not change
165+
* @param pos the starting position for the match, valid for buffer
166+
* @return the number of matching characters, zero for no match
167+
*/
168+
public int isMatch(final char[] buffer, final int pos) {
169+
return isMatch(buffer, pos, 0, buffer.length);
170+
}
171+
172+
}

0 commit comments

Comments
 (0)