Skip to content

Commit 9a21419

Browse files
authored
Rename blocking module to filter and define additional evaluate methods (#89)
* Rename blocking module to filter Signed-off-by: Pavol Loffay <[email protected]> * Define filter interface Signed-off-by: Pavol Loffay <[email protected]> * Working Signed-off-by: Pavol Loffay <[email protected]> * Rename package Signed-off-by: Pavol Loffay <[email protected]> * Rename blocking module to filter Signed-off-by: Pavol Loffay <[email protected]> * Fix muzzle Signed-off-by: Pavol Loffay <[email protected]> * Simplify Signed-off-by: Pavol Loffay <[email protected]> * Add span to interface Signed-off-by: Pavol Loffay <[email protected]>
1 parent 848dbc3 commit 9a21419

File tree

20 files changed

+147
-150
lines changed

20 files changed

+147
-150
lines changed

blocking/build.gradle.kts

Lines changed: 0 additions & 4 deletions
This file was deleted.

blocking/src/main/java/org/hypertrace/agent/blocking/BlockingProvider.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

filter/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`java-library`
3+
}
4+
5+
dependencies {
6+
implementation("io.opentelemetry:opentelemetry-api:0.9.1")
7+
}

blocking/src/main/java/org/hypertrace/agent/blocking/ExecutionBlocked.java renamed to filter/src/main/java/org/hypertrace/agent/filter/ExecutionBlocked.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.hypertrace.agent.blocking;
17+
package org.hypertrace.agent.filter;
1818

1919
/** Indicates that the execution should be blocked. */
20-
class ExecutionBlocked implements BlockingResult {
21-
private final String reason;
20+
class ExecutionBlocked implements FilterResult {
2221

23-
public ExecutionBlocked(String reason) {
24-
this.reason = reason;
25-
}
22+
static ExecutionBlocked INSTANCE = new ExecutionBlocked();
23+
24+
private ExecutionBlocked() {}
2625

2726
@Override
2827
public boolean blockExecution() {
2928
return true;
3029
}
31-
32-
@Override
33-
public String getReason() {
34-
return reason;
35-
}
3630
}

blocking/src/main/java/org/hypertrace/agent/blocking/ExecutionNotBlocked.java renamed to filter/src/main/java/org/hypertrace/agent/filter/ExecutionNotBlocked.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.hypertrace.agent.blocking;
17+
package org.hypertrace.agent.filter;
1818

19-
class ExecutionNotBlocked implements BlockingResult {
19+
class ExecutionNotBlocked implements FilterResult {
2020

2121
static ExecutionNotBlocked INSTANCE = new ExecutionNotBlocked();
2222

@@ -26,9 +26,4 @@ private ExecutionNotBlocked() {}
2626
public boolean blockExecution() {
2727
return false;
2828
}
29-
30-
@Override
31-
public String getReason() {
32-
return null;
33-
}
3429
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright The Hypertrace Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.hypertrace.agent.filter;
18+
19+
import io.opentelemetry.trace.Span;
20+
import java.util.Map;
21+
22+
/**
23+
* {@link FilterEvaluator} evaluates given request/RPC and the result is used to block further
24+
* processing of the request.
25+
*/
26+
public interface FilterEvaluator {
27+
28+
/**
29+
* Evaluate the execution.
30+
*
31+
* @param headers are used for blocking evaluation.
32+
* @return filter result
33+
*/
34+
FilterResult evaluateRequestHeaders(Span span, Map<String, String> headers);
35+
36+
/**
37+
* Evaluate the execution.
38+
*
39+
* @param body request body
40+
* @return filter result
41+
*/
42+
FilterResult evaluateRequestBody(Span span, String body);
43+
}

blocking/src/main/java/org/hypertrace/agent/blocking/BlockingEvaluator.java renamed to filter/src/main/java/org/hypertrace/agent/filter/FilterProvider.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.hypertrace.agent.blocking;
17+
package org.hypertrace.agent.filter;
1818

19-
import java.util.Map;
19+
/** Returns an instance of {@link FilterEvaluator}. */
20+
public class FilterProvider {
2021

21-
/** Blocking evaluator. */
22-
public interface BlockingEvaluator {
22+
private FilterProvider() {}
2323

2424
/**
25-
* Evaluate if execution should be blocked.
25+
* Get {@link FilterEvaluator}
2626
*
27-
* @param attributes are used for blocking evaluation.
28-
* @return blocking result
27+
* @return the filter evaluator.
2928
*/
30-
BlockingResult evaluate(Map<String, String> attributes);
29+
public static FilterEvaluator getFilterEvaluator() {
30+
return MockFilterEvaluator.INSTANCE;
31+
}
3132
}

blocking/src/main/java/org/hypertrace/agent/blocking/BlockingResult.java renamed to filter/src/main/java/org/hypertrace/agent/filter/FilterResult.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.hypertrace.agent.blocking;
17+
package org.hypertrace.agent.filter;
1818

19-
/** Result of blocking evaluation from {@link BlockingEvaluator} */
20-
public interface BlockingResult {
19+
/** Result of filter evaluation from {@link FilterEvaluator} */
20+
public interface FilterResult {
2121

2222
/**
23-
* Indicates that execution should be blocked.
23+
* Indicates whether the execution should be blocked.
2424
*
25-
* @return true if execution should be blocked otherwise false
25+
* @return true if execution should be blocked otherwise false.
2626
*/
2727
boolean blockExecution();
28-
29-
/**
30-
* The reason why execution was blocked.
31-
*
32-
* @return the reason why execution was blocked.
33-
*/
34-
String getReason();
3528
}

blocking/src/main/java/org/hypertrace/agent/blocking/MockBlockingEvaluator.java renamed to filter/src/main/java/org/hypertrace/agent/filter/MockFilterEvaluator.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,29 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.hypertrace.agent.blocking;
17+
package org.hypertrace.agent.filter;
1818

19+
import io.opentelemetry.trace.Span;
1920
import java.util.Map;
2021

2122
/** Mock blocking evaluator, blocks execution if an attribute with "block" key is present. */
22-
class MockBlockingEvaluator implements BlockingEvaluator {
23+
class MockFilterEvaluator implements FilterEvaluator {
2324

24-
public static MockBlockingEvaluator INSTANCE = new MockBlockingEvaluator();
25+
private MockFilterEvaluator() {}
2526

26-
private MockBlockingEvaluator() {}
27+
public static MockFilterEvaluator INSTANCE = new MockFilterEvaluator();
2728

2829
@Override
29-
public BlockingResult evaluate(Map<String, String> attributes) {
30-
if (attributes.containsKey("block")) {
31-
return new ExecutionBlocked("Header 'block' found");
30+
public FilterResult evaluateRequestHeaders(Span span, Map<String, String> headers) {
31+
if (headers.containsKey("block")) {
32+
span.setAttribute("hypertrace.mock.filter.result", "true");
33+
return ExecutionBlocked.INSTANCE;
3234
}
3335
return ExecutionNotBlocked.INSTANCE;
3436
}
37+
38+
@Override
39+
public FilterResult evaluateRequestBody(Span span, String body) {
40+
return ExecutionNotBlocked.INSTANCE;
41+
}
3542
}

instrumentation/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ subprojects {
1313
implementation("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:0.9.0")
1414
implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:0.9.0")
1515
implementation(project(":javaagent-core"))
16-
implementation(project(":blocking"))
16+
implementation(project(":filter"))
1717
}
1818

1919
// This ensures to build jars for all dependencies in instrumentation module for ByteBuddy

0 commit comments

Comments
 (0)