Skip to content

Commit

Permalink
Merge pull request #383 from YangSen-qn/V8.1.1
Browse files Browse the repository at this point in the history
优化日志统计
  • Loading branch information
Mei-Zhao authored Jan 6, 2021
2 parents 8c893b6 + 69bba5d commit f8d1a29
Show file tree
Hide file tree
Showing 27 changed files with 290 additions and 23 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
on: [push]
on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
name: Run Test Cases
jobs:
test-on-mac:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#Changelog
## 8.1.1(2021-01-06)
## 优化
- 优化日志统计

## 8.1.0(2020-12-29)
## 增加
- 支持分片V2
Expand Down
2 changes: 1 addition & 1 deletion Qiniu.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Qiniu'
s.version = '8.1.0'
s.version = '8.1.1'
s.summary = 'Qiniu Resource Storage SDK for iOS and Mac'
s.homepage = 'https://github.com/qiniu/objc-sdk'
s.social_media_url = 'http://weibo.com/qiniutek'
Expand Down
3 changes: 2 additions & 1 deletion QiniuDemo/QiniuDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import "Configure.h" // 测试参数配置,暂时只有token,可删除

#import "ViewController.h"
#import "QNTransactionManager.h"

Expand All @@ -34,6 +33,8 @@ @implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
[QNLogUtil setLogLevel:QNLogLevelInfo];

