Skip to content

Commit

Permalink
RUMM-1691 Add basic stress-testing option for debugging Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ncreated committed Oct 7, 2021
1 parent f466c98 commit c0670b3
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 11 deletions.
69 changes: 58 additions & 11 deletions Datadog/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="gra-d4-cht">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="gra-d4-cht">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -18,15 +18,15 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<view key="tableFooterView" contentMode="scaleToFill" id="wle-IX-rUl">
<rect key="frame" x="0.0" y="223.00000034679067" width="414" height="0.0"/>
<rect key="frame" x="0.0" y="241" width="414" height="0.0"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<sections>
<tableViewSection headerTitle="Debug features:" id="tgY-ka-MYv">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="xoO-Hn-N29" style="IBUITableViewCellStyleDefault" id="2Id-yJ-iEw">
<rect key="frame" x="0.0" y="24.5" width="414" height="43.5"/>
<rect key="frame" x="0.0" y="44.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="2Id-yJ-iEw" id="wdg-my-MT5">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
Expand All @@ -46,7 +46,7 @@
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="NMa-2j-8ux" style="IBUITableViewCellStyleDefault" id="xsC-bs-aKd">
<rect key="frame" x="0.0" y="68" width="414" height="43.5"/>
<rect key="frame" x="0.0" y="88" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="xsC-bs-aKd" id="M0h-rT-0mQ">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
Expand All @@ -66,7 +66,7 @@
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="yCu-pq-IYL" style="IBUITableViewCellStyleDefault" id="3G8-Wa-fSQ">
<rect key="frame" x="0.0" y="111.5" width="414" height="43.5"/>
<rect key="frame" x="0.0" y="131.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="3G8-Wa-fSQ" id="7IJ-XI-RAR">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
Expand All @@ -86,7 +86,7 @@
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="rh1-Lx-HwO" style="IBUITableViewCellStyleDefault" id="cuG-eI-g1N">
<rect key="frame" x="0.0" y="155" width="414" height="43.5"/>
<rect key="frame" x="0.0" y="175" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="cuG-eI-g1N" id="GVN-Oe-gtW">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
Expand Down Expand Up @@ -300,28 +300,74 @@
<constraint firstAttribute="height" constant="44" id="qZn-EW-PqZ"/>
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Rlt-GG-uem" userLabel="Vertical gap 10">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ghm-SJ-eBQ" userLabel="Vertical gap 10">
<rect key="frame" x="0.0" y="251" width="384" height="10"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="10" id="d0W-7M-BGO"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="STRESS TESTING:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hVf-hM-tBK">
<rect key="frame" x="0.0" y="261" width="384" height="13.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" systemColor="systemGrayColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VDB-9q-Bc1" userLabel="Vertical gap 5">
<rect key="frame" x="0.0" y="274.5" width="384" height="5"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="5" id="ObB-P8-mKh"/>
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="l6y-hy-nRu">
<rect key="frame" x="0.0" y="279.5" width="384" height="44"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="n8y-PP-kzI">
<rect key="frame" x="0.0" y="0.0" width="384" height="44"/>
<color key="backgroundColor" red="0.38823529410000002" green="0.17254901959999999" blue="0.65098039220000004" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<state key="normal" title="Keep sending ~500 logs/s for 10s">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="titleShadowColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="layer.masksToBounds" value="YES"/>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="7"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="didTapStressTest:" destination="BYZ-38-t0r" eventType="touchUpInside" id="SzO-9c-7v5"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="44" id="VgF-xP-icc"/>
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Rlt-GG-uem" userLabel="Vertical gap 10">
<rect key="frame" x="0.0" y="323.5" width="384" height="10"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="10" id="oUy-Tr-5NI"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="CONSOLE OUTPUT:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="x1i-in-lYX">
<rect key="frame" x="0.0" y="261" width="384" height="13.5"/>
<rect key="frame" x="0.0" y="333.5" width="384" height="13.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" systemColor="systemGrayColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MU9-DG-sTJ" userLabel="Vertical gap 10">
<rect key="frame" x="0.0" y="274.5" width="384" height="10"/>
<rect key="frame" x="0.0" y="347" width="384" height="10"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="10" id="P0L-Pu-XZ9"/>
</constraints>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2G0-OF-tGX">
<rect key="frame" x="0.0" y="284.5" width="384" height="459.5"/>
<rect key="frame" x="0.0" y="357" width="384" height="387"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<color key="textColor" systemColor="systemGrayColor"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
Expand All @@ -347,6 +393,7 @@
<outlet property="logServiceNameTextField" destination="fGc-5E-uEZ" id="15I-2q-gUt"/>
<outlet property="send10xButton" destination="u78-T2-8Dx" id="EK9-y6-WQK"/>
<outlet property="sendOnceButton" destination="gtC-h0-4xC" id="9Cc-de-Und"/>
<outlet property="stressTestButton" destination="n8y-PP-kzI" id="tKj-cc-sV9"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand Down
41 changes: 41 additions & 0 deletions Datadog/Example/Debugging/DebugLoggingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
*/

import UIKit
import Datadog

class DebugLoggingViewController: UIViewController {
@IBOutlet weak var logLevelSegmentedControl: UISegmentedControl!
@IBOutlet weak var logMessageTextField: UITextField!
@IBOutlet weak var logServiceNameTextField: UITextField!
@IBOutlet weak var sendOnceButton: UIButton!
@IBOutlet weak var send10xButton: UIButton!
@IBOutlet weak var stressTestButton: UIButton!
@IBOutlet weak var consoleTextView: UITextView!

struct StructError: Error {
Expand Down Expand Up @@ -78,4 +80,43 @@ class DebugLoggingViewController: UIViewController {
private func repeat10x(block: () -> Void) {
(0..<10).forEach { _ in block() }
}

// MARK: - Stress testing

var queues: [DispatchQueue] = []
var loggers: [Logger] = []

@IBAction func didTapStressTest(_ sender: Any) {
stressTestButton.disableFor(seconds: 10)

loggers = (0..<5).map { index in
return Logger.builder.set(loggerName: "stress-logger-\(index)")
.sendNetworkInfo(true)
.build()
}

queues = (0..<5).map { index in
return DispatchQueue(label: "com.datadoghq.example.stress-testing-queue\(index)")
}

let endDate = Date(timeIntervalSinceNow: 10) // 10s
zip(loggers, queues).forEach { logger, queue in
keepSendingLogs(on: queue, using: logger, every: 0.01, until: endDate)
}
}

private func keepSendingLogs(on queue: DispatchQueue, using logger: Logger, every timeInterval: TimeInterval, until endDate: Date) {
if Date() < endDate {
queue.asyncAfter(deadline: .now() + timeInterval) { [weak self] in
logger.debug(self?.randomLogMessage() ?? "")
self?.keepSendingLogs(on: queue, using: logger, every: timeInterval, until: endDate)
}
}
}

private let alphanumerics = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

private func randomLogMessage() -> String {
return String((0..<20).map { _ in alphanumerics.randomElement()! })
}
}

0 comments on commit c0670b3

Please sign in to comment.