Skip to content
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

logging: add configurable log-level to startup params #173

Merged
merged 4 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ IndentWidth: 2
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Left
PointerAlignment: Right
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just gonna sneak this in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It's Apple's convention and Left wasn't getting applied consistently by clang-format anyways.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No opinion here, but for context it was Left because that's what upstream Envoy uses for C++

SortIncludes: false
...

Expand Down
2 changes: 1 addition & 1 deletion examples/objective-c/hello_world/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow* window;
@property (strong, nonatomic) UIWindow *window;

@end
5 changes: 3 additions & 2 deletions library/common/jni_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
extern "C" JNIEXPORT jint JNICALL
Java_io_envoyproxy_envoymobile_engine_EnvoyEngine_run(JNIEnv* env,
jobject, // this
jstring config) {
return run_envoy(env->GetStringUTFChars(config, nullptr));
jstring config, jstring log_level) {
return run_envoy(env->GetStringUTFChars(config, nullptr),
env->GetStringUTFChars(log_level, nullptr));
}

extern "C" JNIEXPORT jint JNICALL
Expand Down
7 changes: 4 additions & 3 deletions library/common/main_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
/**
* External entrypoint for library.
*/
extern "C" int run_envoy(const char* config) {
extern "C" int run_envoy(const char* config, const char* log_level) {
std::unique_ptr<Envoy::MainCommon> main_common;

char* envoy_argv[] = {strdup("envoy"), strdup("--config-yaml"), strdup(config), nullptr};
char* envoy_argv[] = {strdup("envoy"), strdup("--config-yaml"), strdup(config),
strdup("-l"), strdup(log_level), nullptr};

// Ensure static factory registration occurs on time.
// Envoy's static factory registration happens when main is run.
Expand All @@ -41,7 +42,7 @@ extern "C" int run_envoy(const char* config) {
// This is a known problem, and will be addressed by:
// https://github.com/lyft/envoy-mobile/issues/34
try {
main_common = std::make_unique<Envoy::MainCommon>(3, envoy_argv);
main_common = std::make_unique<Envoy::MainCommon>(5, envoy_argv);
} catch (const Envoy::NoServingException& e) {
return EXIT_SUCCESS;
} catch (const Envoy::MalformedArgvException& e) {
Expand Down
4 changes: 2 additions & 2 deletions library/common/main_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* External entrypoint for library.
*/
#ifdef __cplusplus
extern "C" int run_envoy(const char* config);
extern "C" int run_envoy(const char* config, const char* log_level);
#else
int run_envoy(const char* config);
int run_envoy(const char* config, const char* log_level);
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public static void load(Context context) {

private static native boolean isAresInitialized();

public static native int run(String config);
public static native int run(String config, String logLevel);
}
7 changes: 4 additions & 3 deletions library/kotlin/io/envoyproxy/envoymobile/Envoy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import android.content.Context
import io.envoyproxy.envoymobile.engine.EnvoyEngine

// Wrapper class that allows for easy calling of Envoy's JNI interface in native Java.
class Envoy(
class Envoy @JvmOverloads constructor(
context: Context,
config: String
config: String,
logLevel: String = "info"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about introducing an enum for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did think about it, and Envoy uses one internally.

However, currently we have to pass this as a string, and there's no portable enum type we could expose for this (so we'd have to define the enum on both platforms and still pass a string ultimately).

This seemed good enough for now to me. ¯\_(ツ)_/¯

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we'll have to create one eventually. Let's keep that in mind on the next iteration for configurations/logs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely agree that this should be an enum at some point. What about making constants to use instead for now? Feels a little too much like a magic string

) {

// Dedicated thread for running this instance of Envoy.
Expand All @@ -21,7 +22,7 @@ class Envoy(
load(context)

runner = Thread(Runnable {
EnvoyEngine.run(config.trim())
EnvoyEngine.run(config.trim(), logLevel)
})

runner.start()
Expand Down
7 changes: 6 additions & 1 deletion library/objective-c/Envoy.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@

/// Create a new Envoy instance. The Envoy runner NSThread is started as part of instance
/// initialization with the configuration provided.
- (instancetype)initWithConfig:(NSString*)config;
- (instancetype)initWithConfig:(NSString *)config;

/// Create a new Envoy instance. The Envoy runner NSThread is started as part of instance
/// initialization with the configuration provided.
- (instancetype)initWithConfig:(NSString *)config logLevel:(NSString *)logLevel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also be nice to document what valid log levels are available here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree enums would be better. Tell you all what I'll open another PR with enums after I merge and re-test iOS. :)


@end
17 changes: 14 additions & 3 deletions library/objective-c/Envoy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#import "library/common/main_interface.h"

static NSString *const kConfig = @"config";
static NSString *const kLogLevel = @"logLevel";

@interface Envoy ()
@property (nonatomic, strong) NSThread *runner;
Expand All @@ -12,9 +14,18 @@ @implementation Envoy
@synthesize runner;

- (instancetype)initWithConfig:(NSString *)config {
self = [self initWithConfig:config logLevel:@"info"];
return self;
}

- (instancetype)initWithConfig:(NSString *)config logLevel:(NSString *) logLevel {
self = [super init];
if (self) {
self.runner = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:config];
NSDictionary *args = @{
kConfig: config,
kLogLevel: logLevel,
};
self.runner = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:args];
[self.runner start];
}
return self;
Expand All @@ -30,9 +41,9 @@ - (BOOL)isTerminated {

#pragma mark private

- (void)run:(NSString *)config {
- (void)run:(NSDictionary *)args {
try {
run_envoy(config.UTF8String);
run_envoy([args[kConfig] UTF8String], [args[kLogLevel] UTF8String]);
} catch (NSException *e) {
NSLog(@"Envoy exception: %@", e);
NSDictionary *userInfo = @{ @"exception": e};
Expand Down