-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Create some core infrastructure for backends #2198
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd51a6b
s/GDLLogClock/GDLClock/
mikehaney24 82eed49
Create some core infrastructure to support backends and prioritizatio…
mikehaney24 be627ac
Docs and slight changes to the scorer API.
mikehaney24 4a6697a
Missing return statement
mikehaney24 e07ff5a
Change 'score' terminology to 'prioritize'. Also style issues.
mikehaney24 2a72159
Change the protocol being used for a prioritizer.
mikehaney24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import "GDLRegistrar.h" | ||
|
||
@implementation GDLRegistrar | ||
|
||
+ (instancetype)sharedInstance { | ||
static GDLRegistrar *sharedInstance; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
sharedInstance = [[GDLRegistrar alloc] init]; | ||
}); | ||
return sharedInstance; | ||
} | ||
|
||
- (void)registerBackend:(id<GDLLogBackend>)backend forLogTarget:(NSInteger)logTarget { | ||
// TODO | ||
} | ||
|
||
- (void)registerLogPrioritizer:(id<GDLLogPrioritizer>)prioritizer | ||
forLogTarget:(NSInteger)logTarget { | ||
// TODO | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
#import "GDLLogEvent.h" | ||
|
||
#import "GDLLogClock.h" | ||
#import "GDLClock.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
|
27 changes: 27 additions & 0 deletions
27
GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLRegistrar_Private.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <GoogleDataLogger/GDLRegistrar.h> | ||
|
||
@interface GDLRegistrar () | ||
|
||
/** A map of logTargets to backend implementations. */ | ||
@property(nonatomic) NSDictionary<NSNumber *, id<GDLLogBackend>> *logTargetToBackend; | ||
|
||
/** A map of logTargets to prioritizer implementations. */ | ||
@property(nonatomic) NSDictionary<NSNumber *, id<GDLLogPrioritizer>> *logTargetToPrioritizer; | ||
|
||
@end |
39 changes: 39 additions & 0 deletions
39
GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogBackend.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** A convenient typedef to define the block to be called upon completion of an upload to the | ||
* backend. | ||
*/ | ||
typedef void (^GDLBackendCompletionBlock)(NSSet<NSURL *> *successfulUploads, | ||
NSSet<NSURL *> *unsuccessfulUploads); | ||
|
||
/** This protocol defines the common interface for logging backend implementations. */ | ||
@protocol GDLLogBackend <NSObject> | ||
|
||
@required | ||
|
||
/** Uploads logs to the backend using this specific backend's chosen format. | ||
* | ||
* @param logFiles The set of log files to upload. | ||
* @param onComplete A block to invoke upon completing the upload. Has two arguments: | ||
* - successfulUploads: The set of filenames uploaded successfully. | ||
* - unsuccessfulUploads: The set of filenames not uploaded successfully. | ||
*/ | ||
- (void)uploadLogs:(NSSet<NSURL *> *)logFiles onComplete:(GDLBackendCompletionBlock)onComplete; | ||
|
||
@end |
47 changes: 47 additions & 0 deletions
47
GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogPrioritizer.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class GDLLogEvent; | ||
|
||
/** This protocol defines the common interface of a log prioritization. Log prioritizers are | ||
* stateful objects that prioritize logs upon insertion into storage and remain prepared to return a | ||
* set of log filenames to the storage system. | ||
*/ | ||
@protocol GDLLogPrioritizer <NSObject> | ||
|
||
@required | ||
|
||
/** Accepts a logEvent and uses the log metadata to make choices on how to prioritize the log. This | ||
* method exists as a way to help prioritize which logs should be sent, which is dependent on the | ||
* request proto structure of your backend. | ||
* | ||
* @note Three things: 1. the logEvent cannot be retained for longer than the execution time of | ||
* this method. 2. The extension should be nil by this point and should not be used to prioritize | ||
* logs. 3. You should retain the logEvent hashes, because those are returned in logsForNextUpload. | ||
* | ||
* @param logEvent The log event to prioritize. | ||
*/ | ||
- (void)prioritizeLog:(GDLLogEvent *)logEvent; | ||
|
||
/** Returns a set of logs based on the logic of the prioritizer. | ||
* | ||
* @return A set of log hashes to upload, presumably based on the logs' priority. | ||
*/ | ||
- (NSSet<NSNumber *> *)logsForNextUpload; | ||
|
||
@end |
49 changes: 49 additions & 0 deletions
49
GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLRegistrar.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <GoogleDataLogger/GDLLogBackend.h> | ||
#import <GoogleDataLogger/GDLLogPrioritizer.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** Manages the registration of log targets with the logging SDK. */ | ||
@interface GDLRegistrar : NSObject | ||
|
||
/** Creates and/or returns the singleton instance. | ||
* | ||
* @return The singleton instance of this class. | ||
*/ | ||
+ (instancetype)sharedInstance; | ||
|
||
/** Registers a backend implementation with the GoogleDataLogger infrastructure. | ||
* | ||
* @param backend The backend object to register. | ||
* @param logTarget The logTarget this backend object will be responsible for. | ||
*/ | ||
- (void)registerBackend:(id<GDLLogBackend>)backend forLogTarget:(NSInteger)logTarget; | ||
|
||
/** Registers a log prioritizer implementation with the GoogleDataLogger infrastructure. | ||
* | ||
* @param prioritizer The prioritizer object to register. | ||
* @param logTarget The logTarget this prioritizer object will be responsible for. | ||
*/ | ||
- (void)registerLogPrioritizer:(id<GDLLogPrioritizer>)prioritizer forLogTarget:(NSInteger)logTarget; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import <GoogleDataLogger/GDLRegistrar.h> | ||
|
||
@interface GDLRegistrarTest : XCTestCase | ||
|
||
@end | ||
|
||
@implementation GDLRegistrarTest | ||
|
||
/** Tests the default initializer. */ | ||
- (void)testInit { | ||
XCTAssertNotNil([[GDLRegistrarTest alloc] init]); | ||
} | ||
|
||
@end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.