Skip to content

Commit e90eb78

Browse files
authored
Create some core infrastructure for backends (#2198)
* s/GDLLogClock/GDLClock/ This isn't a class of log clocks, it's a class of clocks. * Create some core infrastructure to support backends and prioritization of logs. * Docs and slight changes to the scorer API. * Missing return statement * Change 'score' terminology to 'prioritize'. Also style issues. * Change the protocol being used for a prioritizer.
1 parent ea80142 commit e90eb78

File tree

9 files changed

+237
-4
lines changed

9 files changed

+237
-4
lines changed

GoogleDataLogger/GoogleDataLogger/Classes/GDLLogClock.h renamed to GoogleDataLogger/GoogleDataLogger/Classes/GDLClock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef struct {
3131
} GDLLogClockSnapshot;
3232

3333
/** This class manages the device clock and produces snapshots of the current time. */
34-
@interface GDLLogClock : NSObject
34+
@interface GDLClock : NSObject
3535

3636
// TODO(mikehaney24): - (GDLLogClockSnapshot)snapshot;
3737

GoogleDataLogger/GoogleDataLogger/Classes/GDLLogClock.m renamed to GoogleDataLogger/GoogleDataLogger/Classes/GDLClock.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
#import "GDLLogClock.h"
17+
#import "GDLClock.h"
1818

19-
@implementation GDLLogClock
19+
@implementation GDLClock
2020

2121
@end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "GDLRegistrar.h"
18+
19+
@implementation GDLRegistrar
20+
21+
+ (instancetype)sharedInstance {
22+
static GDLRegistrar *sharedInstance;
23+
static dispatch_once_t onceToken;
24+
dispatch_once(&onceToken, ^{
25+
sharedInstance = [[GDLRegistrar alloc] init];
26+
});
27+
return sharedInstance;
28+
}
29+
30+
- (void)registerBackend:(id<GDLLogBackend>)backend forLogTarget:(NSInteger)logTarget {
31+
// TODO
32+
}
33+
34+
- (void)registerLogPrioritizer:(id<GDLLogPrioritizer>)prioritizer
35+
forLogTarget:(NSInteger)logTarget {
36+
// TODO
37+
}
38+
39+
@end

GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLLogEvent_Private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import "GDLLogEvent.h"
1818

19-
#import "GDLLogClock.h"
19+
#import "GDLClock.h"
2020

2121
NS_ASSUME_NONNULL_BEGIN
2222

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <GoogleDataLogger/GDLRegistrar.h>
18+
19+
@interface GDLRegistrar ()
20+
21+
/** A map of logTargets to backend implementations. */
22+
@property(nonatomic) NSDictionary<NSNumber *, id<GDLLogBackend>> *logTargetToBackend;
23+
24+
/** A map of logTargets to prioritizer implementations. */
25+
@property(nonatomic) NSDictionary<NSNumber *, id<GDLLogPrioritizer>> *logTargetToPrioritizer;
26+
27+
@end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
/** A convenient typedef to define the block to be called upon completion of an upload to the
20+
* backend.
21+
*/
22+
typedef void (^GDLBackendCompletionBlock)(NSSet<NSURL *> *successfulUploads,
23+
NSSet<NSURL *> *unsuccessfulUploads);
24+
25+
/** This protocol defines the common interface for logging backend implementations. */
26+
@protocol GDLLogBackend <NSObject>
27+
28+
@required
29+
30+
/** Uploads logs to the backend using this specific backend's chosen format.
31+
*
32+
* @param logFiles The set of log files to upload.
33+
* @param onComplete A block to invoke upon completing the upload. Has two arguments:
34+
* - successfulUploads: The set of filenames uploaded successfully.
35+
* - unsuccessfulUploads: The set of filenames not uploaded successfully.
36+
*/
37+
- (void)uploadLogs:(NSSet<NSURL *> *)logFiles onComplete:(GDLBackendCompletionBlock)onComplete;
38+
39+
@end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
@class GDLLogEvent;
20+
21+
/** This protocol defines the common interface of a log prioritization. Log prioritizers are
22+
* stateful objects that prioritize logs upon insertion into storage and remain prepared to return a
23+
* set of log filenames to the storage system.
24+
*/
25+
@protocol GDLLogPrioritizer <NSObject>
26+
27+
@required
28+
29+
/** Accepts a logEvent and uses the log metadata to make choices on how to prioritize the log. This
30+
* method exists as a way to help prioritize which logs should be sent, which is dependent on the
31+
* request proto structure of your backend.
32+
*
33+
* @note Three things: 1. the logEvent cannot be retained for longer than the execution time of
34+
* this method. 2. The extension should be nil by this point and should not be used to prioritize
35+
* logs. 3. You should retain the logEvent hashes, because those are returned in logsForNextUpload.
36+
*
37+
* @param logEvent The log event to prioritize.
38+
*/
39+
- (void)prioritizeLog:(GDLLogEvent *)logEvent;
40+
41+
/** Returns a set of logs based on the logic of the prioritizer.
42+
*
43+
* @return A set of log hashes to upload, presumably based on the logs' priority.
44+
*/
45+
- (NSSet<NSNumber *> *)logsForNextUpload;
46+
47+
@end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
#import <GoogleDataLogger/GDLLogBackend.h>
20+
#import <GoogleDataLogger/GDLLogPrioritizer.h>
21+
22+
NS_ASSUME_NONNULL_BEGIN
23+
24+
/** Manages the registration of log targets with the logging SDK. */
25+
@interface GDLRegistrar : NSObject
26+
27+
/** Creates and/or returns the singleton instance.
28+
*
29+
* @return The singleton instance of this class.
30+
*/
31+
+ (instancetype)sharedInstance;
32+
33+
/** Registers a backend implementation with the GoogleDataLogger infrastructure.
34+
*
35+
* @param backend The backend object to register.
36+
* @param logTarget The logTarget this backend object will be responsible for.
37+
*/
38+
- (void)registerBackend:(id<GDLLogBackend>)backend forLogTarget:(NSInteger)logTarget;
39+
40+
/** Registers a log prioritizer implementation with the GoogleDataLogger infrastructure.
41+
*
42+
* @param prioritizer The prioritizer object to register.
43+
* @param logTarget The logTarget this prioritizer object will be responsible for.
44+
*/
45+
- (void)registerLogPrioritizer:(id<GDLLogPrioritizer>)prioritizer forLogTarget:(NSInteger)logTarget;
46+
47+
@end
48+
49+
NS_ASSUME_NONNULL_END
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import <GoogleDataLogger/GDLRegistrar.h>
20+
21+
@interface GDLRegistrarTest : XCTestCase
22+
23+
@end
24+
25+
@implementation GDLRegistrarTest
26+
27+
/** Tests the default initializer. */
28+
- (void)testInit {
29+
XCTAssertNotNil([[GDLRegistrarTest alloc] init]);
30+
}
31+
32+
@end

0 commit comments

Comments
 (0)