-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add provisional support for Agent Metrics
- Loading branch information
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// AgentMetrics.swift | ||
// Buildkite | ||
// | ||
// Created by Aaron Sky on 6/5/22. | ||
// Copyright © 2022 Aaron Sky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
public struct AgentMetrics: Codable, Equatable { | ||
public var agents: AgentTotals | ||
public var jobs: JobTotals | ||
public var organization: Organization | ||
|
||
public struct AgentTotals: Codable, Equatable { | ||
public var idle: Int | ||
public var busy: Int | ||
public var total: Int | ||
public var queues: [String: AgentTotals] = [:] | ||
} | ||
|
||
public struct JobTotals: Codable, Equatable { | ||
public var scheduled: Int | ||
public var running: Int | ||
public var waiting: Int | ||
public var total: Int | ||
public var queues: [String: JobTotals] = [:] | ||
} | ||
|
||
public struct Organization: Codable, Equatable { | ||
public var slug: String | ||
} | ||
} |
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,42 @@ | ||
// | ||
// AgentMetrics.swift | ||
// Buildkite | ||
// | ||
// Created by Aaron Sky on 6/5/22. | ||
// Copyright © 2022 Aaron Sky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
extension AgentMetrics { | ||
/// Resources for requesting information about your organization's Buildkite agents. | ||
public enum Resources {} | ||
} | ||
|
||
extension AgentMetrics.Resources { | ||
/// Get metrics about agents active with the current organization. | ||
public struct Get: Resource { | ||
public typealias Content = AgentMetrics | ||
|
||
public var version: APIVersion { | ||
APIVersion.Agent.v3 | ||
} | ||
|
||
public let path = "metrics" | ||
|
||
public init() {} | ||
} | ||
} | ||
|
||
extension Resource where Self == AgentMetrics.Resources.Get { | ||
/// Get an object with properties describing Buildkite | ||
/// | ||
/// Returns meta information about Buildkite. | ||
public static var agentMetrics: Self { | ||
Self() | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Tests/BuildkiteTests/Resources/Agent/AgentMetricsTests.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,50 @@ | ||
// | ||
// AgentMetricsTests.swift | ||
// Buildkite | ||
// | ||
// Created by Aaron Sky on 6/5/22. | ||
// Copyright © 2022 Aaron Sky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
|
||
@testable import Buildkite | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
extension AgentMetrics { | ||
init() { | ||
self.init( | ||
agents: .init( | ||
idle: 0, | ||
busy: 0, | ||
total: 0, | ||
queues: [:] | ||
), | ||
jobs: .init( | ||
scheduled: 0, | ||
running: 0, | ||
waiting: 0, | ||
total: 0, | ||
queues: [:] | ||
), | ||
organization: .init( | ||
slug: "buildkite" | ||
) | ||
) | ||
} | ||
} | ||
|
||
class AgentMetricsTests: XCTestCase { | ||
func testAgentMetricsGet() async throws { | ||
let expected = AgentMetrics() | ||
let context = try MockContext(content: expected) | ||
|
||
let response = try await context.client.send(.agentMetrics) | ||
|
||
XCTAssertEqual(expected, response.content) | ||
} | ||
} |