Skip to content

Commit

Permalink
Added Disable csm flag (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrajatttt authored Oct 17, 2024
1 parent c36f1b4 commit d80d846
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 39 deletions.
13 changes: 2 additions & 11 deletions AmazonConnectChatIOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
F747263E2BF4143D002B278E /* MetricsUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = F747263D2BF4143D002B278E /* MetricsUtils.swift */; };
F74726442BF418F0002B278E /* MetricsClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = F74726432BF418F0002B278E /* MetricsClient.swift */; };
F74726472BF41948002B278E /* MetricsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F74726462BF41948002B278E /* MetricsManager.swift */; };
F74726522BF6F018002B278E /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = F74726512BF6F018002B278E /* Config.swift */; };
F76BB94D2C1898BE0005C3EC /* APIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76BB94C2C1898BE0005C3EC /* APIClient.swift */; };
F76BB9532C18F84D0005C3EC /* MockAPIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76BB9522C18F84D0005C3EC /* MockAPIClient.swift */; };
F76BB9562C1900480005C3EC /* APIClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76BB9552C1900480005C3EC /* APIClientTests.swift */; };
Expand All @@ -63,8 +62,7 @@
F7B4A1382C15649B005C7921 /* MockHttpClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B4A1372C15649B005C7921 /* MockHttpClient.swift */; };
F7B4A13A2C17AE43005C7921 /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B4A1392C17AE43005C7921 /* TestUtils.swift */; };
F7B4A13C2C17E3C3005C7921 /* MockURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B4A13B2C17E3C3005C7921 /* MockURLSession.swift */; };
F7BE6CC82C3E1CC500E7A88A /* BuildFile in Sources */ = {isa = PBXBuildFile; };

