Skip to content

Commit

Permalink
Feature/demrum 863 custom data module skeleton (#240)
Browse files Browse the repository at this point in the history
* DEMRUM-863: adding MRUMCustomData (will be: SplunkCustomData) module skeleton

* DEMRUM-863: fix swiftlint issues other than TODOs

* DEMRUM-863: Update naming to SplunkCustomData
  • Loading branch information
carlosmcevilly authored Feb 5, 2025
1 parent 5708128 commit e94afdc
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Splunk.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions SplunkCustomData/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SplunkCustomData"
BuildableName = "SplunkCustomData"
BlueprintName = "SplunkCustomData"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SplunkCustomData"
BuildableName = "SplunkCustomData"
BlueprintName = "SplunkCustomData"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
33 changes: 33 additions & 0 deletions SplunkCustomData/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// swift-tools-version: 5.9

import PackageDescription

let package = Package(
name: "SplunkCustomData",
platforms: [
.iOS(.v13),
.tvOS(.v13),
.visionOS(.v1)
],
products: [
.library(
name: "SplunkCustomData",
targets: ["SplunkCustomData"]
)
],
dependencies: [
.package(name: "SplunkSharedProtocols", path: "../SplunkSharedProtocols")
],
targets: [
.target(
name: "SplunkCustomData",
dependencies: [
"SplunkSharedProtocols"
]
),
.testTarget(
name: "SplunkCustomDataTests",
dependencies: ["SplunkCustomData"]
)
]
)
64 changes: 64 additions & 0 deletions SplunkCustomData/Sources/SplunkCustomData/CustomData+Module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import SplunkSharedProtocols

// `Data` can be used as an event type that the module produces.
extension Data: ModuleEventData {}

// Struct `EventMetadataCustomData` describes event metadata.
// This type must be unique in the module/agent space.
extension EventMetadataCustomData: ModuleEventMetadata {
public static func == (lhs: EventMetadataCustomData, rhs: EventMetadataCustomData) -> Bool {
lhs.id == rhs.id
}
}

// Defines CustomData conformance to `Module` protocol
// and implements methods that are missing in the original `CustomData`.
extension CustomData: Module {


// MARK: - Module types

public typealias Configuration = CustomDataConfiguration
public typealias RemoteConfiguration = CustomDataRemoteConfiguration

public typealias EventData = Data


// MARK: - Module methods

public func install(with configuration: (any ModuleConfiguration)?, remoteConfiguration: (any RemoteModuleConfiguration)?) {
if let configuration = configuration as? CustomDataConfiguration {
print("known configuration")
print(configuration)
}
}


// MARK: - Type transparency helpers

public func deleteData(for metadata: any ModuleEventMetadata) {
// TODO: Code TBD
}

public func onPublish(data: @escaping (EventMetadataCustomData, EventData) -> Void) {
// TODO: Code TBD
}
}
46 changes: 46 additions & 0 deletions SplunkCustomData/Sources/SplunkCustomData/CustomData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import SplunkSharedProtocols

protocol CustomDataRepresentable: PropertyList {}

public final class CustomData {


// MARK: - Private properties

private var config = CustomDataConfiguration(enabled: true)


// MARK: - CustomData lifecycle

public required init() {} // see install() in Module extension for startup tasks


// MARK: - CustomData helper functions


// MARK: - CustomData Reporting

// This is a placeholder for temporary use only. Will be replaced by
// real data population and output.
private func reportCustom(data: CustomDataRepresentable) {
print(String(describing: data))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import SplunkSharedProtocols

public struct CustomDataConfiguration: ModuleConfiguration {


// MARK: - Public

public var enabled: Bool
public var threshold: CFTimeInterval


// MARK: init()

public init(enabled: Bool, threshold: CFTimeInterval = 2.0) {
self.enabled = enabled
self.threshold = threshold
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import SplunkSharedProtocols

public struct CustomDataRemoteConfiguration: RemoteModuleConfiguration {


// MARK: - Public

public var enabled: Bool


// MARK: init()

public init?(from data: Data) {
enabled = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation

public struct EventMetadataCustomData {


// MARK: - Public

public var timestamp = Date()


// MARK: - Internal

let id: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
/*
Copyright 2025 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

@testable import SplunkCustomData
import XCTest

final class SplunkCustomDataTests: XCTestCase {
func testExample() throws {
// XCTest Documentation
// https://developer.apple.com/documentation/xctest

// Defining Test Cases and Test Methods
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
}
}

0 comments on commit e94afdc

Please sign in to comment.