Skip to content

Commit c2e4f1e

Browse files
Hongyan JiangGitHub Enterprise
authored andcommitted
remove slowSendInterval implementation (#106)
* remove slowSendInterval implementation * scheduleFlush only once with no delay when app goes background * scheduleFlush when app goes to foreground * remove AFNetworking from InstanaAgentExample on behalf of XCode 26.4
1 parent b2317a8 commit c2e4f1e

21 files changed

Lines changed: 166 additions & 282 deletions

Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Changelog
22

3-
## 1.9.8
3+
## 1.10.0
44
- add in-flight flag to corebeacon to prevent duplicated beacons
5+
- remove slowSendInterval implementation
6+
- remove AFNetworking from InstanaAgentExample on behalf of XCode 26.4
57

68
## 1.9.7
79
- workaround XCode 26.4 RC issue

Dev/InstanaAgentExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
727AF73F263AA0FA00B9C59B /* EventListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 727AF73A263AA0FA00B9C59B /* EventListViewController.swift */; };
2828
727AF748263AA16A00B9C59B /* InstanaAgent in Frameworks */ = {isa = PBXBuildFile; productRef = 727AF747263AA16A00B9C59B /* InstanaAgent */; };
2929
72976A9A2681C45800A284F6 /* Webserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72976A992681C45800A284F6 /* Webserver.swift */; };
30-
729C88B5270DE98200492486 /* AFNetworking in Frameworks */ = {isa = PBXBuildFile; productRef = 729C88B4270DE98200492486 /* AFNetworking */; };
3130
729C88B8270DF13700492486 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 729C88B7270DF13700492486 /* Alamofire */; };
3231
A4059B1F2BD067A400C471B6 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = A4059B1E2BD067A400C471B6 /* PrivacyInfo.xcprivacy */; };
3332
A412ECE52BCF3F6C007212F9 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = A412ECE42BCF3F6C007212F9 /* PrivacyInfo.xcprivacy */; };
@@ -114,7 +113,6 @@
114113
A4EFD6A12A9983FB00B9A9A3 /* WebKit.framework in Frameworks */,
115114
729C88B8270DF13700492486 /* Alamofire in Frameworks */,
116115
727AF748263AA16A00B9C59B /* InstanaAgent in Frameworks */,
117-
729C88B5270DE98200492486 /* AFNetworking in Frameworks */,
118116
);
119117
runOnlyForDeploymentPostprocessing = 0;
120118
};
@@ -275,7 +273,6 @@
275273
name = InstanaAgentExample;
276274
packageProductDependencies = (
277275
727AF747263AA16A00B9C59B /* InstanaAgent */,
278-
729C88B4270DE98200492486 /* AFNetworking */,
279276
729C88B7270DF13700492486 /* Alamofire */,
280277
);
281278
productName = InstanaAgentExample;
@@ -354,7 +351,6 @@
354351
);
355352
mainGroup = 727AF67C263A9EBD00B9C59B;
356353
packageReferences = (
357-
729C88B3270DE98200492486 /* XCRemoteSwiftPackageReference "AFNetworking" */,
358354
729C88B6270DF13700492486 /* XCRemoteSwiftPackageReference "Alamofire" */,
359355
);
360356
productRefGroup = 727AF686263A9EBD00B9C59B /* Products */;
@@ -774,7 +770,7 @@
774770
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
775771
CODE_SIGN_ENTITLEMENTS = InstanaAgentExample/InstanaAgentExample.entitlements;
776772
CODE_SIGN_STYLE = Automatic;
777-
DEVELOPMENT_TEAM = 232T4HF9PL;
773+
DEVELOPMENT_TEAM = "";
778774
INFOPLIST_FILE = InstanaAgentExample/Info.plist;
779775
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
780776
LD_RUNPATH_SEARCH_PATHS = (
@@ -796,7 +792,7 @@
796792
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
797793
CODE_SIGN_ENTITLEMENTS = InstanaAgentExample/InstanaAgentExample.entitlements;
798794
CODE_SIGN_STYLE = Automatic;
799-
DEVELOPMENT_TEAM = 232T4HF9PL;
795+
DEVELOPMENT_TEAM = "";
800796
INFOPLIST_FILE = InstanaAgentExample/Info.plist;
801797
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
802798
LD_RUNPATH_SEARCH_PATHS = (
@@ -968,14 +964,6 @@
968964
/* End XCConfigurationList section */
969965

970966
/* Begin XCRemoteSwiftPackageReference section */
971-
729C88B3270DE98200492486 /* XCRemoteSwiftPackageReference "AFNetworking" */ = {
972-
isa = XCRemoteSwiftPackageReference;
973-
repositoryURL = "https://github.com/AFNetworking/AFNetworking.git";
974-
requirement = {
975-
kind = upToNextMajorVersion;
976-
minimumVersion = 4.0.0;
977-
};
978-
};
979967
729C88B6270DF13700492486 /* XCRemoteSwiftPackageReference "Alamofire" */ = {
980968
isa = XCRemoteSwiftPackageReference;
981969
repositoryURL = "https://github.com/Alamofire/Alamofire.git";
@@ -995,11 +983,6 @@
995983
isa = XCSwiftPackageProductDependency;
996984
productName = InstanaAgent;
997985
};
998-
729C88B4270DE98200492486 /* AFNetworking */ = {
999-
isa = XCSwiftPackageProductDependency;
1000-
package = 729C88B3270DE98200492486 /* XCRemoteSwiftPackageReference "AFNetworking" */;
1001-
productName = AFNetworking;
1002-
};
1003986
729C88B7270DF13700492486 /* Alamofire */ = {
1004987
isa = XCSwiftPackageProductDependency;
1005988
package = 729C88B6270DF13700492486 /* XCRemoteSwiftPackageReference "Alamofire" */;

Dev/InstanaAgentExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dev/InstanaAgentExample/ImageViewController.swift

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import UIKit
88
import Combine
99
import InstanaAgent
10-
import AFNetworking
1110
import Alamofire
1211

1312
@available(iOS 13.0, *)
@@ -52,7 +51,7 @@ class ImageViewViewController: UIViewController {
5251

5352
@objc func downloadImage() {
5453
let url = URL(string: "https://picsum.photos/900")!
55-
let function = [downloadWViaAFN, downloadViaCombine, downloadViaAlamofire].randomElement()!
54+
let function = [downloadViaCombine, downloadViaAlamofire].randomElement()!
5655
function(url)
5756
DispatchQueue.global().async {
5857
function(url)
@@ -81,18 +80,6 @@ class ImageViewViewController: UIViewController {
8180
}
8281
}
8382

84-
func downloadWViaAFN(_ url: URL) {
85-
let manager = AFURLSessionManager(sessionConfiguration: .default)
86-
manager.responseSerializer = AFHTTPResponseSerializer()
87-
let request = URLRequest(url: url)
88-
manager.dataTask(with: request, uploadProgress: nil, downloadProgress: nil) { response, data, error in
89-
DispatchQueue.main.async {
90-
guard let data = data as? Data else { return }
91-
self.imageView.image = UIImage(data: data)
92-
}
93-
}.resume()
94-
}
95-
9683
func downloadViaAlamofire(_ url: URL) {
9784
let request = AF.request(url)
9885
request.response { result in

InstanaAgent.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "InstanaAgent"
19-
s.version = "1.9.8"
19+
s.version = "1.10.0"
2020
s.summary = "Instana iOS agent."
2121

2222
# This description is used to generate tags and improve search results.

Sources/InstanaAgent/Beacons/BeaconFlusher.swift

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ class BeaconFlusher {
8787

8888
func schedule() {
8989
let flushItem = DispatchWorkItem { [weak self] in
90-
guard let self = self else { return }
91-
self.flush()
90+
self?.flush()
9291
}
9392
queue.asyncAfter(deadline: .now() + debounce, execute: flushItem)
9493
self.flushItem = flushItem
@@ -125,9 +124,8 @@ class BeaconFlusher {
125124
}
126125
}
127126
disapatchGroup.notify(queue: queue) { [weak self] in
128-
guard let self = self else { return }
129-
self.urlTasks.removeAll()
130-
self.complete()
127+
self?.urlTasks.removeAll()
128+
self?.complete()
131129
// if self.shouldPerformRetry() {
132130
// self.retry()
133131
// } else {
@@ -139,18 +137,7 @@ class BeaconFlusher {
139137

140138
// When error occurred, either goes into slow send mode, or retry sending.
141139
internal func shouldPerformRetry() -> Bool {
142-
let canDoSlowSend = config.slowSendInterval > 0
143-
144140
guard !errors.isEmpty else {
145-
if canDoSlowSend {
146-
// No error, reset the flag
147-
reporter?.setSlowSendStartTime(nil)
148-
}
149-
return false
150-
}
151-
152-
if canDoSlowSend {
153-
reporter?.setSlowSendStartTime(Date())
154141
return false
155142
}
156143
return retryStep < config.maxRetries

Sources/InstanaAgent/Beacons/Reporter.swift

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Reporter {
1313
private let dispatchQueue = DispatchQueue(label: "com.instana.ios.agent.reporter", qos: .utility)
1414
internal var sendFirstBeacon = true // first beacon is sent all by itself, not in a batch
1515
private var slowSendStartTime: Date?
16-
private var inSlowModeBeforeFlush = false
16+
private var allowOneBackgroundFlush = false
1717
internal var lastFlushStartTime: Double?
1818
internal var flusher: BeaconFlusher?
1919
internal var send: BeaconFlusher.Sender?
@@ -53,9 +53,11 @@ public class Reporter {
5353
self.updateNetworkConnection(connectionType)
5454
}
5555
InstanaApplicationStateHandler.shared.listen { [weak self] state, _ in
56-
guard let self = self else { return }
5756
if state == .background, !ProcessInfo.isRunningTests {
58-
// self.runBackgroundFlush()
57+
self?.runBackgroundFlush()
58+
} else if state == .active {
59+
self?.allowOneBackgroundFlush = false
60+
self?.runActiveFlush()
5961
}
6062
}
6163
dispatchQueue.asyncAfter(deadline: .now() + session.configuration.preQueueUsageTime, execute: emptyPreQueueIfNeeded)
@@ -141,23 +143,6 @@ public class Reporter {
141143
scheduleFlush()
142144
}
143145

144-
internal var isInSlowSendMode: Bool {
145-
session.configuration.slowSendInterval > 0 && (sendFirstBeacon || slowSendStartTime != nil)
146-
}
147-
148-
internal func setSlowSendStartTime(_ time: Date?) {
149-
if time == nil {
150-
if slowSendStartTime != nil {
151-
session.logger.add("Slow send ended at \(String(describing: Date()))")
152-
slowSendStartTime = nil
153-
}
154-
} else if slowSendStartTime == nil {
155-
// if slow send started, do not update so as to keep the earliest time
156-
slowSendStartTime = time
157-
session.logger.add("Slow send started at \(String(describing: time!))")
158-
}
159-
}
160-
161146
func checkDeviceCondition() -> InstanaError? {
162147
// Check network and battery condition
163148
var error: InstanaError?
@@ -202,29 +187,27 @@ public class Reporter {
202187
}
203188

204189
func scheduleFlush() {
205-
guard !queue.items.isEmpty else { return }
190+
let flushableItemsAvailable = queue.flushableItemsAvailable()
191+
192+
let isBackground = InstanaApplicationStateHandler.shared.state == .background
193+
if isBackground, !allowOneBackgroundFlush {
194+
session.logger.add("Skip flush - app has been in background", level: .debug)
195+
return
196+
}
197+
if isBackground {
198+
session.logger.add("App entered background, allowOneBackgroundFlush", level: .debug)
199+
allowOneBackgroundFlush = false
200+
}
201+
202+
guard flushableItemsAvailable else { return }
206203

207204
if !canScheduleFlush() { return }
208205

209206
let start = Date()
210-
var debounce: TimeInterval
207+
let debounce: TimeInterval = isBackground ? 0.0 : calcDebounceTime()
211208
var beaconsToSend: Set<CoreBeacon> = Set([])
212-
inSlowModeBeforeFlush = isInSlowSendMode
213-
if inSlowModeBeforeFlush {
214-
if sendFirstBeacon {
215-
debounce = flushDebounce
216-
sendFirstBeacon = false
217-
} else {
218-
debounce = session.configuration.slowSendInterval
219-
}
220-
var beacon = queue.items.first!
221-
beacon.updateMetaDataWithSlowSendStartTime(slowSendStartTime)
222-
beaconsToSend.insert(beacon)
223-
} else {
224-
debounce = calcDebounceTime()
225-
// Filter out beacons already in-flight to prevent duplicate sends
226-
beaconsToSend = queue.items.filter { $0.ifl != true }
227-
}
209+
// Filter out beacons already in-flight to prevent duplicate sends
210+
beaconsToSend = queue.items.filter { $0.ifl != true }
228211

229212
guard !beaconsToSend.isEmpty else {
230213
session.logger.add("All beacons are in-flight, skipping flush")
@@ -271,15 +254,17 @@ public class Reporter {
271254
}
272255

273256
func runBackgroundFlush() {
274-
#if os(tvOS) || os(watchOS) || os(iOS)
275-
ProcessInfo.processInfo.performExpiringActivity(withReason: "BackgroundFlush") { expired in
276-
guard !expired else { return }
277-
self.dispatchQueue.async { [weak self] in
278-
guard let self = self else { return }
279-
self.scheduleFlush()
280-
}
281-
}
282-
#endif
257+
dispatchQueue.async { [weak self] in
258+
self?.allowOneBackgroundFlush = true
259+
self?.scheduleFlush()
260+
}
261+
}
262+
263+
func runActiveFlush() {
264+
dispatchQueue.async { [weak self] in
265+
self?.session.logger.add("App entered foreground, resume regular flush", level: .debug)
266+
self?.scheduleFlush()
267+
}
283268
}
284269

285270
private func handle(flushResult: BeaconFlusher.Result,
@@ -346,17 +331,6 @@ public class Reporter {
346331

347332
flusher = nil // mark this round flush done
348333
lastFlushStartTime = nil
349-
if inSlowModeBeforeFlush {
350-
// Another flush either resend 1 beacon (still in slow mode currently)
351-
// or flush remaining beacons (got out of slow send mode already)
352-
var msg: String
353-
if isInSlowSendMode {
354-
msg = "schedule flush to send 1 beacon in slow send mode"
355-
} else {
356-
msg = "flush all beacons after out of slow send mode"
357-
}
358-
session.logger.add(msg)
359-
}
360334
// schedule next round flush
361335
scheduleFlush()
362336
}

Sources/InstanaAgent/Configuration/Defines.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ let usi_startTimeKey = "Instana_usiStartTimeKey"
2222

2323
let ignoreZipReportingKey = "IgnoreZIPReporting"
2424

25-
let maxSlowSendInterval: Instana.Types.Seconds = 3600.0
26-
2725
let maxDaysToKeepCrashLog = 90
2826

2927
let sessionIDKey = "Instana_SessionIdKey"

Sources/InstanaAgent/Configuration/InstanaConfiguraton.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class InstanaConfiguration {
7070
var httpCaptureConfig: HTTPCaptureConfig
7171
var suspendReporting: Set<SuspendReporting>
7272
var monitorTypes: Set<MonitorTypes>
73-
var slowSendInterval: Instana.Types.Seconds
7473
var usiRefreshTimeIntervalInHrs: Double
7574
var anrThreshold: Double?
7675
var trustDeviceTiming: Bool?
@@ -94,7 +93,6 @@ class InstanaConfiguration {
9493

9594
required init(reportingURL: URL, key: String, httpCaptureConfig: HTTPCaptureConfig,
9695
enableCrashReporting: Bool, suspendReporting: Set<SuspendReporting>? = nil,
97-
slowSendInterval: Instana.Types.Seconds,
9896
usiRefreshTimeIntervalInHrs: Double,
9997
rateLimits: RateLimits?,
10098
perfConfig: InstanaPerformanceConfig? = nil,
@@ -128,7 +126,6 @@ class InstanaConfiguration {
128126
monitorTypes.insert(.crash)
129127
}
130128
self.suspendReporting = suspendReporting ?? SuspendReporting.defaults
131-
self.slowSendInterval = slowSendInterval
132129
self.usiRefreshTimeIntervalInHrs = usiRefreshTimeIntervalInHrs
133130
self.hybridAgentId = hybridAgentId
134131
self.hybridAgentVersion = hybridAgentVersion
@@ -182,7 +179,6 @@ class InstanaConfiguration {
182179
static func `default`(key: String, reportingURL: URL, httpCaptureConfig: HTTPCaptureConfig = .automatic,
183180
enableCrashReporting: Bool,
184181
suspendReporting: Set<SuspendReporting>? = nil,
185-
slowSendInterval: Instana.Types.Seconds = 0.0,
186182
usiRefreshTimeIntervalInHrs: Double = defaultUsiRefreshTimeIntervalInHrs,
187183
rateLimits: RateLimits? = nil,
188184
perfConfig: InstanaPerformanceConfig? = nil,
@@ -197,7 +193,6 @@ class InstanaConfiguration {
197193
self.init(reportingURL: reportingURL, key: key, httpCaptureConfig: httpCaptureConfig,
198194
enableCrashReporting: enableCrashReporting,
199195
suspendReporting: suspendReporting,
200-
slowSendInterval: slowSendInterval,
201196
usiRefreshTimeIntervalInHrs: usiRefreshTimeIntervalInHrs,
202197
rateLimits: rateLimits,
203198
perfConfig: perfConfig,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
struct VersionConfig {
2-
static let agentVersion = "1.9.8"
2+
static let agentVersion = "1.10.0"
33
}

0 commit comments

Comments
 (0)