F7BE6CC82C3E1CC500E7A88A /* (null) in Sources */ = {isa = PBXBuildFile; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -119,7 +117,6 @@
F747263D2BF4143D002B278E /* MetricsUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricsUtils.swift; sourceTree = "<group>"; };
F74726432BF418F0002B278E /* MetricsClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricsClient.swift; sourceTree = "<group>"; };
F74726462BF41948002B278E /* MetricsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricsManager.swift; sourceTree = "<group>"; };
F74726512BF6F018002B278E /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
F76BB94C2C1898BE0005C3EC /* APIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClient.swift; sourceTree = "<group>"; };
F76BB9522C18F84D0005C3EC /* MockAPIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAPIClient.swift; sourceTree = "<group>"; };
F76BB9552C1900480005C3EC /* APIClientTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClientTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -297,7 +294,6 @@
7E58A6082BBB460900965327 /* CommonUtils.swift */,
7E91597A2BC0A92E00821C05 /* Constants.swift */,
F747263D2BF4143D002B278E /* MetricsUtils.swift */,
F74726512BF6F018002B278E /* Config.swift */,
7E1FA2192C3DC16D0014C33F /* TranscriptItemUtils.swift */,
);
path = Utils;
Expand Down Expand Up @@ -473,15 +469,14 @@
7E57F6522BC7758C00B25623 /* ConnectionDetails.swift in Sources */,
F76BB94D2C1898BE0005C3EC /* APIClient.swift in Sources */,
7E58A6092BBB460A00965327 /* DefaultHttpClient.swift in Sources */,
F74726522BF6F018002B278E /* Config.swift in Sources */,
7E91597B2BC0A92E00821C05 /* Constants.swift in Sources */,
7E58A5F92BB605F300965327 /* TranscriptResponse.swift in Sources */,
7E58A6232BBDDBF900965327 /* ChatSession.swift in Sources */,
7E58A6272BBDDE4A00965327 /* AWSClient.swift in Sources */,
7E58A5FC2BB605F300965327 /* MessageContent.swift in Sources */,
7E57F6542BC7762900B25623 /* ConnectionDetailsProvider.swift in Sources */,
7E58A6292BBE415700965327 /* ChatService.swift in Sources */,
F7BE6CC82C3E1CC500E7A88A /* BuildFile in Sources */,
F7BE6CC82C3E1CC500E7A88A /* (null) in Sources */,
7E58A60E2BBB460A00965327 /* CommonUtils.swift in Sources */,
7ED5DEC42BEAFD42001693FC /* Event.swift in Sources */,
7E58A60A2BBB460A00965327 /* HttpMethod.swift in Sources */,
Expand Down Expand Up @@ -670,7 +665,6 @@
};
7E58A5E92BB5F3DA00965327 /* Debug */ = {
isa = XCBuildConfiguration;

buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand Down Expand Up @@ -703,7 +697,6 @@
};
7E58A5EA2BB5F3DA00965327 /* Release */ = {
isa = XCBuildConfiguration;

buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand Down Expand Up @@ -736,7 +729,6 @@
};
7E58A5EC2BB5F3DA00965327 /* Debug */ = {
isa = XCBuildConfiguration;

buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
Expand All @@ -756,7 +748,6 @@
};
7E58A5ED2BB5F3DA00965327 /* Release */ = {
isa = XCBuildConfiguration;

buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,23 @@ The Amazon Connect Chat SDK for iOS provides two methods to receive messages.
The `GlobalConfig` object is used to configure both the AWS ConnectParticipant client as well as some of the chat behavior.

#### `GlobalConfig.init`
The initializer for the `GlobalConfig` object takes in the `AWSRegionType` and the enabled `Features`
The initializer for the `GlobalConfig` object takes in the `AWSRegionType`, the enabled `Features` and `disableCSM` flag to disable metrics.

```
public struct GlobalConfig {
public var region: AWSRegionType
public var features: Features
public var disableCsm: Bool

public static var defaultRegion: AWSRegionType {
return Constants.DEFAULT_REGION
}

// Initializes a new global configuration with optional custom settings or defaults
public init(region: AWSRegionType = defaultRegion, features: Features = .defaultFeatures) {
public init(region: AWSRegionType = defaultRegion, features: Features = .defaultFeatures, disableCsm: Bool = false) {
self.region = region
self.features = features
self.disableCsm = disableCsm
}
}
```
Expand Down
4 changes: 3 additions & 1 deletion Sources/Core/Models/GlobalConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import AWSCore
public struct GlobalConfig {
public var region: AWSRegionType
public var features: Features
public var disableCsm: Bool

public static var defaultRegion: AWSRegionType {
return Constants.DEFAULT_REGION
}

// Initializes a new global configuration with optional custom settings or defaults
public init(region: AWSRegionType = defaultRegion, features: Features = .defaultFeatures) {
public init(region: AWSRegionType = defaultRegion, features: Features = .defaultFeatures, disableCsm: Bool = false) {
self.region = region
self.features = features
self.disableCsm = disableCsm
}
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/Core/Network/MetricsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ class MetricsClient {
self.metricsManager = MetricsManager(endpointUrl: MetricsUtils().getMetricsEndpoint())
}

func configureMetricsManager(config: GlobalConfig){
metricsManager.configure(config: config)
}

func triggerCountMetric(metricName: MetricName) {
metricsManager.addCountMetric(metricName: metricName)
}
}

13 changes: 9 additions & 4 deletions Sources/Core/Network/MetricsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ class MetricsManager {
private var metricList: [Metric]
private var isMonitoring: Bool = false
private var shouldRetry: Bool = true
private var isCsmDisabled: Bool = false

init(endpointUrl: String) {
self.endpointUrl = endpointUrl
self.metricList = []
if !MetricsUtils().isCsmDisabled() {
monitorAndSendMetrics()
}
}

deinit {
self.timer?.invalidate()
}

func configure(config: GlobalConfig){
isCsmDisabled = config.disableCsm
if !isCsmDisabled {
monitorAndSendMetrics()
}
}

private func monitorAndSendMetrics() {
if self.isMonitoring {
return
Expand Down Expand Up @@ -76,7 +81,7 @@ class MetricsManager {
}

func addMetric(metric: Metric) {
if MetricsUtils().isCsmDisabled() {
if isCsmDisabled {
return
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Core/Service/ChatService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ class ChatService : ChatServiceProtocol {
let messageReceiptConfig = config.features.messageReceipts
messageReceiptsManager?.throttleTime = messageReceiptConfig.throttleTime
messageReceiptsManager?.shouldSendMessageReceipts = messageReceiptConfig.shouldSendMessageReceipts
MetricsClient.shared.configureMetricsManager(config: config)
}

func registerNotificationListeners() {
Expand Down
12 changes: 0 additions & 12 deletions Sources/Core/Utils/Config.swift

This file was deleted.

10 changes: 1 addition & 9 deletions Sources/Core/Utils/MetricsUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Foundation
import AWSConnectParticipant

struct MetricsUtils {
private let config = Config()

func getCurrentMetricTimestamp() -> String {
let formatter = ISO8601DateFormatter()
Expand All @@ -17,14 +16,7 @@ struct MetricsUtils {
}

func getMetricsEndpoint() -> String {
if config.isDevMode {
return "https://f9cskafqk3.execute-api.us-west-2.amazonaws.com/devo/put-metrics"
} else {
return "https://ieluqbvv.telemetry.connect.us-west-2.amazonaws.com/prod/put-metrics"
}
return "https://ieluqbvv.telemetry.connect.us-west-2.amazonaws.com/prod/put-metrics"
}

func isCsmDisabled() -> Bool {
return config.disableCsm
}
}

0 comments on commit d80d846

Please sign in to comment.