The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#) https://grpc.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.4 KiB

[logging] Centralize configuration for trace flags (#36576) All TraceFlags are now configured in `src/core/lib/debug/trace_flags.yaml`. The format is: ``` my_flag: default: false # the default value; default=false description: Some Description debug_only: false # debug_only flags only work in debug builds; default=false internal: false # internal flags will not show up in documentation; default=false ``` To regenerate the trace flag source code, run `tools/codegen/core/gen_trace_flags.py` (requires mako). This script is also run when sanity checking. This PR also adds two new features: ### Glob-based flag configuration Trace flag configuration now supports `?` (single wildcard character) and `*` (one or more wildcard characters). For example, using `GRPC_TRACE='event_engine*'` will enable all flags that match that glob. It expands to: * event_engine * event_engine_client_channel_resolver * event_engine_dns * event_engine_endpoint * event_engine_endpoint_data * event_engine_poller ### A cleaner trace-logging macro in abseil logging format If your goal is only to add log statements when the `fault_injection_filter` trace flag is enabled, you can use the macro: ``` GRPC_TRACE_LOG(fault_injection, INFO) << "Filtered:" << 42; ``` When the trace flag is enabled, the the log will show something like this: ``` I0000 00:00:1715733657.430042 16 file.cc:174] Filtered:42 ``` ---- Note: just like with the gpr_log to abseil logging conversion, the pre-existing trace logging usages can be replaced with the new tracing macro across multiple PRs. Closes #36576 PiperOrigin-RevId: 641295215
6 months ago
// Copyright 2024 The gRPC Authors
//
// Licensed 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.
#include "src/core/lib/gprpp/glob.h"
#include "absl/strings/match.h"
#include "gtest/gtest.h"
#include <grpc/grpc.h>
#include "test/core/test_util/test_config.h"
namespace grpc_core {
namespace testing {
TEST(GlobTest, DefaultsToStringMatching) {
EXPECT_TRUE(GlobMatch("arst", "arst"));
}
TEST(GlobTest, AsteriskMatchesMultipleCharacters) {
EXPECT_TRUE(GlobMatch("a", "*"));
EXPECT_TRUE(GlobMatch("arst", "*"));
}
TEST(GlobTest, QuestionMarkMatchesSingleCharacter) {
EXPECT_TRUE(GlobMatch("a", "?"));
EXPECT_FALSE(GlobMatch("arst", "?"));
}
TEST(GlobTest, AsteriskMatchesEmpty) { EXPECT_TRUE(GlobMatch("", "*")); }
TEST(GlobTest, QuestionMarkDoesNotMatcheEmpty) {
EXPECT_FALSE(GlobMatch("", "?"));
}
TEST(GlobTest, EmbeddedAsterisk) {
EXPECT_TRUE(GlobMatch("arst", "a*t"));
EXPECT_TRUE(GlobMatch("arst", "*rst"));
EXPECT_TRUE(GlobMatch("arst", "ar*"));
EXPECT_TRUE(GlobMatch("arst", "*r*"));
EXPECT_FALSE(GlobMatch("arst", "*q*"));
EXPECT_FALSE(GlobMatch("*arst", "**q*"));
}
TEST(GlobTest, EmbeddedQuestionMark) {
EXPECT_TRUE(GlobMatch("arst", "?rst"));
EXPECT_TRUE(GlobMatch("arst", "a?st"));
EXPECT_TRUE(GlobMatch("arst", "ar?t"));
EXPECT_TRUE(GlobMatch("arst", "ars?"));
EXPECT_TRUE(GlobMatch("arst", "??s?"));
EXPECT_TRUE(GlobMatch("?arst", "???s?"));
EXPECT_FALSE(GlobMatch("?arst", "arst"));
}
TEST(GlobTest, BothWildcardsWorkTogether) {
EXPECT_TRUE(GlobMatch("arst", "?r*"));
EXPECT_TRUE(GlobMatch("arst", "*s?"));
EXPECT_TRUE(GlobMatch("arst", "a?*"));
EXPECT_TRUE(GlobMatch("arst", "*?t"));
}
} // namespace testing
} // namespace grpc_core
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
grpc_init();
auto res = RUN_ALL_TESTS();
grpc_shutdown();
return res;
}