// Do any additional setup after loading the view, typically from a nib.
[self changeUploadState:UploadStatePrepare];
self.title = @"七牛云上传";
Expand Down
17 changes: 15 additions & 2 deletions QiniuSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
31C2EEEC242DEF6A00713A33 /* QNUtilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */; };
31C2EEED242DEF6A00713A33 /* QNUtilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */; };
31C6E68824ECC75700633629 /* NSData+QNGZip.m in Sources */ = {isa = PBXBuildFile; fileRef = 31259E3124E3D02C00CF7531 /* NSData+QNGZip.m */; };
31CBB0F92595F2720089C795 /* QNLogUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 31CBB0F72595F2720089C795 /* QNLogUtil.h */; settings = {ATTRIBUTES = (Public, ); }; };
31CBB0FA2595F2720089C795 /* QNLogUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 31CBB0F72595F2720089C795 /* QNLogUtil.h */; settings = {ATTRIBUTES = (Public, ); }; };
31CBB0FB2595F2720089C795 /* QNLogUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 31CBB0F82595F2720089C795 /* QNLogUtil.m */; };
31CBB0FC2595F2720089C795 /* QNLogUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 31CBB0F82595F2720089C795 /* QNLogUtil.m */; };
31D8446A254017BD005C0222 /* QNErrorCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 31D84468254017BD005C0222 /* QNErrorCode.h */; settings = {ATTRIBUTES = (Public, ); }; };
31D8446B254017BD005C0222 /* QNErrorCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 31D84469254017BD005C0222 /* QNErrorCode.m */; };
31D8446C254017BD005C0222 /* QNErrorCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 31D84469254017BD005C0222 /* QNErrorCode.m */; };
Expand Down Expand Up @@ -412,6 +416,8 @@
31C2EEE1242DE86300713A33 /* QNUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUtils.h; sourceTree = "<group>"; };
31C2EEE2242DE86300713A33 /* QNUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUtils.m; sourceTree = "<group>"; };
31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUtilTest.m; sourceTree = "<group>"; };
31CBB0F72595F2720089C795 /* QNLogUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNLogUtil.h; sourceTree = "<group>"; };
31CBB0F82595F2720089C795 /* QNLogUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNLogUtil.m; sourceTree = "<group>"; };
31D84468254017BD005C0222 /* QNErrorCode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNErrorCode.h; sourceTree = "<group>"; };
31D84469254017BD005C0222 /* QNErrorCode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNErrorCode.m; sourceTree = "<group>"; };
31DD31D524971BD7004BFDDE /* QNUploadFileNameTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUploadFileNameTest.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -617,6 +623,8 @@
4551E56624D0065100447285 /* NSData+MD5.m */,
31A070142501E27B0067D718 /* QNDefine.h */,
31A070152501E27B0067D718 /* QNDefine.m */,
31CBB0F72595F2720089C795 /* QNLogUtil.h */,
31CBB0F82595F2720089C795 /* QNLogUtil.m */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -937,6 +945,7 @@
313B380D2575E49400FBB57B /* QNPartsUploadPerformer.h in Headers */,
318E2F092552AE1C004EDE8C /* QNTransactionManager.h in Headers */,
318E2F182552AE2B004EDE8C /* QNHttpRegionRequest.h in Headers */,
31CBB0FA2595F2720089C795 /* QNLogUtil.h in Headers */,
318E2F062552AE05004EDE8C /* NSObject+QNSwizzle.h in Headers */,
318E2EF42552ADD1004EDE8C /* QNReportItem.h in Headers */,
313B37EF2574F00200FBB57B /* QNPartsUploadPerformerV1.h in Headers */,
Expand Down Expand Up @@ -1043,6 +1052,7 @@
31F553D024597182000B66AD /* QNHttpSingleRequest.h in Headers */,
CC2513C42455C141003F4C65 /* QNTempFile.h in Headers */,
3149A1D324626B3100A2A15B /* QNUploadSystemClient.h in Headers */,
31CBB0F92595F2720089C795 /* QNLogUtil.h in Headers */,
31F553C02457FFB0000B66AD /* QNPipeline.h in Headers */,
31F553E4245A6986000B66AD /* QNRequestTransaction.h in Headers */,
DFA9B64919E0018800A15FD1 /* QNUploadOption.h in Headers */,
Expand Down Expand Up @@ -1140,7 +1150,7 @@
DF2CDDF719DAC05500CE01FB /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1140;
LastUpgradeCheck = 1220;
ORGANIZATIONNAME = Qiniu;
TargetAttributes = {
31259E4624E63B9700CF7531 = {
Expand Down Expand Up @@ -1323,7 +1333,6 @@
31A1841B246A8C77001D6EEE /* QNUploadRequestMetrics.m in Sources */,
451A36B724BD893D00754A15 /* QNReportConfig.m in Sources */,
313B37F62574F00F00FBB57B /* QNPartsUploadPerformerV2.m in Sources */,
31C2EECD242CC52600713A33 /* QNDnsCacheInfo.m in Sources */,
31BAA279243DB83700B7E883 /* QNURLProtocol.m in Sources */,
313B380E2575E49400FBB57B /* QNPartsUploadPerformer.m in Sources */,
31F553A32456F2F3000B66AD /* QNFile.m in Sources */,
Expand Down Expand Up @@ -1358,6 +1367,7 @@
3149A1DD2462A57400A2A15B /* QNUploadDomainRegion.m in Sources */,
31C2EEE4242DE86300713A33 /* QNUtils.m in Sources */,
31FD0920248662F900217848 /* QNUploadServerFreezeManager.m in Sources */,
31CBB0FB2595F2720089C795 /* QNLogUtil.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1413,6 +1423,7 @@
31C6E68824ECC75700633629 /* NSData+QNGZip.m in Sources */,
31A070182501E27B0067D718 /* QNDefine.m in Sources */,
31BAA280243DBE6200B7E883 /* QNURLProtocol.m in Sources */,
31CBB0FC2595F2720089C795 /* QNLogUtil.m in Sources */,
DF293CA019DBC2AE00799011 /* QNUserAgent.m in Sources */,
314944592446FF4700386F16 /* QNCFHttpClient.m in Sources */,
31C2EED7242CC52600713A33 /* QNDnsCacheFile.m in Sources */,
Expand Down Expand Up @@ -1620,6 +1631,7 @@
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
"EXCLUDED_ARCHS[sdk=*]" = arm64;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
PRODUCT_NAME = QiniuSDK_Mac;
Expand All @@ -1633,6 +1645,7 @@
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
"EXCLUDED_ARCHS[sdk=*]" = arm64;
PRODUCT_NAME = QiniuSDK_Mac;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1220"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1220"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1220"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1220"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
23 changes: 17 additions & 6 deletions QiniuSDK/Collect/QNReportItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,19 @@ extern NSString *const QNReportRequestKeyOsVersion;
extern NSString *const QNReportRequestKeySDKName;
extern NSString *const QNReportRequestKeySDKVersion;
extern NSString *const QNReportRequestKeyClientTime;
extern NSString *const QNReportRequestKeyHttpClient;
extern NSString *const QNReportRequestKeyNetworkType;
extern NSString *const QNReportRequestKeySignalStrength;
extern NSString * const QNReportRequestKeyPrefetchedDnsSource;
extern NSString * const QNReportRequestKeyPrefetchedBefore;
extern NSString * const QNReportRequestKeyPrefetchedErrorMessage;
extern NSString *const QNReportRequestKeyPrefetchedDnsSource;
extern NSString *const QNReportRequestKeyPrefetchedBefore;
extern NSString *const QNReportRequestKeyPrefetchedErrorMessage;


//MARK:-- 分块上传统计⽇志
extern NSString *const QNReportBlockKeyLogType;
extern NSString *const QNReportBlockKeyUpTime;
extern NSString *const QNReportBlockKeyTargetBucket;
extern NSString *const QNReportBlockKeyTargetKey;
extern NSString *const QNReportBlockKeyTargetRegionId;
extern NSString *const QNReportBlockKeyCurrentRegionId;
extern NSString *const QNReportBlockKeyTotalElapsedTime;
Expand All @@ -102,7 +105,10 @@ extern NSString *const QNReportBlockKeyPid;
extern NSString *const QNReportBlockKeyTid;
extern NSString *const QNReportBlockKeyUpApiVersion;
extern NSString *const QNReportBlockKeyClientTime;

extern NSString *const QNReportBlockKeyOsName;
extern NSString *const QNReportBlockKeyOsVersion;
extern NSString *const QNReportBlockKeySDKName;
extern NSString *const QNReportBlockKeySDKVersion;

//MARK:-- 上传质量统计
extern NSString *const QNReportQualityKeyLogType;
Expand All @@ -115,7 +121,12 @@ extern NSString *const QNReportQualityKeyRequestsCount;
extern NSString *const QNReportQualityKeyRegionsCount;
extern NSString *const QNReportQualityKeyBytesSent;
extern NSString *const QNReportQualityKeyCloudType;
extern NSString * const QNReportQualityKeyErrorType;
extern NSString * const QNReportQualityKeyErrorDescription;
extern NSString *const QNReportQualityKeyErrorType;
extern NSString *const QNReportQualityKeyErrorDescription;
extern NSString *const QNReportQualityKeyOsName;
extern NSString *const QNReportQualityKeyOsVersion;
extern NSString *const QNReportQualityKeySDKName;
extern NSString *const QNReportQualityKeySDKVersion;


NS_ASSUME_NONNULL_END
15 changes: 14 additions & 1 deletion QiniuSDK/Collect/QNReportItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "QNReportItem.h"
#import "QNAsyncRun.h"
#import "QNLogUtil.h"

@interface QNReportItem()

Expand Down Expand Up @@ -72,6 +73,7 @@ @implementation QNUploadInfoReporter(ReportItem)
- (void)reportItem:(QNReportItem *)item token:(NSString *)token{
QNAsyncRun(^{
NSString *itemJsonString = [item toJson];
QNLogInfo(@"up log:%@", itemJsonString);
if (itemJsonString && ![itemJsonString isEqualToString:@"{}"]) {
[self report:itemJsonString token:token];
}
Expand Down Expand Up @@ -195,6 +197,7 @@ - (NSString *)qualityResult{
NSString * const QNReportRequestKeySDKName = @"sdk_name";
NSString * const QNReportRequestKeySDKVersion = @"sdk_version";
NSString * const QNReportRequestKeyClientTime = @"client_time";
NSString * const QNReportRequestKeyHttpClient = @"http_client";
NSString * const QNReportRequestKeyNetworkType = @"network_type";
NSString * const QNReportRequestKeySignalStrength = @"signal_strength";
NSString * const QNReportRequestKeyPrefetchedDnsSource = @"prefetched_dns_source";
Expand All @@ -203,7 +206,9 @@ - (NSString *)qualityResult{

//MARK:-- 分块上传统计⽇志
NSString * const QNReportBlockKeyLogType = @"log_type";
NSString *const QNReportBlockKeyUpTime = @"up_time";
NSString * const QNReportBlockKeyUpTime = @"up_time";
NSString * const QNReportBlockKeyTargetBucket = @"target_bucket";
NSString * const QNReportBlockKeyTargetKey = @"target_key";
NSString * const QNReportBlockKeyTargetRegionId = @"target_region_id";
NSString * const QNReportBlockKeyCurrentRegionId = @"current_region_id";
NSString * const QNReportBlockKeyTotalElapsedTime = @"total_elapsed_time";
Expand All @@ -214,6 +219,10 @@ - (NSString *)qualityResult{
NSString * const QNReportBlockKeyTid = @"tid";
NSString * const QNReportBlockKeyUpApiVersion = @"up_api_version";
NSString * const QNReportBlockKeyClientTime = @"client_time";
NSString * const QNReportBlockKeyOsName = @"os_name";
NSString * const QNReportBlockKeyOsVersion = @"os_version";
NSString * const QNReportBlockKeySDKName = @"sdk_name";
NSString * const QNReportBlockKeySDKVersion = @"sdk_version";


//MARK:-- 上传质量统计
Expand All @@ -229,3 +238,7 @@ - (NSString *)qualityResult{
NSString * const QNReportQualityKeyCloudType = @"cloud_type";
NSString * const QNReportQualityKeyErrorType = @"error_type";
NSString * const QNReportQualityKeyErrorDescription = @"error_description";
NSString * const QNReportQualityKeyOsName = @"os_name";
NSString * const QNReportQualityKeyOsVersion = @"os_version";
NSString * const QNReportQualityKeySDKName = @"sdk_name";
NSString * const QNReportQualityKeySDKVersion = @"sdk_version";
6 changes: 6 additions & 0 deletions QiniuSDK/Http/Request/QNHttpRegionRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "QNDefine.h"
#import "QNLogUtil.h"
#import "QNAsyncRun.h"
#import "QNHttpRegionRequest.h"
#import "QNConfiguration.h"
Expand All @@ -20,6 +21,7 @@ @interface QNHttpRegionRequest()

@property(nonatomic, strong)QNConfiguration *config;
@property(nonatomic, strong)QNUploadOption *uploadOption;
@property(nonatomic, strong)QNUploadRequestInfo *requestInfo;
@property(nonatomic, strong)QNUploadRequestState *requestState;

@property(nonatomic, strong)QNUploadRegionRequestMetrics *requestMetrics;
Expand All @@ -43,6 +45,7 @@ - (instancetype)initWithConfig:(QNConfiguration *)config
_config = config;
_uploadOption = uploadOption;
_region = region;
_requestInfo = requestInfo;
_requestState = requestState;
_singleRequest = [[QNHttpSingleRequest alloc] initWithConfig:config
uploadOption:uploadOption
Expand Down Expand Up @@ -153,6 +156,9 @@ - (void)performRequest:(id <QNUploadServer>)server
[request setTimeoutInterval:self.config.timeoutInterval];
request.HTTPBody = body;

QNLogInfo(@"key:%@ url:%@", self.requestInfo.key, request.URL);
QNLogInfo(@"key:%@ headers:%@", self.requestInfo.key, headers);

kQNWeakSelf;
[self.singleRequest request:request
server:server
Expand Down
4 changes: 4 additions & 0 deletions QiniuSDK/Http/Request/QNHttpSingleRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "QNAsyncRun.h"
#import "QNVersion.h"
#import "QNUtils.h"
#import "QNLogUtil.h"
#import "QNHttpSingleRequest.h"
#import "QNConfiguration.h"
#import "QNUploadOption.h"
Expand Down Expand Up @@ -107,6 +108,8 @@ - (void)retryRequest:(NSURLRequest *)request
return isCancelled;
};

QNLogInfo(@"key:%@ retry:%d url:%@", self.requestInfo.key, self.currentRetryTime, request.URL);

[self.client request:request connectionProxy:self.config.proxy progress:^(long long totalBytesWritten, long long totalBytesExpectedToWrite) {
kQNStrongSelf;

Expand Down Expand Up @@ -142,6 +145,7 @@ - (void)retryRequest:(NSURLRequest *)request
response:(NSHTTPURLResponse *)response
body:responseData
error:error];
QNLogInfo(@"key:%@ response:%@", self.requestInfo.key, responseInfo);
if (shouldRetry(responseInfo, responseDic)
&& self.currentRetryTime < self.config.retryMax
&& responseInfo.couldHostRetry) {
Expand Down
8 changes: 8 additions & 0 deletions QiniuSDK/Http/ServerRegion/QNUploadDomainRegion.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "QNZoneInfo.h"
#import "QNUploadServerFreezeManager.h"
#import "QNDnsPrefetch.h"
#import "QNLogUtil.h"
#import "QNUtils.h"

@interface QNUploadIpGroup : NSObject
Expand Down Expand Up @@ -208,6 +209,9 @@ - (void)setupRegionData:(QNZoneInfo *)zoneInfo{
}
self.oldDomainHostList = oldDomainHostList;
self.oldDomainDictionary = [self createDomainDictionary:serverGroups];

QNLogInfo(@"region :%@",domainHostList);
QNLogInfo(@"region old:%@",oldDomainHostList);
}
- (NSDictionary *)createDomainDictionary:(NSArray <NSString *> *)hosts{
NSMutableDictionary *domainDictionary = [NSMutableDictionary dictionary];
Expand Down Expand Up @@ -247,13 +251,16 @@ - (NSDictionary *)createDomainDictionary:(NSArray <NSString *> *)hosts{
if (server == nil) {
self.isAllFrozen = YES;
}

QNLogInfo(@"get server host:%@ ip:%@", server.host, server.ip);
return server;
}

- (void)freezeServerIfNeed:(QNResponseInfo *)responseInfo freezeServer:(QNUploadServer *)freezeServer {
if (freezeServer.serverId) {
// 无法连接到Host || Host不可用, 局部冻结
if (!responseInfo.canConnectToHost || responseInfo.isHostUnavailable) {
QNLogInfo(@"partial freeze server host:%@ ip:%@", freezeServer.host, freezeServer.ip);
[_domainDictionary[freezeServer.serverId] freeze:freezeServer.ip
freezeManager:self.partialFreezeManager
frozenTime:kQNGlobalConfiguration.partialHostFrozenTime];
Expand All @@ -264,6 +271,7 @@ - (void)freezeServerIfNeed:(QNResponseInfo *)responseInfo freezeServer:(QNUpload

// Host不可用,全局冻结
if (responseInfo.isHostUnavailable) {
QNLogInfo(@"global freeze server host:%@ ip:%@", freezeServer.host, freezeServer.ip);
[_domainDictionary[freezeServer.serverId] freeze:freezeServer.ip
freezeManager:kQNUploadServerFreezeManager
frozenTime:kQNGlobalConfiguration.globalHostFrozenTime];
Expand Down
1 change: 1 addition & 0 deletions QiniuSDK/QiniuSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "QNZone.h"
#import "QNFixedZone.h"
#import "QNAutoZone.h"
#import "QNLogUtil.h"
#import "QNConfiguration.h"
#import "QNRecorderDelegate.h"
#import "QNFileRecorder.h"
Expand Down
Loading

0 comments on commit f8d1a29

Please sign in to comment.