-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update attribute processor for stable metrics (#524)
Previously AttribtueProcessor is a class and not open. It can't be customized externally. Now it's changed to procotol and its static functions are moved into SimpleAttributeProcessor (now it's public). Also duplicated NoopAttributesProcessor is removed and more tests are added.
- Loading branch information
Showing
5 changed files
with
78 additions
and
70 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
Sources/OpenTelemetrySdk/Metrics/Stable/NoopAttributesProcessor.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Tests/OpenTelemetrySdkTests/Metrics/StableMetrics/AttributeProcessorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
import OpenTelemetryApi | ||
@testable import OpenTelemetrySdk | ||
import XCTest | ||
|
||
class AttributeProcessorTests : XCTestCase { | ||
func testStaticNoop() { | ||
XCTAssertNotNil(NoopAttributeProcessor.noop) | ||
XCTAssertEqual(NoopAttributeProcessor.noop.process(incoming: ["hello": AttributeValue.string("world")]), ["hello" : AttributeValue.string("world")]) | ||
} | ||
|
||
func testSimpleProcessor() { | ||
let incoming = ["hello": AttributeValue("world")] | ||
|
||
var processor: AttributeProcessor = SimpleAttributeProcessor.append(attributes: ["foo" : .string("bar")]) | ||
XCTAssertEqual(processor.process(incoming: incoming), ["hello" : .string("world"), "foo": .string("bar")]) | ||
|
||
processor = processor.then(other: SimpleAttributeProcessor.filterByKeyName(nameFilter: { $0 == "foo" })) | ||
XCTAssertEqual(processor.process(incoming: incoming), ["foo": .string("bar")]) | ||
} | ||
|
||
func testJoinedProcessor() { | ||
let incoming = ["hello": AttributeValue("world")] | ||
|
||
let processor0 = SimpleAttributeProcessor.append(attributes: ["foo" : .string("bar0")]) | ||
let processor1 = SimpleAttributeProcessor.append(attributes: ["foo" : .string("bar1")]) | ||
let processor2 = SimpleAttributeProcessor.append(attributes: ["foo" : .string("bar2")]) | ||
|
||
var processor = JoinedAttributeProcessor([processor0]) | ||
XCTAssertEqual(processor.process(incoming: incoming), ["hello" : .string("world"), "foo": .string("bar0")]) | ||
|
||
processor = processor.prepend(processor: processor1) | ||
XCTAssertEqual(processor.process(incoming: incoming), ["hello" : .string("world"), "foo": .string("bar0")]) | ||
|
||
processor = processor.append(processor: processor2) | ||
XCTAssertEqual(processor.process(incoming: incoming), ["hello" : .string("world"), "foo": .string("bar2")]) | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
Tests/OpenTelemetrySdkTests/Metrics/StableMetrics/NoopAttributesProcessorTests.swift
This file was deleted.
Oops, something went wrong.