Skip to content

Commit a541fca

Browse files
authored
add period to service filter regular expression in logging config (#9631) (#9634)
1 parent 65677d0 commit a541fca

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

gcp-observability/src/main/java/io/grpc/gcp/observability/ObservabilityConfigImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ final class ObservabilityConfigImpl implements ObservabilityConfig {
5050
private static final double EPSILON = 1e-6;
5151

5252
private static final Pattern METHOD_NAME_REGEX =
53-
Pattern.compile("^([*])|((([\\w]+)/((?:\\w+)|[*])))$");
53+
Pattern.compile("^([*])|((([\\w.]+)/((?:\\w+)|[*])))$");
5454

5555
private boolean enableCloudLogging = false;
5656
private boolean enableCloudMonitoring = false;

gcp-observability/src/test/java/io/grpc/gcp/observability/ObservabilityConfigImplTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ public class ObservabilityConfigImplTest {
9494
+ " }\n"
9595
+ "}";
9696

97+
private static final String VALID_LOG_FILTERS = "{\n"
98+
+ " \"project_id\": \"grpc-testing\",\n"
99+
+ " \"cloud_logging\": {\n"
100+
+ " \"server_rpc_events\": [{\n"
101+
+ " \"methods\": [\"service.Service1/*\", \"service2.Service4/method4\"],\n"
102+
+ " \"max_metadata_bytes\": 16,\n"
103+
+ " \"max_message_bytes\": 64\n"
104+
+ " }"
105+
+ " ]\n"
106+
+ " }\n"
107+
+ "}";
108+
109+
97110
private static final String PROJECT_ID = "{\n"
98111
+ " \"project_id\": \"grpc-testing\",\n"
99112
+ " \"cloud_logging\": {},\n"
@@ -460,4 +473,20 @@ public void logFilterInvalidMethod() throws IOException {
460473
"invalid service or method filter");
461474
}
462475
}
476+
477+
@Test
478+
public void validLogFilter() throws Exception {
479+
observabilityConfig.parse(VALID_LOG_FILTERS);
480+
assertTrue(observabilityConfig.isEnableCloudLogging());
481+
assertThat(observabilityConfig.getProjectId()).isEqualTo("grpc-testing");
482+
List<LogFilter> logFilterList = observabilityConfig.getServerLogFilters();
483+
assertThat(logFilterList).hasSize(1);
484+
assertThat(logFilterList.get(0).headerBytes).isEqualTo(16);
485+
assertThat(logFilterList.get(0).messageBytes).isEqualTo(64);
486+
assertThat(logFilterList.get(0).excludePattern).isFalse();
487+
assertThat(logFilterList.get(0).matchAll).isFalse();
488+
assertThat(logFilterList.get(0).services).isEqualTo(Collections.singleton("service.Service1"));
489+
assertThat(logFilterList.get(0).methods)
490+
.isEqualTo(Collections.singleton("service2.Service4/method4"));
491+
}
463492
}

0 commit comments

Comments
 (0)