From 10b32a1bf234debd9036488c918830c41135faf0 Mon Sep 17 00:00:00 2001 From: Arafo Date: Sun, 19 Nov 2023 22:20:47 +0100 Subject: [PATCH 1/4] Add a new endpoint to filter build metadata Draft for issue #108 --- .../Builds/Controllers/BuildController.swift | 49 +++++++++++++++++++ .../Model/BuildMetadataFilterParams.swift | 28 +++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Sources/XCMetricsBackendLib/Builds/Model/BuildMetadataFilterParams.swift diff --git a/Sources/XCMetricsBackendLib/Builds/Controllers/BuildController.swift b/Sources/XCMetricsBackendLib/Builds/Controllers/BuildController.swift index 787b2c4..f5a7941 100644 --- a/Sources/XCMetricsBackendLib/Builds/Controllers/BuildController.swift +++ b/Sources/XCMetricsBackendLib/Builds/Controllers/BuildController.swift @@ -38,6 +38,7 @@ public struct BuildController: RouteCollection { routes.get("v1", "build", ":id", use: build) routes.get("v1", "build", use: index) routes.get("v1", "build", "step", ":day", ":id", use: targetSteps) + routes.post("v1", "build", "metadata", "filter", use: metadataFilter) } /// Endpoint that returns the paginated list of `Build` @@ -529,6 +530,54 @@ public struct BuildController: RouteCollection { .all(decoding: Step.self) } + /// Endpoint that returns the list of `BuildMetadata`s that were added to a build + /// filtered by a given key-value pair. + /// - Method: `POST` + /// - Route: `/v1/build/metadata/filter` + /// - Request body + /// + /// ``` + /// { + /// "key": "aKey", + /// "value": "value1" + /// } + /// ``` + /// + /// - Body Parameters + /// - `key`. `BuildMetadata` metadata dictionary key + /// - `value`. `BuildMetadata` metadata dictionary value + /// + /// - Response: + /// + /// ``` + /// [ + /// { + /// "metadata": { + /// "anotherKey": "42", + /// "thirdKey": "Third value", + /// "aKey": "value1" + /// }, + /// "id": "C1CDF2CE-0CC2-49C3-B8A2-481E67020CB8", + /// "day": "2020-11-02T00:00:00Z", + /// "buildIdentifier": "MyMac_0B9294B4-7E5A-4D40-91AB-5953A5075785_1" + /// }, + /// ... + /// ] + /// ``` + /// + public func metadataFilter(req: Request) throws -> EventLoopFuture<[BuildMetadata]> { + let params = try req.content.decode(BuildMetadataFilterParams.self) + guard let sql = req.db as? SQLDatabase else { + throw Abort(.internalServerError) + } + + return sql.raw(""" + SELECT * FROM \(raw: BuildMetadata.schema) + WHERE metadata ->> '\(raw: params.key)' = '\(raw: params.value)' + """) + .all(decoding: BuildMetadata.self) + } + } public struct BuildResponse: Content { diff --git a/Sources/XCMetricsBackendLib/Builds/Model/BuildMetadataFilterParams.swift b/Sources/XCMetricsBackendLib/Builds/Model/BuildMetadataFilterParams.swift new file mode 100644 index 0000000..6710c9d --- /dev/null +++ b/Sources/XCMetricsBackendLib/Builds/Model/BuildMetadataFilterParams.swift @@ -0,0 +1,28 @@ +// Copyright (c) 2020 Spotify AB. +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 Vapor + +struct BuildMetadataFilterParams: Content { + + var key: String + + var value: String +} From 41bd0a5baeb7d5b51548f1a5f66ea22f608b681d Mon Sep 17 00:00:00 2001 From: Patrick Balestra Date: Wed, 10 Jan 2024 14:21:48 +0100 Subject: [PATCH 2/4] Remove references to Spotify FOSS Slack (#113) --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index a9ecf66..97cef87 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ _XCMetrics is the easiest way to collect Xcode builds metrics and improve your d [![Build Status](https://github.com/spotify/XCMetrics/workflows/CI/badge.svg)](https://github.com/spotify/XCMetrics/workflows/CI/badge.svg) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![Docker image](https://img.shields.io/docker/pulls/spotify/xcmetrics.svg)](https://hub.docker.com/r/spotify/xcmetrics) -[![Slack](https://slackin.spotify.com/badge.svg)](https://slackin.spotify.com) ## Overview @@ -36,8 +35,6 @@ xed Package.swift Create a [new issue](https://github.com/spotify/XCMetrics/issues/new) with as many details as possible. It's important that you follow the issue template and include all required information in order for us to get back to you as soon as possible. -Reach us at the `#xcmetrics` channel in [Slack](https://slackin.spotify.com/). - ## Contributing We feel that a welcoming community is important and we ask that you follow Spotify's From 9befa67145850f0b0aa738ce8d569f1a42e28e6a Mon Sep 17 00:00:00 2001 From: LouieAtFetch <146202371+LouieAtFetch@users.noreply.github.com> Date: Tue, 16 Jan 2024 08:49:39 -0600 Subject: [PATCH 3/4] issue-111 update XCLogParser to v0.2.37 (#112) * issue-111 update XCLogParser to v0.2.37 * issue-111 upgraded to 0.2.38 of XCLogParser due to bug fix --- Package.resolved | 908 +++++++++++++++++++++++------------------------ Package.swift | 2 +- 2 files changed, 454 insertions(+), 456 deletions(-) diff --git a/Package.resolved b/Package.resolved index e7e6aaa..e000e53 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,457 +1,455 @@ { - "object": { - "pins": [ - { - "package": "async-http-client", - "repositoryURL": "https://github.com/swift-server/async-http-client.git", - "state": { - "branch": null, - "revision": "fc510a39cff61b849bf5cdff17eb2bd6d0777b49", - "version": "1.11.5" - } - }, - { - "package": "async-kit", - "repositoryURL": "https://github.com/vapor/async-kit.git", - "state": { - "branch": null, - "revision": "c3329e444bafbb12d1d312af9191be95348a8175", - "version": "1.13.0" - } - }, - { - "package": "AWSSDKSwiftCore", - "repositoryURL": "https://github.com/swift-aws/aws-sdk-swift-core.git", - "state": { - "branch": null, - "revision": "13738adc1603e4b50ae6aa3f758fc44f51e46aa3", - "version": "4.5.1" - } - }, - { - "package": "console-kit", - "repositoryURL": "https://github.com/vapor/console-kit.git", - "state": { - "branch": null, - "revision": "7cf8185ad62d50ae9777ce78bcfde8f5c9f900e2", - "version": "4.2.1" - } - }, - { - "package": "CryptoSwift", - "repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git", - "state": { - "branch": null, - "revision": "e2bc81be54d71d566a52ca17c3983d141c30aa70", - "version": "1.3.3" - } - }, - { - "package": "fluent", - "repositoryURL": "https://github.com/vapor/fluent.git", - "state": { - "branch": null, - "revision": "26c446002f03c5ab34b20d86873014ef3d92d0da", - "version": "4.5.0" - } - }, - { - "package": "fluent-kit", - "repositoryURL": "https://github.com/vapor/fluent-kit.git", - "state": { - "branch": null, - "revision": "38670d2eefcba27530272946d627ac8d4e45f017", - "version": "1.35.1" - } - }, - { - "package": "fluent-postgres-driver", - "repositoryURL": "https://github.com/vapor/fluent-postgres-driver.git", - "state": { - "branch": null, - "revision": "a8b2839ea86c44a35c17f66eb0885f9e5b51a531", - "version": "2.4.0" - } - }, - { - "package": "google-cloud-kit", - "repositoryURL": "https://github.com/vapor-community/google-cloud-kit.git", - "state": { - "branch": null, - "revision": "100c049449634db059b539a58467dff37450398e", - "version": "1.0.0-rc.3" - } - }, - { - "package": "GRPC", - "repositoryURL": "https://github.com/grpc/grpc-swift.git", - "state": { - "branch": null, - "revision": "be70633c91d722496e5fcb225f822edbd5c36a5a", - "version": "1.0.0-alpha.9" - } - }, - { - "package": "Gzip", - "repositoryURL": "https://github.com/1024jp/GzipSwift", - "state": { - "branch": null, - "revision": "ba0b6cb51cc6202f896e469b87d2889a46b10d1b", - "version": "5.1.1" - } - }, - { - "package": "HypertextApplicationLanguage", - "repositoryURL": "https://github.com/swift-aws/HypertextApplicationLanguage.git", - "state": { - "branch": null, - "revision": "aa2c9141d491682f17b2310aed17b9adfc006256", - "version": "1.1.1" - } - }, - { - "package": "jwt-kit", - "repositoryURL": "https://github.com/vapor/jwt-kit.git", - "state": { - "branch": null, - "revision": "6055fe8439769aa3646a3c797d573ce7305849c8", - "version": "4.2.0" - } - }, - { - "package": "Mobius", - "repositoryURL": "https://github.com/Spotify/Mobius.swift", - "state": { - "branch": null, - "revision": "afe23c2a66ea1fd52fb9fe76fa051d9a7b789845", - "version": "0.3.0" - } - }, - { - "package": "multipart-kit", - "repositoryURL": "https://github.com/vapor/multipart-kit.git", - "state": { - "branch": null, - "revision": "2dd9368a3c9580792b77c7ef364f3735909d9996", - "version": "4.5.1" - } - }, - { - "package": "Nimble", - "repositoryURL": "https://github.com/Quick/Nimble", - "state": { - "branch": null, - "revision": "7a46a5fc86cb917f69e3daf79fcb045283d8f008", - "version": "8.1.2" - } - }, - { - "package": "PathKit", - "repositoryURL": "https://github.com/kylef/PathKit.git", - "state": { - "branch": null, - "revision": "3bfd2737b700b9a36565a8c94f4ad2b050a5e574", - "version": "1.0.1" - } - }, - { - "package": "INIParser", - "repositoryURL": "https://github.com/swift-aws/Perfect-INIParser.git", - "state": { - "branch": null, - "revision": "42de0efc7a01105e19b80d533d3d282a98277f6c", - "version": "3.0.3" - } - }, - { - "package": "postgres-kit", - "repositoryURL": "https://github.com/vapor/postgres-kit.git", - "state": { - "branch": null, - "revision": "e97975309073e05d408749ccc1356076e4fdc22a", - "version": "2.8.2" - } - }, - { - "package": "postgres-nio", - "repositoryURL": "https://github.com/vapor/postgres-nio.git", - "state": { - "branch": null, - "revision": "d648c5b4594ffbc2f6173318f70f5531e05ccb4e", - "version": "1.11.0" - } - }, - { - "package": "queues", - "repositoryURL": "https://github.com/vapor/queues.git", - "state": { - "branch": null, - "revision": "9418af49ca3ca779c2fab7aa0cedecb1aa6779b6", - "version": "1.5.1" - } - }, - { - "package": "queues-redis-driver", - "repositoryURL": "https://github.com/vapor/queues-redis-driver.git", - "state": { - "branch": null, - "revision": "04306b81ef25b3bc42d9634c7c657b3eb498ed0e", - "version": "1.0.0" - } - }, - { - "package": "Quick", - "repositoryURL": "https://github.com/Quick/Quick", - "state": { - "branch": null, - "revision": "09b3becb37cb2163919a3842a4c5fa6ec7130792", - "version": "2.2.1" - } - }, - { - "package": "redis", - "repositoryURL": "https://github.com/vapor/redis.git", - "state": { - "branch": null, - "revision": "00fdd687ec56468a3e21204ac0a9b6337d7e79ed", - "version": "4.0.0" - } - }, - { - "package": "RediStack", - "repositoryURL": "https://gitlab.com/mordil/RediStack.git", - "state": { - "branch": null, - "revision": "b2367ac33eb8632011c1ec7afff12307838a4dab", - "version": "1.1.0" - } - }, - { - "package": "routing-kit", - "repositoryURL": "https://github.com/vapor/routing-kit.git", - "state": { - "branch": null, - "revision": "ffac7b3a127ce1e85fb232f1a6271164628809ad", - "version": "4.6.0" - } - }, - { - "package": "AWSSDKSwift", - "repositoryURL": "https://github.com/soto-project/soto.git", - "state": { - "branch": null, - "revision": "803ab6a86a3c90e1405afb8fd6a131ec9b9ec64a", - "version": "4.6.0" - } - }, - { - "package": "Spectre", - "repositoryURL": "https://github.com/kylef/Spectre.git", - "state": { - "branch": null, - "revision": "26cc5e9ae0947092c7139ef7ba612e34646086c7", - "version": "0.10.1" - } - }, - { - "package": "sql-kit", - "repositoryURL": "https://github.com/vapor/sql-kit.git", - "state": { - "branch": null, - "revision": "3c5413a229bc2abc962dab17ea66d25e448ad344", - "version": "3.21.0" - } - }, - { - "package": "swift-algorithms", - "repositoryURL": "https://github.com/apple/swift-algorithms.git", - "state": { - "branch": null, - "revision": "b14b7f4c528c942f121c8b860b9410b2bf57825e", - "version": "1.0.0" - } - }, - { - "package": "swift-argument-parser", - "repositoryURL": "https://github.com/apple/swift-argument-parser", - "state": { - "branch": null, - "revision": "fddd1c00396eed152c45a46bea9f47b98e59301d", - "version": "1.2.0" - } - }, - { - "package": "swift-atomics", - "repositoryURL": "https://github.com/apple/swift-atomics.git", - "state": { - "branch": null, - "revision": "919eb1d83e02121cdb434c7bfc1f0c66ef17febe", - "version": "1.0.2" - } - }, - { - "package": "swift-backtrace", - "repositoryURL": "https://github.com/swift-server/swift-backtrace.git", - "state": { - "branch": null, - "revision": "f2fd8c4845a123419c348e0bc4b3839c414077d5", - "version": "1.2.0" - } - }, - { - "package": "swift-collections", - "repositoryURL": "https://github.com/apple/swift-collections.git", - "state": { - "branch": null, - "revision": "f504716c27d2e5d4144fa4794b12129301d17729", - "version": "1.0.3" - } - }, - { - "package": "swift-crypto", - "repositoryURL": "https://github.com/apple/swift-crypto.git", - "state": { - "branch": null, - "revision": "afe4c9b5f65b612a2bd4b1cb5ac70eb5841f278e", - "version": "1.1.0" - } - }, - { - "package": "swift-log", - "repositoryURL": "https://github.com/apple/swift-log.git", - "state": { - "branch": null, - "revision": "6fe203dc33195667ce1759bf0182975e4653ba1c", - "version": "1.4.4" - } - }, - { - "package": "swift-metrics", - "repositoryURL": "https://github.com/apple/swift-metrics.git", - "state": { - "branch": null, - "revision": "708b960b4605abb20bc55d65abf6bad607252200", - "version": "2.0.0" - } - }, - { - "package": "swift-nio", - "repositoryURL": "https://github.com/apple/swift-nio.git", - "state": { - "branch": null, - "revision": "bc4c55b9f9584f09eb971d67d956e28d08caa9d0", - "version": "2.43.1" - } - }, - { - "package": "swift-nio-extras", - "repositoryURL": "https://github.com/apple/swift-nio-extras.git", - "state": { - "branch": null, - "revision": "f73ca5ee9c6806800243f1ac415fcf82de9a4c91", - "version": "1.10.2" - } - }, - { - "package": "swift-nio-http2", - "repositoryURL": "https://github.com/apple/swift-nio-http2.git", - "state": { - "branch": null, - "revision": "00576e6f1efa5c46dca2ca3081dc56dd233b402d", - "version": "1.23.0" - } - }, - { - "package": "swift-nio-ssl", - "repositoryURL": "https://github.com/apple/swift-nio-ssl.git", - "state": { - "branch": null, - "revision": "52a486ff6de9bc3e26bf634c5413c41c5fa89ca5", - "version": "2.17.2" - } - }, - { - "package": "swift-nio-transport-services", - "repositoryURL": "https://github.com/apple/swift-nio-transport-services.git", - "state": { - "branch": null, - "revision": "b6e37a0d442745760d6ed0195d8f283d3ce0414a", - "version": "1.14.1" - } - }, - { - "package": "swift-numerics", - "repositoryURL": "https://github.com/apple/swift-numerics", - "state": { - "branch": null, - "revision": "0a5bc04095a675662cf24757cc0640aa2204253b", - "version": "1.0.2" - } - }, - { - "package": "SwiftProtobuf", - "repositoryURL": "https://github.com/apple/swift-protobuf.git", - "state": { - "branch": null, - "revision": "0279688c9fc5a40028e1b5bb0cb56534a45a6020", - "version": "1.12.0" - } - }, - { - "package": "swift-system", - "repositoryURL": "https://github.com/apple/swift-system.git", - "state": { - "branch": null, - "revision": "836bc4557b74fe6d2660218d56e3ce96aff76574", - "version": "1.1.1" - } - }, - { - "package": "swift-tools-support-core", - "repositoryURL": "https://github.com/apple/swift-tools-support-core.git", - "state": { - "branch": null, - "revision": "4f07be3dc201f6e2ee85b6942d0c220a16926811", - "version": "0.2.7" - } - }, - { - "package": "vapor", - "repositoryURL": "https://github.com/vapor/vapor.git", - "state": { - "branch": null, - "revision": "dda0de537e7906414dccd551e77095be1e34e3da", - "version": "4.65.2" - } - }, - { - "package": "websocket-kit", - "repositoryURL": "https://github.com/vapor/websocket-kit.git", - "state": { - "branch": null, - "revision": "b0736014be634475dac4c23843811257d86dcdc1", - "version": "2.1.1" - } - }, - { - "package": "XCLogParser", - "repositoryURL": "https://github.com/MobileNativeFoundation/XCLogParser", - "state": { - "branch": null, - "revision": "2c4a36f6e8975585f87b664a4df7c38b3d7f71d7", - "version": "0.2.35" - } - }, - { - "package": "Yams", - "repositoryURL": "https://github.com/jpsim/Yams.git", - "state": { - "branch": null, - "revision": "81a65c4069c28011ee432f2858ba0de49b086677", - "version": "3.0.1" - } - } - ] - }, - "version": 1 + "pins" : [ + { + "identity" : "async-http-client", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-server/async-http-client.git", + "state" : { + "revision" : "fc510a39cff61b849bf5cdff17eb2bd6d0777b49", + "version" : "1.11.5" + } + }, + { + "identity" : "async-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/async-kit.git", + "state" : { + "revision" : "c3329e444bafbb12d1d312af9191be95348a8175", + "version" : "1.13.0" + } + }, + { + "identity" : "aws-sdk-swift-core", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-aws/aws-sdk-swift-core.git", + "state" : { + "revision" : "13738adc1603e4b50ae6aa3f758fc44f51e46aa3", + "version" : "4.5.1" + } + }, + { + "identity" : "console-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/console-kit.git", + "state" : { + "revision" : "7cf8185ad62d50ae9777ce78bcfde8f5c9f900e2", + "version" : "4.2.1" + } + }, + { + "identity" : "cryptoswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", + "state" : { + "revision" : "e2bc81be54d71d566a52ca17c3983d141c30aa70", + "version" : "1.3.3" + } + }, + { + "identity" : "fluent", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/fluent.git", + "state" : { + "revision" : "26c446002f03c5ab34b20d86873014ef3d92d0da", + "version" : "4.5.0" + } + }, + { + "identity" : "fluent-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/fluent-kit.git", + "state" : { + "revision" : "38670d2eefcba27530272946d627ac8d4e45f017", + "version" : "1.35.1" + } + }, + { + "identity" : "fluent-postgres-driver", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/fluent-postgres-driver.git", + "state" : { + "revision" : "a8b2839ea86c44a35c17f66eb0885f9e5b51a531", + "version" : "2.4.0" + } + }, + { + "identity" : "google-cloud-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor-community/google-cloud-kit.git", + "state" : { + "revision" : "100c049449634db059b539a58467dff37450398e", + "version" : "1.0.0-rc.3" + } + }, + { + "identity" : "grpc-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/grpc/grpc-swift.git", + "state" : { + "revision" : "be70633c91d722496e5fcb225f822edbd5c36a5a", + "version" : "1.0.0-alpha.9" + } + }, + { + "identity" : "gzipswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/1024jp/GzipSwift", + "state" : { + "revision" : "ba0b6cb51cc6202f896e469b87d2889a46b10d1b", + "version" : "5.1.1" + } + }, + { + "identity" : "hypertextapplicationlanguage", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-aws/HypertextApplicationLanguage.git", + "state" : { + "revision" : "aa2c9141d491682f17b2310aed17b9adfc006256", + "version" : "1.1.1" + } + }, + { + "identity" : "jwt-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/jwt-kit.git", + "state" : { + "revision" : "6055fe8439769aa3646a3c797d573ce7305849c8", + "version" : "4.2.0" + } + }, + { + "identity" : "mobius.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Spotify/Mobius.swift", + "state" : { + "revision" : "afe23c2a66ea1fd52fb9fe76fa051d9a7b789845", + "version" : "0.3.0" + } + }, + { + "identity" : "multipart-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/multipart-kit.git", + "state" : { + "revision" : "2dd9368a3c9580792b77c7ef364f3735909d9996", + "version" : "4.5.1" + } + }, + { + "identity" : "nimble", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Quick/Nimble", + "state" : { + "revision" : "7a46a5fc86cb917f69e3daf79fcb045283d8f008", + "version" : "8.1.2" + } + }, + { + "identity" : "pathkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kylef/PathKit.git", + "state" : { + "revision" : "3bfd2737b700b9a36565a8c94f4ad2b050a5e574", + "version" : "1.0.1" + } + }, + { + "identity" : "perfect-iniparser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-aws/Perfect-INIParser.git", + "state" : { + "revision" : "42de0efc7a01105e19b80d533d3d282a98277f6c", + "version" : "3.0.3" + } + }, + { + "identity" : "postgres-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/postgres-kit.git", + "state" : { + "revision" : "e97975309073e05d408749ccc1356076e4fdc22a", + "version" : "2.8.2" + } + }, + { + "identity" : "postgres-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/postgres-nio.git", + "state" : { + "revision" : "d648c5b4594ffbc2f6173318f70f5531e05ccb4e", + "version" : "1.11.0" + } + }, + { + "identity" : "queues", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/queues.git", + "state" : { + "revision" : "9418af49ca3ca779c2fab7aa0cedecb1aa6779b6", + "version" : "1.5.1" + } + }, + { + "identity" : "queues-redis-driver", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/queues-redis-driver.git", + "state" : { + "revision" : "04306b81ef25b3bc42d9634c7c657b3eb498ed0e", + "version" : "1.0.0" + } + }, + { + "identity" : "quick", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Quick/Quick", + "state" : { + "revision" : "09b3becb37cb2163919a3842a4c5fa6ec7130792", + "version" : "2.2.1" + } + }, + { + "identity" : "redis", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/redis.git", + "state" : { + "revision" : "00fdd687ec56468a3e21204ac0a9b6337d7e79ed", + "version" : "4.0.0" + } + }, + { + "identity" : "redistack", + "kind" : "remoteSourceControl", + "location" : "https://gitlab.com/mordil/RediStack.git", + "state" : { + "revision" : "b2367ac33eb8632011c1ec7afff12307838a4dab", + "version" : "1.1.0" + } + }, + { + "identity" : "routing-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/routing-kit.git", + "state" : { + "revision" : "ffac7b3a127ce1e85fb232f1a6271164628809ad", + "version" : "4.6.0" + } + }, + { + "identity" : "soto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/soto-project/soto.git", + "state" : { + "revision" : "803ab6a86a3c90e1405afb8fd6a131ec9b9ec64a", + "version" : "4.6.0" + } + }, + { + "identity" : "spectre", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kylef/Spectre.git", + "state" : { + "revision" : "26cc5e9ae0947092c7139ef7ba612e34646086c7", + "version" : "0.10.1" + } + }, + { + "identity" : "sql-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/sql-kit.git", + "state" : { + "revision" : "3c5413a229bc2abc962dab17ea66d25e448ad344", + "version" : "3.21.0" + } + }, + { + "identity" : "swift-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-algorithms.git", + "state" : { + "revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e", + "version" : "1.0.0" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser", + "state" : { + "revision" : "fddd1c00396eed152c45a46bea9f47b98e59301d", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe", + "version" : "1.0.2" + } + }, + { + "identity" : "swift-backtrace", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-server/swift-backtrace.git", + "state" : { + "revision" : "f2fd8c4845a123419c348e0bc4b3839c414077d5", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "f504716c27d2e5d4144fa4794b12129301d17729", + "version" : "1.0.3" + } + }, + { + "identity" : "swift-crypto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-crypto.git", + "state" : { + "revision" : "afe4c9b5f65b612a2bd4b1cb5ac70eb5841f278e", + "version" : "1.1.0" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c", + "version" : "1.4.4" + } + }, + { + "identity" : "swift-metrics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-metrics.git", + "state" : { + "revision" : "708b960b4605abb20bc55d65abf6bad607252200", + "version" : "2.0.0" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "bc4c55b9f9584f09eb971d67d956e28d08caa9d0", + "version" : "2.43.1" + } + }, + { + "identity" : "swift-nio-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-extras.git", + "state" : { + "revision" : "f73ca5ee9c6806800243f1ac415fcf82de9a4c91", + "version" : "1.10.2" + } + }, + { + "identity" : "swift-nio-http2", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-http2.git", + "state" : { + "revision" : "00576e6f1efa5c46dca2ca3081dc56dd233b402d", + "version" : "1.23.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "52a486ff6de9bc3e26bf634c5413c41c5fa89ca5", + "version" : "2.17.2" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "b6e37a0d442745760d6ed0195d8f283d3ce0414a", + "version" : "1.14.1" + } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics", + "state" : { + "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", + "version" : "1.0.2" + } + }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "0279688c9fc5a40028e1b5bb0cb56534a45a6020", + "version" : "1.12.0" + } + }, + { + "identity" : "swift-system", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-system.git", + "state" : { + "revision" : "836bc4557b74fe6d2660218d56e3ce96aff76574", + "version" : "1.1.1" + } + }, + { + "identity" : "swift-tools-support-core", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-tools-support-core.git", + "state" : { + "revision" : "4f07be3dc201f6e2ee85b6942d0c220a16926811", + "version" : "0.2.7" + } + }, + { + "identity" : "vapor", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/vapor.git", + "state" : { + "revision" : "dda0de537e7906414dccd551e77095be1e34e3da", + "version" : "4.65.2" + } + }, + { + "identity" : "websocket-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/websocket-kit.git", + "state" : { + "revision" : "b0736014be634475dac4c23843811257d86dcdc1", + "version" : "2.1.1" + } + }, + { + "identity" : "xclogparser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/MobileNativeFoundation/XCLogParser", + "state" : { + "revision" : "e536e3009d391513a791e08b991d6fe413be0f9c", + "version" : "0.2.38" + } + }, + { + "identity" : "yams", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/Yams.git", + "state" : { + "revision" : "81a65c4069c28011ee432f2858ba0de49b086677", + "version" : "3.0.1" + } + } + ], + "version" : 2 } diff --git a/Package.swift b/Package.swift index c394baa..3f41fe9 100644 --- a/Package.swift +++ b/Package.swift @@ -16,7 +16,7 @@ let package = Package( .library(name: "XCMetricsUtils", targets: ["XCMetricsUtils"]), ], dependencies: [ - .package(url: "https://github.com/MobileNativeFoundation/XCLogParser", from: "0.2.35"), + .package(url: "https://github.com/MobileNativeFoundation/XCLogParser", from: "0.2.38"), .package(url: "https://github.com/apple/swift-tools-support-core.git", exact: "0.2.7"), .package(url: "https://github.com/grpc/grpc-swift.git", exact: "1.0.0-alpha.9"), .package(url: "https://github.com/apple/swift-nio.git", from: "2.32.3"), From 91d2611a8d0eddd865122c6869ac0e3dcfc6fb36 Mon Sep 17 00:00:00 2001 From: Arafo Date: Sun, 19 Nov 2023 22:20:47 +0100 Subject: [PATCH 4/4] Add a new endpoint to filter build metadata Draft for issue #108 --- .../Builds/Controllers/BuildController.swift | 49 +++++++++++++++++++ .../Model/BuildMetadataFilterParams.swift | 28 +++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Sources/XCMetricsBackendLib/Builds/Model/BuildMetadataFilterParams.swift diff --git a/Sources/XCMetricsBackendLib/Builds/Controllers/BuildController.swift b/Sources/XCMetricsBackendLib/Builds/Controllers/BuildController.swift index 787b2c4..f5a7941 100644 --- a/Sources/XCMetricsBackendLib/Builds/Controllers/BuildController.swift +++ b/Sources/XCMetricsBackendLib/Builds/Controllers/BuildController.swift @@ -38,6 +38,7 @@ public struct BuildController: RouteCollection { routes.get("v1", "build", ":id", use: build) routes.get("v1", "build", use: index) routes.get("v1", "build", "step", ":day", ":id", use: targetSteps) + routes.post("v1", "build", "metadata", "filter", use: metadataFilter) } /// Endpoint that returns the paginated list of `Build` @@ -529,6 +530,54 @@ public struct BuildController: RouteCollection { .all(decoding: Step.self) } + /// Endpoint that returns the list of `BuildMetadata`s that were added to a build + /// filtered by a given key-value pair. + /// - Method: `POST` + /// - Route: `/v1/build/metadata/filter` + /// - Request body + /// + /// ``` + /// { + /// "key": "aKey", + /// "value": "value1" + /// } + /// ``` + /// + /// - Body Parameters + /// - `key`. `BuildMetadata` metadata dictionary key + /// - `value`. `BuildMetadata` metadata dictionary value + /// + /// - Response: + /// + /// ``` + /// [ + /// { + /// "metadata": { + /// "anotherKey": "42", + /// "thirdKey": "Third value", + /// "aKey": "value1" + /// }, + /// "id": "C1CDF2CE-0CC2-49C3-B8A2-481E67020CB8", + /// "day": "2020-11-02T00:00:00Z", + /// "buildIdentifier": "MyMac_0B9294B4-7E5A-4D40-91AB-5953A5075785_1" + /// }, + /// ... + /// ] + /// ``` + /// + public func metadataFilter(req: Request) throws -> EventLoopFuture<[BuildMetadata]> { + let params = try req.content.decode(BuildMetadataFilterParams.self) + guard let sql = req.db as? SQLDatabase else { + throw Abort(.internalServerError) + } + + return sql.raw(""" + SELECT * FROM \(raw: BuildMetadata.schema) + WHERE metadata ->> '\(raw: params.key)' = '\(raw: params.value)' + """) + .all(decoding: BuildMetadata.self) + } + } public struct BuildResponse: Content { diff --git a/Sources/XCMetricsBackendLib/Builds/Model/BuildMetadataFilterParams.swift b/Sources/XCMetricsBackendLib/Builds/Model/BuildMetadataFilterParams.swift new file mode 100644 index 0000000..6710c9d --- /dev/null +++ b/Sources/XCMetricsBackendLib/Builds/Model/BuildMetadataFilterParams.swift @@ -0,0 +1,28 @@ +// Copyright (c) 2020 Spotify AB. +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 Vapor + +struct BuildMetadataFilterParams: Content { + + var key: String + + var value: String +}