-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use protobuf reflection for loading runtime configuration #2025
base: master
Are you sure you want to change the base?
Conversation
This change is based upon a toy project I have at https://github.com/Molter73/config-much. The basic idea is to use the reflection API from protobuf to populate the runtime configuration structures, which should allow us to add new fields to our protobuf definitions and have them magically show up in our code to use.
collector/lib/ConfigLoader.cpp
Outdated
case FieldDescriptor::CPPTYPE_INT32: | ||
return ParseArrayInner<int32>(msg, node, field); | ||
case FieldDescriptor::CPPTYPE_UINT32: | ||
return ParseArrayInner<uint32_t>(msg, node, field); | ||
case google::protobuf::FieldDescriptor::CPPTYPE_INT64: | ||
return ParseArrayInner<int64_t>(msg, node, field); | ||
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: | ||
return ParseArrayInner<uint64_t>(msg, node, field); | ||
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: | ||
return ParseArrayInner<double>(msg, node, field); | ||
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: | ||
return ParseArrayInner<float>(msg, node, field); | ||
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: | ||
return ParseArrayInner<bool>(msg, node, field); | ||
case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: | ||
return ParseArrayEnum(msg, node, field); | ||
case google::protobuf::FieldDescriptor::CPPTYPE_STRING: | ||
return ParseArrayInner<std::string>(msg, node, field); | ||
case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: { | ||
return {{"Unsupport repeated type MESSAGE"}}; | ||
} break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
case FieldDescriptor::CPPTYPE_INT32: | |
return ParseArrayInner<int32>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_UINT32: | |
return ParseArrayInner<uint32_t>(msg, node, field); | |
case google::protobuf::FieldDescriptor::CPPTYPE_INT64: | |
return ParseArrayInner<int64_t>(msg, node, field); | |
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: | |
return ParseArrayInner<uint64_t>(msg, node, field); | |
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: | |
return ParseArrayInner<double>(msg, node, field); | |
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: | |
return ParseArrayInner<float>(msg, node, field); | |
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: | |
return ParseArrayInner<bool>(msg, node, field); | |
case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: | |
return ParseArrayEnum(msg, node, field); | |
case google::protobuf::FieldDescriptor::CPPTYPE_STRING: | |
return ParseArrayInner<std::string>(msg, node, field); | |
case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: { | |
return {{"Unsupport repeated type MESSAGE"}}; | |
} break; | |
case FieldDescriptor::CPPTYPE_INT32: | |
return ParseArrayInner<int32>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_UINT32: | |
return ParseArrayInner<uint32_t>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_INT64: | |
return ParseArrayInner<int64_t>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_UINT64: | |
return ParseArrayInner<uint64_t>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_DOUBLE: | |
return ParseArrayInner<double>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_FLOAT: | |
return ParseArrayInner<float>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_BOOL: | |
return ParseArrayInner<bool>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_ENUM: | |
return ParseArrayEnum(msg, node, field); | |
case FieldDescriptor::CPPTYPE_STRING: | |
return ParseArrayInner<std::string>(msg, node, field); | |
case FieldDescriptor::CPPTYPE_MESSAGE: { | |
return {{"Unsupport repeated type MESSAGE"}}; | |
} break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also going to space them out a bit, it's a little hard to read otherwise.
collector/lib/ConfigLoader.cpp
Outdated
} | ||
|
||
config_.SetRuntimeConfig(std::move(runtime_config)); | ||
CLOG(DEBUG) << "Runtime configuration:\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set this to INFO? I don't think it should trigger often enough to be spamming the log, and would be invaluable to see how Collector is operating at any given moment
Description
This change is based upon a toy project I have at https://github.com/Molter73/config-much.
The basic idea is to use the introspection and reflection APIs from protobuf to populate the runtime configuration structures, which should allow us to add new fields to our protobuf definitions and have them magically show up in our code to use.
This is an alternative implementation to #1993.
Checklist
Automated testing
If any of these don't apply, please comment below.
Testing Performed
CI should be enough to ensure no behavioral changes have been introduced.