Skip to content

Commit f3e1a25

Browse files
Grafana Loki Local Setup | Fix Metrics Service Conflicts in api_dev and worker_dev services (#201)
* feat(entrypoint): loki log backend implemented along with console logger to stream logs to console Everything tested. api_dev (development container service in docker-compose) works as expected. NOTE: the workers service specified in docker-compose must use a different port or should not expose its metrics (or can use port forwarding), since they are all on the same network (host network) * fix(configure): start prometheus service on a different port when running workers as processes This is required to avoid starting metrics server on exact same port when running locally with docker-compose (api_dev and worker_dev are both on host network) * fixup! fix(configure): start prometheus service on a different port when running workers as processes * fix: fixed some linting errors, refactored shared method to handle vapor application for tests Specifically the `withApp` method * fix: fixed all linting errors, deleted CLI and cli testing gh workflow
1 parent 0af53b7 commit f3e1a25

45 files changed

Lines changed: 262 additions & 1584 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/automa-cli-testing.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

App/AutomaAppShared/Sources/AutomaAppShared/Screens/Debug/DebugMenu.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public struct DebugMenu: View {
106106
config.text = "Set URL"
107107
},
108108
action: { _ in
109-
self.setBaseEnvUrl()
109+
setBaseEnvUrl()
110110
}
111111
)
112112
}

Backend/Package.resolved

Lines changed: 50 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Backend/Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public let package = Package(
3333
.package(url: "https://github.com/GetAutomaApp/Fakery", branch: "master"),
3434
.package(url: "https://github.com/GetAutomaApp/AutomaUtilities", branch: "main"),
3535
.package(url: "https://github.com/scinfu/SwiftSoup.git", from: "2.11.1"),
36+
.package(url: "https://github.com/lovetodream/swift-log-loki.git", branch: "main"),
3637
],
3738
targets: [
3839
.executableTarget(
@@ -56,7 +57,8 @@ public let package = Package(
5657
.product(name: "FeedKit", package: "FeedKit"),
5758
.product(name: "DMRetry", package: "swift-retry"),
5859
.product(name: "AutomaUtilities", package: "AutomaUtilities"),
59-
"SwiftSoup"
60+
"SwiftSoup",
61+
.product(name: "LoggingLoki", package: "swift-log-loki"),
6062
],
6163
exclude: [
6264
"Documentation.md",

Backend/Sources/App/Clients/AutomaWebCoreClient/AutomaWebCoreClient.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ internal struct AutomaWebCoreClient {
1010
private let client: any Client
1111
private let baseURL: URL
1212

13+
/// Initialize a new client for using AutomaWebCore API
14+
/// - Parameter client: HTTP client from a request of application
15+
/// - Throws: an error if environment variable `AUTOMA_WEB_CORE_API_BASE_URL` isn't found
1316
public init(client: any Client) throws {
1417
self.client = client
1518
let urlString = try Environment.getOrThrow("AUTOMA_WEB_CORE_API_BASE_URL")
1619
baseURL = try URL.fromString(payload: .init(string: urlString))
1720
}
1821

22+
/// Get the HTML of a specific website
23+
/// - Parameter payload: AutomaWebCoreAPI endpoint payload for configuring what website & how to get
24+
/// the HTML
25+
/// - Throws: An error when there was a problem making a request to AutomaWebCore API or
26+
/// when encoding the payload into request body
27+
/// - Returns: The website HTML as a string
1928
public func getWebsiteHTML(payload: AutomaWebCoreAPIEndpointPayload) async throws -> String {
2029
let res = try await client.get("\(baseURL.absoluteString)/api") { req in
2130
try req.content.encode(payload)

Backend/Sources/App/Clients/ChatCompletionClient/OpenAIChatCompletionClient/OpenAIChatCompletionClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ internal struct OpenAIChatCompletionClient: ChatCompletionClientBase {
130130

131131
// Log usage information
132132
logger.info(
133-
"OpenAI chat completions result metadata",
133+
"OpenAI chat completions result usage metadata",
134134
metadata: [
135135
"to": .string("\(String(describing: Self.self)).\(#function)"),
136136
"usage": .string("\(usage)"),
@@ -156,10 +156,10 @@ internal struct OpenAIChatCompletionClient: ChatCompletionClientBase {
156156
BackendMetric.chatCompletionServiceCall(platform: .openai, model: model, status: .success).increment()
157157
let metadata = try JSONEncoder().encode(result)
158158
logger.info(
159-
"OpenAI chat completions result metadata",
159+
"OpenAI chat completions result full metadata",
160160
metadata: [
161161
"to": .string("\(String(describing: Self.self)).\(#function)"),
162-
"metadata": .string(String(describing: metadata)),
162+
"metadata": .string(String(reflecting: result)),
163163
]
164164
)
165165

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// EnvironmentExtensions.swift
2+
// Copyright (c) 2025 GetAutomaApp
3+
// All source code and related assets are the property of GetAutomaApp.
4+
// All rights reserved.
5+
6+
import Vapor
7+
8+
internal extension Environment {
9+
enum AppMode {
10+
case http
11+
case queue(name: String)
12+
}
13+
14+
var appMode: AppMode {
15+
if
16+
CommandLine.arguments.contains("queues") ||
17+
CommandLine.arguments.contains("vapor-queues")
18+
{
19+
guard let name = CommandLine.arguments.firstIndex(of: "--queue") else {
20+
return .queue(name: "default")
21+
}
22+
23+
return .queue(name: CommandLine.arguments[name + 1])
24+
} else {
25+
return .http
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)