Skip to content

Commit

Permalink
Merge pull request #58 from intergral/logging
Browse files Browse the repository at this point in the history
feat(logging): initial implementation of tracepoint logging
  • Loading branch information
Umaaz authored Nov 2, 2023
2 parents 0931cf8 + c4de31a commit 6973c0b
Show file tree
Hide file tree
Showing 34 changed files with 4,978 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/runConfigurations/Listen_for_debug_connections.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion LICENSING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The default license for this project is [AGPL-3.0-only](LICENSE).
The following folders and their subfolders are licensed under Apache-2.0:

```
agent-api/src/main/java/com/intergral/deep/agent/api/utils/string
```

The following file or directories and their subdirectories are licensed under their original upstream licenses:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2023 Intergral GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.intergral.deep.agent.api.logger;

/**
* Tracepoint logger is used to log the result of an injected log message.
*/
public interface ITracepointLogger {

/**
* Log the result of a tracepoint injected log message.
*
* @param logMsg the processed log message
* @param tracepointId the tracepoint id that triggered the log
* @param snapshotId the snapshot id of the generated snapshot from the log
*/
void logTracepoint(final String logMsg, final String tracepointId, final String snapshotId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2023 Intergral GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.intergral.deep.agent.api.logger;

/**
* Log the tracepoint logs to {@link System#out}.
*/
public class StdOutLogger implements ITracepointLogger {

@Override
public void logTracepoint(final String logMsg, final String tracepointId, final String snapshotId) {
final String format = String.format("%s snapshot=%s tracepoint=%s", logMsg, tracepointId, snapshotId);
System.out.println(format);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2023 Intergral GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.intergral.deep.agent.api.logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This is the default tracepoint logger that will log to the default Deep logger.
*/
public class TracepointLogger implements ITracepointLogger {

private static final Logger LOGGER = LoggerFactory.getLogger(TracepointLogger.class);

@Override
public void logTracepoint(final String logMsg, final String tracepointId, final String snapshotId) {
final String format = String.format("%s snapshot=%s tracepoint=%s", logMsg, tracepointId, snapshotId);
LOGGER.info(format);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,19 @@ interface IPluginRegistration extends IRegistration<IPlugin> {
* to use this provider, else {@code false}
*/
boolean isAuthProvider();

/**
* Indicates if this plugin is being used to decorate the resource data.
*
* @return {@code true} if this plugin was used to decorate the resource data, else {@code false}.
*/
boolean isResourceProvider();

/**
* Indicates if this plugin is being used to log tracepoints.
*
* @return {@code true} if this plugin is being used to log the tracepoint logs, else {@code false}.
*/
boolean isTracepointLogger();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/

package com.intergral.deep.agent.api.utils.string;

import java.util.Arrays;

/**
* A matcher class that can be queried to determine if a character array portion matches.
* <p>
* This class comes complete with various factory methods. If these do not suffice, you can subclass and implement your own matcher.
*
* @since 1.3
*/
abstract class AbstractStringMatcher implements StringMatcher {

/**
* Class used to define a character for matching purposes.
*/
static final class CharMatcher extends AbstractStringMatcher {

/**
* The character to match.
*/
private final char ch;

/**
* Constructor that creates a matcher that matches a single character.
*
* @param ch the character to match
*/
CharMatcher(final char ch) {
super();
this.ch = ch;
}

/**
* Returns whether or not the given character matches.
*
* @param buffer the text content to match against, do not change
* @param pos the starting position for the match, valid for buffer
* @param bufferStart the first active index in the buffer, valid for buffer
* @param bufferEnd the end index of the active buffer, valid for buffer
* @return the number of matching characters, zero for no match
*/
@Override
public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) {
return ch == buffer[pos] ? 1 : 0;
}
}


/**
* Class used to match no characters.
*/
static final class NoMatcher extends AbstractStringMatcher {

/**
* Constructs a new instance of <code>NoMatcher</code>.
*/
NoMatcher() {
super();
}

/**
* Always returns <code>false</code>.
*
* @param buffer the text content to match against, do not change
* @param pos the starting position for the match, valid for buffer
* @param bufferStart the first active index in the buffer, valid for buffer
* @param bufferEnd the end index of the active buffer, valid for buffer
* @return the number of matching characters, zero for no match
*/
@Override
public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) {
return 0;
}
}

/**
* Class used to define a set of characters for matching purposes.
*/
static final class StringMatcher extends AbstractStringMatcher {

/**
* The string to match, as a character array.
*/
private final char[] chars;

/**
* Constructor that creates a matcher from a String.
*
* @param str the string to match, must not be null
*/
StringMatcher(final String str) {
super();
chars = str.toCharArray();
}

/**
* Returns whether or not the given text matches the stored string.
*
* @param buffer the text content to match against, do not change
* @param pos the starting position for the match, valid for buffer
* @param bufferStart the first active index in the buffer, valid for buffer
* @param bufferEnd the end index of the active buffer, valid for buffer
* @return the number of matching characters, zero for no match
*/
@Override
public int isMatch(final char[] buffer, int pos, final int bufferStart, final int bufferEnd) {
final int len = chars.length;
if (pos + len > bufferEnd) {
return 0;
}
for (int i = 0; i < chars.length; i++, pos++) {
if (chars[i] != buffer[pos]) {
return 0;
}
}
return len;
}

@Override
public String toString() {
return super.toString() + ' ' + Arrays.toString(chars);
}

}


/**
* Constructor.
*/
protected AbstractStringMatcher() {
super();
}

/**
* Returns the number of matching characters, zero for no match.
* <p>
* This method is called to check for a match. The parameter <code>pos</code> represents the current position to be checked in the string
* <code>buffer</code> (a character array which must not be changed). The API guarantees that
* <code>pos</code> is a valid index for <code>buffer</code>.
* <p>
* The matching code may check one character or many. It may check characters preceding <code>pos</code> as well as those after.
* <p>
* It must return zero for no match, or a positive number if a match was found. The number indicates the number of characters that
* matched.
*
* @param buffer the text content to match against, do not change
* @param pos the starting position for the match, valid for buffer
* @return the number of matching characters, zero for no match
*/
public int isMatch(final char[] buffer, final int pos) {
return isMatch(buffer, pos, 0, buffer.length);
}

}
Loading

0 comments on commit 6973c0b

Please sign in to comment.