### Start Local Services with Docker Compose Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Starts Redis and Postgresql in detached mode using Docker Compose. This is a prerequisite for running the backend from Xcode. ```bash docker-compose up -d ``` -------------------------------- ### Start Backend from Command Line Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Launches the XCMetrics backend application from the command line using the Swift Package Manager. Assumes dependencies and migrations are set up. ```bash swift run XCMetricsBackend ``` -------------------------------- ### Additional Header JSON Example Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md This example shows how to pass additional headers, including authorization, as a JSON string to the XCMetrics executable. This can be used for custom authentication with a third-party service. ```shell XCMetrics --additionalHeaderJson '{"Api-Key":"123","Authorization":"bearer 456"}' ``` -------------------------------- ### Run Docker Compose for Local Backend Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Starts the Postgres database, Redis, and the XCMetrics backend using a provided Docker Compose file. The backend will be accessible on port 8080. ```bash docker-compose -f docker-compose-local.yml up ``` -------------------------------- ### Implement Custom Metrics Collection with Plugin Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md Example of a custom XCMetrics implementation that includes thermal throttling information collection using a plugin from XCMetricsPlugins. ```swift import Foundation import XCMetricsClient import XCMetricsPlugins public struct SPTXCMetrics { public static func main() { let metrics = XCMetrics.parseOrExit() let configuration = XCMetricsConfiguration() configuration.add(plugin: ThermalThrottlingPlugin().create()) // ThermalThrottlingPlugin lives in XCMetricsPlugins. metrics.run(with: configuration) } } ``` -------------------------------- ### Inspect XCMetrics Logs via Console Command Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md Use the `log show` command with a predicate to filter and view XCMetricsApp logs. Adjust the start time as needed. ```bash log show --start '2020-10-05 12:05:00' --info --predicate "process like 'XCMetricsApp'" ``` -------------------------------- ### Enable Scheduled Jobs for XCMetrics in Backstage Source: https://github.com/spotify/xcmetrics/blob/main/docs/Backstage Integration.md Start the XCMetrics backend with the '--scheduled' flag and set the 'XCMETRICS_SCHEDULE_STATISTICS_JOBS' environment variable to '1' to enable daily data aggregation for the Backstage plugin. Ensure only one backend instance runs these jobs to avoid data computation issues. ```bash XCMETRICS_SCHEDULE_STATISTICS_JOBS=1 ./XCMetricsBackend queues --scheduled --env production ``` -------------------------------- ### Configure Docker Compose Port Mapping Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Example of how to change the port mapping in a docker-compose.yml file to avoid port conflicts. This example remaps the host port 6500 to the container's default Redis port 6379. ```yaml ports: - "6500:6379" ``` -------------------------------- ### Open Package.swift with Xcode Source: https://github.com/spotify/xcmetrics/blob/main/README.md Use this command to open the Package.swift file in Xcode for development. ```bash xed Package.swift ``` -------------------------------- ### Create a new SPM executable package Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md Use this command to initialize a new Swift Package Manager project of type executable. ```shell swift package init --type executable ``` -------------------------------- ### Run Database Migrations with Swift CLI Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Applies database migrations to create necessary tables for the XCMetrics backend. This command is run from the command line using the Swift Package Manager. ```bash swift run XCMetricsBackend migrate ``` -------------------------------- ### Deploy Scheduled Jobs for Web UI Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Deploy the Scheduled Jobs and service configurations if you intend to use the Web UI for Backstage. ```shell kubectl create -f xcmetrics-scheduled-jobs-deployment.yaml kubectl create -f xcmetrics-scheduled-jobs-service.yaml ``` -------------------------------- ### Create XCMetrics Database and User Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Use this SQL script to create the 'xcmetrics' database, a user with encrypted password, and grant all privileges to the user on the database. ```sql CREATE DATABASE xcmetrics; CREATE USER xcmetrics WITH ENCRYPTED PASSWORD 'mypassword'; GRANT ALL PRIVILEGES ON DATABASE xcmetrics to xcmetrics; ``` -------------------------------- ### Force Post-Action Scheme on Build Failure Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md Add `runPostActionsOnFailure = "YES"` to the `BuildAction` tag in your `.xcscheme` file to ensure post-actions execute even if the build fails. ```xml ``` -------------------------------- ### Xcode Post-Build Action Script Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md This script is added to the post-actions of an Xcode build scheme. It launches the XCMetrics executable in the background to collect and send build metrics. Ensure build settings are provided to the post-action scheme. ```shell ${SRCROOT}/../../XCMetricsLauncher ${SRCROOT}/../../.build/release/XCMetrics --name BasicApp --buildDir ${BUILD_DIR} --serviceURL https://yourservice.com/v1/metrics ``` -------------------------------- ### Deploy MultiInstance XCMetrics Jobs Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md For MultiInstance deployments, deploy the XCMetrics Jobs and service configurations. ```shell kubectl create -f xcmetrics-jobs-deployment.yaml kubectl create -f xcmetrics-jobs-service.yaml ``` -------------------------------- ### List Deployed Kubernetes Services Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Run this command to list all services deployed in the Kubernetes cluster and check the External IP for the XCMetrics backend. ```shell kubectl get services ``` -------------------------------- ### Deploy Redis Artifacts Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Deploy the Redis deployment and service configurations to your Kubernetes cluster. ```shell kubectl create -f xcmetrics-redis-deployment.yaml kubectl create -f xcmetrics-redis-service.yaml ``` -------------------------------- ### Configure Xcode PostAction for Cloud Run Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Update your Xcode's PostAction script to point the XCMetrics client to the `metrics-sync` endpoint on your deployed Cloud Run service. Ensure the serviceURL correctly points to your Cloud Run endpoint. ```shell ${SRCROOT}/../../XCMetricsLauncher ${SRCROOT}/../../.build/release/XCMetrics --name BasicApp --buildDir ${BUILD_DIR} --serviceURL https://yourservice.com/v1/metrics-sync ``` -------------------------------- ### Initialize Slideshow Source: https://github.com/spotify/xcmetrics/blob/main/microsite/index.html This JavaScript code initializes a slideshow functionality for displaying screenshots. It sets up automatic sliding at a 3-second interval. ```javascript var currentSlide = 0; function slideShow() { var slides = document.getElementsByClassName("screenshot"); for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } slides[currentSlide].style.display = "block"; currentSlide = ((currentSlide + 1) % slides.length); setTimeout(slideShow, 3000); } slideShow(); ``` -------------------------------- ### Update xcmetrics-deployment.yaml for Cloud SQL Proxy Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Modify the xcmetrics-deployment.yaml file to configure the Cloud SQL Proxy. Replace 'Replace with your Cloud SQL connection string' with your actual Cloud SQL connection string. ```yaml command: ["/cloud_sql_proxy", "-instances=Replace with your Cloud SQL connection string=tcp:5432", "-credential_file=/secrets/service_account.json"] ``` -------------------------------- ### Deploy XCMetrics Artifacts Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Deploy the main XCMetrics application deployment and service configurations to your Kubernetes cluster. ```shell kubectl create -f xcmetrics-deployment.yaml kubectl create -f xcmetrics-service.yaml ``` -------------------------------- ### Find and Kill XCMetricsBackend Process Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Locates and terminates a running XCMetricsBackend process, typically used when the backend fails to stop cleanly and causes an 'Address already in use' error. It involves listing processes and then using the 'kill' command with the process ID (PID). ```bash ps -ax | grep -i XCMetricsBackend ``` ```bash kill -9 86981 ``` -------------------------------- ### Configure kubectl for GKE Cluster Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Configure kubectl to connect to your newly created GKE cluster. Replace 'name-of-cluster' with your actual cluster name. ```shell gcloud container clusters get-credentials name-of-cluster ``` -------------------------------- ### Verify Backend Health Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Checks if the XCMetrics backend is running and accessible by sending a HEAD request to the /hello endpoint. Assumes the backend is running on port 8080. ```bash curl -I http://localhost:8080/hello ``` -------------------------------- ### Compile XCMetrics Executable Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md Compile the XCMetrics executable in release mode using Swift Package Manager. The executable will be located in the .build/release/XCMetrics directory. ```shell swift build --product XCMetrics -c release ``` -------------------------------- ### Add XCMetrics Dependency to Package.swift Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md Modify your Package.swift file to include XCMetrics as a dependency and define your custom target. ```swift // swift-tools-version:5.2 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "client", platforms: [ .macOS(.v10_15), ], products: [ .executable(name: "SPTXCMetrics", targets: ["SPTXCMetricsApp"]), ], dependencies: [ .package(url: "https://github.com/spotify/XCMetrics", from: "0.1.0"), ], targets: [ .target( name: "SPTXCMetrics", dependencies: [.product(name: "XCMetricsClient", package: "XCMetrics")]), .target( name: "SPTXCMetricsApp", dependencies: ["SPTXCMetrics"] ), .testTarget( name: "SPTXCMetricsTests", dependencies: ["SPTXCMetrics"]) ] ) ``` -------------------------------- ### Create Kubernetes Secret for Database Password Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Create a Kubernetes secret to securely store your database password. Replace 'database password' with your actual password. ```shell kubectl create secret generic db-secret \ --from-literal=password='database password' ``` -------------------------------- ### Verify XCMetrics Backend API Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Use curl to test the XCMetrics backend API endpoint and ensure it returns a successful response. ```shell curl -i http://35.187.83.38/v1/build HTTP/1.1 200 OK content-type: application/json; charset=utf-8 content-length: 53 connection: keep-alive date: Wed, 14 Oct 2020 17:48:00 GMT {"metadata":{"total":0,"page":1,"per":10},"items":[]} ``` -------------------------------- ### Create Kubernetes Secret for Service Account Source: https://github.com/spotify/xcmetrics/blob/main/docs/How to Deploy Backend.md Create a Kubernetes secret to store your Google Cloud service account credentials JSON file. Ensure the path to your credentials file is correct. ```shell kubectl create secret generic google-service-account \ --from-file=service_account.json=/path/to/credentials.json ``` -------------------------------- ### Stop Local Services Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Stops the Docker instances for Redis and Postgresql when local development is finished. ```bash docker-compose stop ``` -------------------------------- ### Add XCMetricsPlugins to SPTXCMetrics Target Source: https://github.com/spotify/xcmetrics/blob/main/docs/Getting Started.md Extend the SPTXCMetrics target in Package.swift to include the XCMetricsPlugins library for additional metric collection capabilities. ```swift .target( name: "SPTXCMetrics", dependencies: [ .product(name: "XCMetricsClient", package: "XCMetrics"), .product(name: "XCMetricsPlugins", package: "XCMetrics") ] ), ``` -------------------------------- ### Restart Docker Compose for Debugging Source: https://github.com/spotify/xcmetrics/blob/main/docs/Run the Backend Locally.md Stops existing Docker instances and then restarts them without the detached flag to view command output. This is useful for diagnosing 'Connection reset error' issues. ```bash docker-compose stop ``` ```bash docker-compose up ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.