├── .github └── workflows │ └── build.yml ├── Dockerfile ├── LICENSE ├── README.md ├── bin └── build.sh ├── cmd └── promswarmconnect │ ├── dockerdiscovery.go │ ├── dummyservercert.go │ ├── main.go │ ├── metricsendpointparser.go │ ├── metricsendpointparser_test.go │ ├── tritonadapter.go │ └── tritonadapter_test.go ├── docs ├── architecture.png ├── architecture.xml └── security.md ├── go.mod ├── go.sum └── turbobob.json /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: Build 11 | run: | 12 | curl --fail --location --silent --output bob https://function61.com/go/turbobob-latest-linux-amd64 && chmod +x bob 13 | CI_REVISION_ID="$GITHUB_SHA" ./bob build --publish-artefacts 14 | # unfortunately there doesn't seem to be a way to "expose all secrets", so you must 15 | # list here each secret to pass on to the build 16 | env: 17 | DOCKER_CREDS: ${{ secrets.DOCKER_CREDS }} 18 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | 3 | CMD ["/promswarmconnect"] 4 | 5 | ADD rel/promswarmconnect_linux-amd64 /promswarmconnect 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Build status](https://github.com/function61/promswarmconnect/workflows/Build/badge.svg) 2 | [![Download](https://img.shields.io/docker/pulls/fn61/promswarmconnect.svg?style=for-the-badge)](https://hub.docker.com/r/fn61/promswarmconnect/) 3 | 4 | 5 | > [!WARNING] 6 | > [Prometheus recently added native Swarm support](https://prometheus.io/docs/guides/dockerswarm/) (therefore this project might be considered unnecessary) 7 | > 8 | > For more details see [Issue #14](https://github.com/function61/promswarmconnect/issues/14) 9 | 10 | 11 | What? 12 | ----- 13 | 14 | Syncs services/tasks from Docker Swarm to Prometheus by pretending to be a Triton service 15 | discovery endpoint, which is a 16 | [built-in service discovery module](https://github.com/prometheus/prometheus/tree/master/discovery/triton) 17 | in Prometheus. 18 | 19 | Features: 20 | 21 | - Have your container metrics scraped fully automatically to Prometheus. 22 | - We don't have to make ANY changes to Prometheus (or its container) to support Docker 23 | Swarm (except configuration changes). 24 | - Supports overriding metrics endpoint (default `/metrics`) and port. 25 | - Supports clustering, so containers are discovered from all nodes. Neither Prometheus 26 | nor promswarmconnect needs to run on the Swarm manager node. 27 | * promswarmconnect needs to run on Swarm manager if you use the `docker.sock` mount option 28 | - Supports scoping Prometheus `job` label to a) container (default), b) host (think host-level 29 | metrics) or c) static string (think cluster-wide metrics). 30 | [Read more](https://github.com/function61/promswarmconnect/blob/ecc947d4aa6b29bb4595929d2bc23b1ec7bd5e9e/cmd/promswarmconnect/main.go#L173) 31 | 32 | ![](docs/architecture.png) 33 | 34 | NOTE: the drawing is for option 2). This is even simpler if you use option 1) with socket mount. 35 | 36 | 37 | How to deploy 38 | ------------- 39 | 40 | Run the image from Docker Hub (see top of README) with the configuration mentioned below. 41 | Both options mention "VERSION" version of the image. You'll find the latest version from 42 | the Docker Hub. We don't currently publish "latest" tag so the versions are immutable. 43 | 44 | You need to run promswarmconnect and Prometheus on the same network. 45 | 46 | ### Option 1: run on Swarm manager node with mounted `docker.sock` 47 | 48 | This is the easiest option, but requires you to have a placement constraint to guarantee 49 | that promswarmconnect always runs on the manager node - its Docker socket is the only API 50 | with knowledge of the whole cluster state. 51 | 52 | ```console 53 | $ docker service create \ 54 | --name promswarmconnect \ 55 | --constraint node.role==manager \ 56 | --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \ 57 | --env "DOCKER_URL=unix:///var/run/docker.sock" \ 58 | --env "NETWORK_NAME=yourNetwork" \ 59 | --network yourNetwork \ 60 | "fn61/promswarmconnect:VERSION" 61 | ``` 62 | 63 | NOTE: `unix:..` contains three forward slashes! 64 | 65 | 66 | ### Option 2: run on any node by having Docker's socket exposed over HTTPS 67 | 68 | This may be useful to you if you have other needs that also require you to expose Docker's 69 | port. For example I'm running [Portainer](https://www.portainer.io/) on my own computer 70 | and that needs to dial to Docker's socket over TLS from the outside world. 71 | 72 | Docker's socket needs to be exposed over HTTPS with a client cert authentication. We use 73 | [dockersockproxy](https://github.com/function61/dockersockproxy) for this. You can do the 74 | same with just pure Docker (expose the API over HTTPS) configuration, but I found it much 75 | easier to not mess with default Docker settings, and to do this by just deploying a container. 76 | 77 | Below configuration `DOCKER_CLIENTCERT` (and its key) refers to the client cert that is allowed to 78 | connect to the Docker socket over HTTPS. They can be encoded to base64 like this: 79 | 80 | - `$ cat cert.pem | base64 -w 0` 81 | - `$ cat cert.key | base64 -w 0` 82 | 83 | ```console 84 | $ docker service create \ 85 | --name promswarmconnect \ 86 | --env "DOCKER_URL=https://dockersockproxy:4431" \ 87 | --env "DOCKER_CLIENTCERT=..." \ 88 | --env "DOCKER_CLIENTCERT_KEY=..." \ 89 | --env "NETWORK_NAME=yourNetwork" \ 90 | --network yourNetwork \ 91 | "fn61/promswarmconnect:VERSION" 92 | ``` 93 | 94 | Obviously, you need to replace URL and port with your Docker socket's details. 95 | 96 | ### Verify that it's working 97 | 98 | Before moving on to configure Prometheus, verify that promswarmconnect is working. 99 | 100 | Grab an Alpine container (on the same network), and verify that you can `$ curl` the API: 101 | 102 | ```console 103 | $ docker run --rm -it --network yourNetwork alpine sh 104 | $ apk add curl 105 | $ curl -k https://promswarmconnect/v1/discover 106 | { 107 | "containers": [ 108 | { 109 | "server_uuid": "/metrics", 110 | "vm_alias": "10.0.1.7:8081", 111 | "vm_brand": "http", 112 | "vm_image_uuid": "traefik_traefik", 113 | "vm_uuid": "rsvltiqm6nbcj72ibi7bess0w" 114 | }, 115 | { 116 | "server_uuid": "/metrics", <-- __metrics_path__ 117 | "vm_alias": "10.0.1.15:80", <-- __address__ 118 | "vm_brand": "http", <-- __scheme__ 119 | "vm_image_uuid": "hellohttp_hellohttp", <-- job (Docker service name) 120 | "vm_uuid": "p44b6yr05ucmhpl0teiadq3jt" <-- instance (Docker task ID) 121 | } 122 | ] 123 | } 124 | ``` 125 | 126 | [More info here](https://github.com/function61/promswarmconnect/blob/ecc947d4aa6b29bb4595929d2bc23b1ec7bd5e9e/cmd/promswarmconnect/main.go#L207) 127 | on why the JSON keys are so different W.R.T. Prometheus labels they'll be relabeled at 128 | (see also our config example). 129 | 130 | 131 | Running in a swarm via docker-compose 132 | ---------------------------------------- 133 | 134 | You can launch promswarmconnect via docker-compose, an entry would look similar to the below for the promswarmconnect container. 135 | ```yaml 136 | promswarmconnect: 137 | image: fn61/promswarmconnect:20190126_1620_7b450c47 138 | volumes: 139 | - /var/run/docker.sock:/var/run/docker.sock 140 | environment: 141 | - DOCKER_URL=unix:///var/run/docker.sock 142 | - NETWORK_NAME= 143 | deploy: 144 | placement: 145 | constraints: [node.role == manager] 146 | 147 | ``` 148 | 149 | Then for each service you wish to monitor metrics for, add an environment var as noted above in this readme, for example: 150 | ```yaml 151 | nats_monitoring: 152 | image: ainsey11/nats_prometheus_exporter 153 | environment: 154 | - METRICS_ENDPOINT=:7777/metrics 155 | ports: 156 | - 7777:7777 157 | command: ["-varz", "-connz", "-routez", "-subz", "http://nats:8222"] 158 | 159 | ``` 160 | 161 | Exporting per node metrics via multiple containers in a service 162 | -------------------------------------------------------------- 163 | 164 | The prime use case of this is when running something like node_exporter, or cAdvisor as a service with a global constraint 165 | basically, each docker host will have a cAdvisor container running, the problem with this is that by default promswarmconnect doesn't return by default, the hostname of the host the container is on 166 | this makes it difficult to differentiate which container is which when the data is surfaced into prometheus itself, 167 | 168 | as described in Issue Number 4, you can edit the environment variable of the container you wish to autodiscover, as follows: 169 | ``` METRICS_ENDPOINT=/metrics,instance=_HOSTNAME_ ``` 170 | 171 | this will then return a value similar to: 172 | 173 | ```json 174 | { 175 | "server_uuid": "/metrics", 176 | "vm_alias": "10.0.3.86:8080", 177 | "vm_brand": "http", 178 | "vm_image_uuid": "test_stack1_cadvisor", 179 | "vm_uuid": "nc-docker-1" 180 | }, 181 | 182 | ``` 183 | 184 | 185 | Configuring Prometheus 186 | ---------------------- 187 | 188 | Configure your Prometheus: 189 | [example configuration that works for us](https://github.com/function61/prometheus-conf/blob/e5c70f03674a87f1b1ffed9555f8386a7a84b758/prometheus.yml#L14). 190 | 191 | **The relabeling steps are really important** 192 | 193 | The `endpoint` needs to be your service name in Docker that you use to run promswarmconnect. 194 | 195 | Pro-tip: you could probably use 196 | [our Prometheus image](https://github.com/function61/prometheus-conf) (check the Docker 197 | Hub link) as-is, if not for production but at least to check out if this concept works for 198 | you! 199 | 200 | 201 | Considerations for running containers 202 | ------------------------------------- 203 | 204 | promswarmconnect only picks up containers whose *service-level ENV vars* specify 205 | `METRICS_ENDPOINT=/metrics`. To use non-80 port, specify `METRICS_ENDPOINT=:8080/metrics`. 206 | The metrics path is also configurable, obviously. 207 | 208 | For a complete demo with dummy application, deploy: 209 | 210 | - promswarmconnect (instructions were at this document) 211 | - our prometheus image (instructions were at above pro-tip) and 212 | - [hellohttp](https://github.com/joonas-fi/hellohttp) (it has built-in Prometheus metrics) 213 | 214 | 215 | FAQ 216 | --- 217 | 218 | > Can I read `DOCKER_CLIENTCERT` or `DOCKER_CLIENTCERT_KEY` from file or use Docker secrets? 219 | 220 | Yes, see [#10](https://github.com/function61/promswarmconnect/issues/10) 221 | 222 | > TLS? 223 | 224 | See [#12](https://github.com/function61/promswarmconnect/issues/12#issuecomment-664344435) 225 | 226 | 227 | How to build & develop 228 | ---------------------- 229 | 230 | [How to build & develop](https://github.com/function61/turbobob/blob/master/docs/external-how-to-build-and-dev.md) 231 | (with Turbo Bob, our build tool). It's easy and simple! 232 | 233 | 234 | Alternatives & links 235 | -------------------- 236 | 237 | - https://github.com/ContainerSolutions/prometheus-swarm-discovery 238 | - https://github.com/prometheus/prometheus/issues/1766 239 | - https://github.com/jmendiara/prometheus-swarm-discovery 240 | -------------------------------------------------------------------------------- /bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eu 2 | 3 | source /build-common.sh 4 | 5 | COMPILE_IN_DIRECTORY="cmd/promswarmconnect" 6 | BINARY_NAME="promswarmconnect" 7 | 8 | standardBuildProcess 9 | -------------------------------------------------------------------------------- /cmd/promswarmconnect/dockerdiscovery.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net" 7 | "net/http" 8 | 9 | "github.com/function61/gokit/app/udocker" 10 | "github.com/function61/gokit/net/http/ezhttp" 11 | "github.com/function61/gokit/os/osutil" 12 | ) 13 | 14 | func listDockerServiceAndContainerInstances( 15 | ctx context.Context, 16 | dockerUrl string, 17 | networkName string, 18 | dockerClient *http.Client, 19 | ) ([]Service, error) { 20 | services, err := listDockerServiceInstances(ctx, dockerUrl, networkName, dockerClient) 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | containersAsServices, err := listDockerContainerInstances(ctx, dockerUrl, networkName, dockerClient) 26 | if err != nil { 27 | return nil, err 28 | } 29 | 30 | return append(services, containersAsServices...), nil 31 | } 32 | 33 | func listDockerServiceInstances( 34 | ctx context.Context, 35 | dockerUrl string, 36 | networkName string, 37 | dockerClient *http.Client, 38 | ) ([]Service, error) { 39 | // all the requests have to finish within this timeout 40 | ctx, cancel := context.WithTimeout(ctx, ezhttp.DefaultTimeout10s) 41 | defer cancel() 42 | 43 | dockerTasks := []udocker.Task{} 44 | if _, err := ezhttp.Get( 45 | ctx, 46 | dockerUrl+udocker.TasksEndpoint, 47 | ezhttp.Client(dockerClient), 48 | ezhttp.RespondsJsonAllowUnknownFields(&dockerTasks), 49 | ); err != nil { 50 | return nil, err 51 | } 52 | 53 | dockerServices := []udocker.Service{} 54 | if _, err := ezhttp.Get( 55 | ctx, 56 | dockerUrl+udocker.ServicesEndpoint, 57 | ezhttp.Client(dockerClient), 58 | ezhttp.RespondsJsonAllowUnknownFields(&dockerServices), 59 | ); err != nil { 60 | return nil, err 61 | } 62 | 63 | dockerNodes := []udocker.Node{} 64 | if _, err := ezhttp.Get( 65 | ctx, 66 | dockerUrl+udocker.NodesEndpoint, 67 | ezhttp.Client(dockerClient), 68 | ezhttp.RespondsJsonAllowUnknownFields(&dockerNodes), 69 | ); err != nil { 70 | return nil, err 71 | } 72 | 73 | services := []Service{} 74 | 75 | for _, dockerService := range dockerServices { 76 | instances := []ServiceInstance{} 77 | 78 | for _, task := range dockerTasks { 79 | if task.ServiceID != dockerService.ID { 80 | continue 81 | } 82 | 83 | // task is not allocated to run on an explicit node yet, skip it since 84 | // our context is discovering running containers. 85 | if task.NodeID == "" { 86 | continue 87 | } 88 | 89 | node := nodeById(task.NodeID, dockerNodes) 90 | if node == nil { 91 | return nil, fmt.Errorf("node %s not found for task %s", task.NodeID, task.ID) 92 | } 93 | 94 | ip, err := func() (string, error) { 95 | if attachment := networkAttachmentForNetworkName(task, networkName); attachment != nil && len(attachment.Addresses) > 0 { 96 | // for some reason Docker insists on stuffing the CIDR after the IP 97 | firstIp, _, err := net.ParseCIDR(attachment.Addresses[0]) 98 | if err != nil { 99 | return "", err 100 | } 101 | 102 | return firstIp.String(), nil 103 | } 104 | 105 | // fallback for host networking 106 | if hostAttachment := networkAttachmentForNetworkName(task, "host"); hostAttachment != nil && node.Status.Addr != "" { 107 | return node.Status.Addr, nil 108 | } 109 | 110 | return "", nil 111 | }() 112 | if err != nil { 113 | return nil, err 114 | } 115 | 116 | if ip == "" { // failed to find address for the task 117 | continue 118 | } 119 | 120 | instances = append(instances, ServiceInstance{ 121 | DockerTaskId: task.ID, 122 | NodeID: node.ID, 123 | NodeHostname: node.Description.Hostname, 124 | IPv4: ip, 125 | }) 126 | } 127 | 128 | envs := map[string]string{} 129 | 130 | for _, envSerialized := range dockerService.Spec.TaskTemplate.ContainerSpec.Env { 131 | envKey, envVal := osutil.ParseEnv(envSerialized) 132 | if envKey != "" { 133 | envs[envKey] = envVal 134 | } 135 | } 136 | 137 | services = append(services, Service{ 138 | Name: dockerService.Spec.Name, 139 | Image: dockerService.Spec.TaskTemplate.ContainerSpec.Image, 140 | ENVs: envs, 141 | Instances: instances, 142 | }) 143 | } 144 | 145 | return services, nil 146 | } 147 | 148 | func listDockerContainerInstances( 149 | ctx context.Context, 150 | dockerUrl string, 151 | networkName string, 152 | dockerClient *http.Client, 153 | ) ([]Service, error) { 154 | services := []Service{} 155 | 156 | containers := []udocker.ContainerListItem{} 157 | if _, err := ezhttp.Get( 158 | ctx, 159 | dockerUrl+udocker.ListContainersEndpoint, 160 | ezhttp.Client(dockerClient), 161 | ezhttp.RespondsJsonAllowUnknownFields(&containers), 162 | ); err != nil { 163 | return nil, err 164 | } 165 | 166 | for _, container := range containers { 167 | if len(container.Names) == 0 { 168 | continue 169 | } 170 | 171 | // these are already handled by more specific handler 172 | if _, isSwarmService := container.Labels[udocker.SwarmServiceNameLabelKey]; isSwarmService { 173 | continue 174 | } 175 | 176 | ipAddress := "" 177 | if settings, found := container.NetworkSettings.Networks[networkName]; found { 178 | ipAddress = settings.IPAddress // prefer IP from the asked networkName 179 | } 180 | 181 | if settings, found := container.NetworkSettings.Networks["bridge"]; ipAddress == "" && found { 182 | ipAddress = settings.IPAddress // fall back to bridge IP if not found 183 | } 184 | 185 | if ipAddress == "" { 186 | continue 187 | } 188 | 189 | serviceName := container.Names[0] 190 | if composeServiceName, has := container.Labels["com.docker.compose.service"]; has { 191 | serviceName = composeServiceName 192 | } 193 | 194 | // stupid Docker doesn't return ENV vars with ListContainers call, so let's lie that 195 | // labels are ENV vars and inch closer to our goal of being able to specify metrics 196 | // endpoint as a label (so, now labels only work for docker-compose or manually 197 | // launched containers) 198 | labelsAsEnvs := map[string]string{} 199 | for key, value := range container.Labels { 200 | labelsAsEnvs[key] = value 201 | } 202 | 203 | services = append(services, Service{ 204 | Name: serviceName, 205 | Image: container.Image, 206 | ENVs: labelsAsEnvs, 207 | Instances: []ServiceInstance{ 208 | { 209 | DockerTaskId: container.Id[0:12], // Docker ps uses 12 hexits 210 | NodeID: "dummy", 211 | NodeHostname: "dummy", 212 | IPv4: ipAddress, 213 | }, 214 | }, 215 | }) 216 | } 217 | 218 | return services, nil 219 | } 220 | 221 | func networkAttachmentForNetworkName(task udocker.Task, networkName string) *udocker.TaskNetworkAttachment { 222 | for _, attachment := range task.NetworksAttachments { 223 | if attachment.Network.Spec.Name == networkName { 224 | return &attachment 225 | } 226 | } 227 | 228 | return nil 229 | } 230 | 231 | func nodeById(id string, nodes []udocker.Node) *udocker.Node { 232 | for _, node := range nodes { 233 | if node.ID == id { 234 | return &node 235 | } 236 | } 237 | 238 | return nil 239 | } 240 | -------------------------------------------------------------------------------- /cmd/promswarmconnect/dummyservercert.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // dummy cert valid until 2028-12-18T07:57:25Z 4 | 5 | const ( 6 | dummyCert = `-----BEGIN CERTIFICATE----- 7 | MIIBpTCCASygAwIBAgIQDsTUCPYmLiljAbeoyAHYKjAKBggqhkjOPQQDAzAbMRkw 8 | FwYDVQQKExBwcm9tc3dhcm1jb25uZWN0MB4XDTE4MTIyMTA2NTcyNVoXDTI4MTIx 9 | ODA3NTcyNVowGzEZMBcGA1UEChMQcHJvbXN3YXJtY29ubmVjdDB2MBAGByqGSM49 10 | AgEGBSuBBAAiA2IABLljHLrnXRQDnr6OseBV/a4PKcHN4aQ38k/LFxYIbiFGKrj5 11 | GRyrCepMloKt5tNW6Rx3y3AYoupQ9Gs5mKEPC6zgYLPV++C8VfAeldbFYWz54Rwu 12 | O3yTgIMPqC9rwYApRqM1MDMwDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoGCCsG 13 | AQUFBwMBMAwGA1UdEwEB/wQCMAAwCgYIKoZIzj0EAwMDZwAwZAIwB0cZRz8oenm9 14 | p7VGsEvI8ZjEyp9FH/4fnWCyTqYiy5FE95rkPBpeAGddvTnfgFfOAjB9Ls6xxJNo 15 | BhdLAfTZ1VAElbsDqoBID9mpKHmsq+G+EASGGBEWpQiQz5P52KL+ryg= 16 | -----END CERTIFICATE-----` 17 | dummyCertKey = `-----BEGIN EC PRIVATE KEY----- 18 | MIGkAgEBBDArRRWPn6/SAyDjGXIzIr5Z1/EuTGcJdq05QULZk5oWJ3e9nb0TPJCr 19 | h2xXdfKux9+gBwYFK4EEACKhZANiAAS5Yxy6510UA56+jrHgVf2uDynBzeGkN/JP 20 | yxcWCG4hRiq4+RkcqwnqTJaCrebTVukcd8twGKLqUPRrOZihDwus4GCz1fvgvFXw 21 | HpXWxWFs+eEcLjt8k4CDD6gva8GAKUY= 22 | -----END EC PRIVATE KEY-----` 23 | ) 24 | -------------------------------------------------------------------------------- /cmd/promswarmconnect/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "encoding/json" 7 | "io/ioutil" 8 | "log" 9 | "net/http" 10 | "os" 11 | "strings" 12 | 13 | "github.com/function61/gokit/app/dynversion" 14 | "github.com/function61/gokit/app/udocker" 15 | "github.com/function61/gokit/log/logex" 16 | "github.com/function61/gokit/net/http/httputils" 17 | "github.com/function61/gokit/os/osutil" 18 | ) 19 | 20 | type Service struct { 21 | Name string 22 | Image string 23 | ENVs map[string]string 24 | Instances []ServiceInstance 25 | } 26 | 27 | type ServiceInstance struct { 28 | DockerTaskId string 29 | NodeID string 30 | NodeHostname string 31 | IPv4 string 32 | } 33 | 34 | func registerTritonDiscoveryApi(mux *http.ServeMux) error { 35 | networkName, err := osutil.GetenvRequired("NETWORK_NAME") 36 | if err != nil { 37 | return err 38 | } 39 | 40 | dockerUrl, err := osutil.GetenvRequired("DOCKER_URL") 41 | if err != nil { 42 | return err 43 | } 44 | 45 | dockerClient, dockerUrlTransformed, err := udocker.Client( 46 | dockerUrl, 47 | clientCertFromEnvOrFile, 48 | true) 49 | if err != nil { 50 | return err 51 | } 52 | 53 | // for unix sockets we need to fake "http://localhost" 54 | dockerUrl = dockerUrlTransformed 55 | 56 | // adapts Docker Swarm services to Prometheus by pretending to be Triton discovery service. 57 | // requires also some hacking via Prometheus config, because we're passing data in fields 58 | // in different format than Prometheus expects 59 | mux.HandleFunc("/v1/discover", func(w http.ResponseWriter, r *http.Request) { 60 | services, err := listDockerServiceAndContainerInstances( 61 | r.Context(), 62 | dockerUrl, 63 | networkName, 64 | dockerClient) 65 | if err != nil { 66 | http.Error(w, err.Error(), http.StatusInternalServerError) 67 | return 68 | } 69 | 70 | jsonResponse(w, serviceInstancesToTritonContainers(services)) 71 | }) 72 | 73 | return nil 74 | } 75 | 76 | func main() { 77 | rootLogger := logex.StandardLogger() 78 | 79 | osutil.ExitIfError(mainInternal( 80 | osutil.CancelOnInterruptOrTerminate(rootLogger), 81 | rootLogger)) 82 | } 83 | 84 | func mainInternal(ctx context.Context, logger *log.Logger) error { 85 | logl := logex.Levels(logger) 86 | 87 | mux := http.NewServeMux() 88 | 89 | if err := registerTritonDiscoveryApi(mux); err != nil { 90 | return err 91 | } 92 | 93 | serverCert, err := tls.X509KeyPair([]byte(dummyCert), []byte(dummyCertKey)) 94 | if err != nil { 95 | return err 96 | } 97 | 98 | // we need TLS even though calling Prometheus specifies InsecureSkipVerify, because 99 | // the code in Prometheus is hardcoded to use https. well, I guess encryption without 100 | // authentication is still better than no encryption at all. 101 | srv := &http.Server{ 102 | Handler: mux, 103 | Addr: ":443", 104 | TLSConfig: &tls.Config{ 105 | Certificates: []tls.Certificate{serverCert}, 106 | }, 107 | } 108 | 109 | logl.Info.Printf("Started v%s", dynversion.Version) 110 | 111 | return httputils.CancelableServer(ctx, srv, func() error { return srv.ListenAndServeTLS("", "") }) 112 | } 113 | 114 | func clientCertFromEnvOrFile() (*tls.Certificate, error) { 115 | clientCert, err := getDataFromEnvBase64OrFile("DOCKER_CLIENTCERT") 116 | if err != nil { 117 | return nil, err 118 | } 119 | 120 | clientCertKey, err := getDataFromEnvBase64OrFile("DOCKER_CLIENTCERT_KEY") 121 | if err != nil { 122 | return nil, err 123 | } 124 | 125 | clientKeypair, err := tls.X509KeyPair(clientCert, clientCertKey) 126 | if err != nil { 127 | return nil, err 128 | } 129 | 130 | return &clientKeypair, nil 131 | } 132 | 133 | // read ENV var (identified by key) value as base64, or if value begins with "@/home/foo/data.txt", 134 | // value is read from that file. this is safe because "@" is not part of base64 alphabet 135 | func getDataFromEnvBase64OrFile(key string) ([]byte, error) { 136 | if strings.HasPrefix(os.Getenv(key), "@") { 137 | path := os.Getenv(key)[1:] // remove leading "@" 138 | 139 | return ioutil.ReadFile(path) 140 | } 141 | 142 | return osutil.GetenvRequiredFromBase64(key) 143 | } 144 | 145 | func jsonResponse(w http.ResponseWriter, output interface{}) { 146 | w.Header().Set("Content-Type", "application/json") 147 | 148 | jsonEncoder := json.NewEncoder(w) 149 | jsonEncoder.SetIndent("", " ") 150 | if err := jsonEncoder.Encode(output); err != nil { 151 | // not safe to respond with HTTP error, because headers are most likely sent and 152 | // connection is probably broken 153 | log.Printf("jsonResponse: %v", err) 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /cmd/promswarmconnect/metricsendpointparser.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | type MetricsEndpoint struct { 11 | // https://prometheus.io/docs/concepts/jobs_instances/ 12 | Job string 13 | Instance string 14 | Address string // __address__ 15 | MetricsPath string // __metrics_path__ 16 | Scheme string // __scheme__ 17 | 18 | Service *Service 19 | } 20 | 21 | // parses Prometheus endpoints from Service info provided by a discovery backend 22 | 23 | func serviceToMetricsEndpoints(services []Service) []MetricsEndpoint { 24 | metricsEndpoints := []MetricsEndpoint{} 25 | 26 | for _, service := range services { 27 | // looks up METRICS_ENDPOINT, METRICS_OVERRIDE_INSTANCE 28 | foundEndpoints := processSuffix(service, "") 29 | metricsEndpoints = append(metricsEndpoints, foundEndpoints...) 30 | 31 | i := 2 32 | for { 33 | // looks up METRICS_ENDPOINT2, METRICS_OVERRIDE_INSTANCE2 etc. 34 | foundEndpoints = processSuffix(service, fmt.Sprintf("%d", i)) 35 | if len(foundEndpoints) == 0 { 36 | break 37 | } 38 | 39 | metricsEndpoints = append(metricsEndpoints, foundEndpoints...) 40 | i++ 41 | } 42 | } 43 | 44 | return metricsEndpoints 45 | } 46 | 47 | func processSuffix(service Service, suff string) []MetricsEndpoint { 48 | // don't add all services, but only those whitelisted by this explicit setting 49 | endpointSpecifierRaw, endpointSpecifierExists := service.ENVs["METRICS_ENDPOINT"+suff] 50 | if !endpointSpecifierExists { 51 | return nil 52 | } 53 | 54 | spec, err := parseEndpointSpecifier(endpointSpecifierRaw) 55 | if err != nil { 56 | panic(err) // FIXME: handle error gracefully 57 | } 58 | metricsEndpointPort := "80" 59 | if spec.port != "" { 60 | metricsEndpointPort = spec.port 61 | } 62 | 63 | /* Prometheus timeseries have two required labels for each timeseries: 64 | 65 | - job. this corresponds with a service. example: "html2pdf" 66 | - instance. there usually are multiple instances of a service (job) running 67 | 68 | Usually instance is container specific, but there are exceptions. Here are the 69 | use cases for instance label in order of popularity: 70 | 71 | 1) container scoped (default) => each container gets own timeseries 72 | - use container ID (or IP) as "instance" label 73 | 2) host scoped => each host gets own timeseries 74 | - example: host-level metrics, but exporter runs in container 75 | - use hostname (or host id) as "instance" label 76 | 3) static string => only one timeseries in whole cluster 77 | - example: cluster-wide metrics (node count for example) 78 | - use static string (e.g. "n/a") as "instance" label 79 | */ 80 | 81 | // this is used to implement cases 2) and 3). use "_HOSTNAME_" to replace with hostname 82 | // or any other string to have a static string 83 | // TODO: deprecate this over the now-smarter endpoint specifier 84 | overrideInstanceLabel := service.ENVs["METRICS_OVERRIDE_INSTANCE"+suff] // ok if not set 85 | if spec.instanceOverride != "" { 86 | overrideInstanceLabel = spec.instanceOverride 87 | } 88 | 89 | jobLabel := service.Name 90 | if spec.jobOverride != "" { 91 | jobLabel = spec.jobOverride 92 | } 93 | 94 | metricsEndpoints := []MetricsEndpoint{} 95 | 96 | scheme := func() string { 97 | if metricsEndpointPort == "443" { // FIXME: support non-default ports also.. 98 | return "https" 99 | } else { 100 | return "http" 101 | } 102 | }() 103 | 104 | for _, instance := range service.Instances { 105 | hostAndPort := instance.IPv4 + ":" + metricsEndpointPort 106 | 107 | instanceLabel := instance.DockerTaskId 108 | if overrideInstanceLabel != "" { 109 | instanceLabel = overrideInstanceLabel 110 | 111 | if instanceLabel == "_HOSTNAME_" { 112 | instanceLabel = instance.NodeHostname 113 | } 114 | } 115 | 116 | metricsEndpoints = append(metricsEndpoints, MetricsEndpoint{ 117 | Job: jobLabel, 118 | Instance: instanceLabel, 119 | Address: hostAndPort, 120 | MetricsPath: spec.path, 121 | Scheme: scheme, 122 | 123 | Service: &service, 124 | }) 125 | } 126 | 127 | return metricsEndpoints 128 | } 129 | 130 | type endpointSpecifier struct { 131 | port string 132 | path string 133 | instanceOverride string 134 | jobOverride string 135 | } 136 | 137 | // ":443/metrics" => ("443", "/metrics") 138 | // "/metrics" => ("", "/metrics") 139 | var splitPortAndPathRe = regexp.MustCompile("^(:([0-9]+))?(.+)") 140 | 141 | // parses values like: 142 | // "/metrics" 143 | // ":80/metrics,job=hellohttp,instance=fas5324df" 144 | func parseEndpointSpecifier(hostPort string) (*endpointSpecifier, error) { 145 | portions := strings.Split(hostPort, ",") 146 | 147 | hostPortParse := splitPortAndPathRe.FindStringSubmatch(portions[0]) 148 | if hostPortParse == nil { 149 | return nil, errors.New("unable to parse host:port") 150 | } 151 | 152 | spec := endpointSpecifier{ 153 | port: hostPortParse[2], 154 | path: hostPortParse[3], 155 | } 156 | 157 | for _, portion := range portions[1:] { 158 | equalsPos := strings.Index(portion, "=") 159 | if equalsPos == -1 { 160 | return nil, errors.New("portion equals sign not found") 161 | } 162 | 163 | key := portion[0:equalsPos] 164 | value := portion[equalsPos+1:] 165 | 166 | switch key { 167 | case "job": 168 | spec.jobOverride = value 169 | case "instance": 170 | spec.instanceOverride = value 171 | default: 172 | return nil, fmt.Errorf("unknown key: %s", key) 173 | } 174 | 175 | if value == "" { 176 | return nil, fmt.Errorf("empty value for key: %s", key) 177 | } 178 | } 179 | 180 | return &spec, nil 181 | } 182 | -------------------------------------------------------------------------------- /cmd/promswarmconnect/metricsendpointparser_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/function61/gokit/testing/assert" 8 | ) 9 | 10 | func TestServiceToMetricsEndpointsNo(t *testing.T) { 11 | metricsEndpointMissing := map[string]string{ 12 | "foo": "bar", // no METRICS_ENDPOINT defined => will not parse as endpoint 13 | } 14 | 15 | endpoints := serviceToMetricsEndpoints([]Service{serviceDef(metricsEndpointMissing, inst1, inst2)}) 16 | assert.Assert(t, len(endpoints) == 0) 17 | } 18 | 19 | func TestServiceToMetricsEndpoints(t *testing.T) { 20 | envs := map[string]string{ 21 | "METRICS_ENDPOINT": ":80/metrics", 22 | } 23 | 24 | endpoints := serviceToMetricsEndpoints([]Service{serviceDef(envs, inst1, inst2)}) 25 | assert.Assert(t, len(endpoints) == 2) 26 | 27 | assertEndpoint(t, endpoints[0], "job instance address<10.0.0.2:80> path") 28 | assertEndpoint(t, endpoints[1], "job instance address<10.0.0.3:80> path") 29 | } 30 | 31 | func TestServiceToMetricsEndpointsDifferentPortAndPath(t *testing.T) { 32 | envs := map[string]string{ 33 | "METRICS_ENDPOINT": ":443/foometrics", 34 | } 35 | 36 | endpoints := serviceToMetricsEndpoints([]Service{serviceDef(envs, inst1, inst2)}) 37 | assert.Assert(t, len(endpoints) == 2) 38 | 39 | assertEndpoint(t, endpoints[0], "job instance address<10.0.0.2:443> path") 40 | assertEndpoint(t, endpoints[1], "job instance address<10.0.0.3:443> path") 41 | } 42 | 43 | func TestServiceToMetricsEndpointsOverrideInstance(t *testing.T) { 44 | envs := map[string]string{ 45 | "METRICS_ENDPOINT": "/metrics", // also testing missing port => default to 80 46 | "METRICS_OVERRIDE_INSTANCE": "n/a", 47 | } 48 | 49 | endpoints := serviceToMetricsEndpoints([]Service{serviceDef(envs, inst1, inst2)}) 50 | assert.Assert(t, len(endpoints) == 2) 51 | 52 | assertEndpoint(t, endpoints[0], "job instance address<10.0.0.2:80> path") 53 | assertEndpoint(t, endpoints[1], "job instance address<10.0.0.3:80> path") 54 | } 55 | 56 | func TestServiceToMetricsEndpointsOverrideInstanceWithHostname(t *testing.T) { 57 | envs := map[string]string{ 58 | "METRICS_ENDPOINT": "/metrics", 59 | "METRICS_OVERRIDE_INSTANCE": "_HOSTNAME_", // can be used for host-level metrics 60 | } 61 | 62 | endpoints := serviceToMetricsEndpoints([]Service{serviceDef(envs, inst1)}) 63 | assert.Assert(t, len(endpoints) == 1) 64 | 65 | assertEndpoint(t, endpoints[0], "job instance address<10.0.0.2:80> path") 66 | } 67 | 68 | // V2 = use more modern specifier 69 | func TestServiceToMetricsEndpointsOverrideInstanceWithHostnameV2(t *testing.T) { 70 | envs := map[string]string{ 71 | "METRICS_ENDPOINT": "/metrics,instance=_HOSTNAME_", 72 | } 73 | 74 | endpoints := serviceToMetricsEndpoints([]Service{serviceDef(envs, inst1)}) 75 | assert.Assert(t, len(endpoints) == 1) 76 | 77 | assertEndpoint(t, endpoints[0], "job instance address<10.0.0.2:80> path") 78 | } 79 | 80 | func TestServiceToMetricsEndpointsMultipleEndpoints(t *testing.T) { 81 | envs := map[string]string{ 82 | "METRICS_ENDPOINT": "/metrics/foo,job=foo", 83 | "METRICS_ENDPOINT2": "/metrics/bar,job=bar", 84 | } 85 | 86 | endpoints := serviceToMetricsEndpoints([]Service{serviceDef(envs, inst1, inst2)}) 87 | assert.Assert(t, len(endpoints) == 4) 88 | 89 | assertEndpoint(t, endpoints[0], "job instance address<10.0.0.2:80> path") 90 | assertEndpoint(t, endpoints[1], "job instance address<10.0.0.3:80> path") 91 | assertEndpoint(t, endpoints[2], "job instance address<10.0.0.2:80> path") 92 | assertEndpoint(t, endpoints[3], "job instance address<10.0.0.3:80> path") 93 | } 94 | 95 | func TestParseEndpointSpecifier(t *testing.T) { 96 | oneSpecifier := func(t *testing.T, input string, expectedRepr string) { 97 | t.Helper() 98 | 99 | spec, err := parseEndpointSpecifier(input) 100 | var actualRepr string 101 | if err != nil { 102 | actualRepr = err.Error() 103 | } else { 104 | actualRepr = fmt.Sprintf( 105 | "path<%s> port<%s> job<%s> instance<%s>", 106 | spec.path, 107 | spec.port, 108 | spec.jobOverride, 109 | spec.instanceOverride) 110 | } 111 | 112 | assert.EqualString(t, actualRepr, expectedRepr) 113 | } 114 | 115 | oneSpecifier(t, ":80/metrics", "path port<80> job<> instance<>") 116 | oneSpecifier(t, "/metrics,job=overriddenJob", "path port<> job instance<>") 117 | oneSpecifier(t, "/metrics,instance=overriddenInstance", "path port<> job<> instance") 118 | oneSpecifier(t, "/metrics,job=hello,instance=inst1", "path port<> job instance") 119 | 120 | // failures 121 | oneSpecifier(t, "", "unable to parse host:port") 122 | oneSpecifier(t, "/metrics,foo=bar", "unknown key: foo") 123 | oneSpecifier(t, "/metrics,job=", "empty value for key: job") 124 | } 125 | 126 | func assertEndpoint(t *testing.T, endpoint MetricsEndpoint, expectedRepr string) { 127 | t.Helper() 128 | 129 | actualRepr := fmt.Sprintf( 130 | "job<%s> instance<%s> address<%s> path<%s>", 131 | endpoint.Job, 132 | endpoint.Instance, 133 | endpoint.Address, 134 | endpoint.MetricsPath) 135 | 136 | assert.EqualString(t, actualRepr, expectedRepr) 137 | } 138 | 139 | // test data 140 | var inst1 = ServiceInstance{ 141 | DockerTaskId: "task1", 142 | NodeID: "node1", 143 | NodeHostname: "node1.example.com", 144 | IPv4: "10.0.0.2", 145 | } 146 | 147 | var inst2 = ServiceInstance{ 148 | DockerTaskId: "task2", 149 | NodeID: "node1", 150 | NodeHostname: "node1.example.com", 151 | IPv4: "10.0.0.3", 152 | } 153 | 154 | func serviceDef(envs map[string]string, instances ...ServiceInstance) Service { 155 | return Service{ 156 | Name: "hellohttp", 157 | Image: "joonas/hellohttp:latest", 158 | ENVs: envs, 159 | Instances: instances, 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /cmd/promswarmconnect/tritonadapter.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // cannot reference from Prometheus sources because this was inlined 4 | type TritonDiscoveryResponseContainer struct { 5 | ServerUUID string `json:"server_uuid"` 6 | VMAlias string `json:"vm_alias"` 7 | VMBrand string `json:"vm_brand"` 8 | VMImageUUID string `json:"vm_image_uuid"` 9 | VMUUID string `json:"vm_uuid"` 10 | } 11 | 12 | type TritonDiscoveryResponse struct { 13 | Containers []TritonDiscoveryResponseContainer `json:"containers"` 14 | } 15 | 16 | func metricsEndpointToTritonResponse(endpoints []MetricsEndpoint) TritonDiscoveryResponse { 17 | containers := []TritonDiscoveryResponseContainer{} 18 | 19 | for _, endpoint := range endpoints { 20 | // these pieces of info are assigned to pretty much random keys, knowing that 21 | // we must redirect them into other/correct fields anyway by hacking with 22 | // Prometheus relabeling ("VMAlias actually means __address_" etc) configuration. 23 | // without relabeling the Triton plugin code in Prometheus requires DNS suffixes etc. 24 | containers = append(containers, TritonDiscoveryResponseContainer{ 25 | VMImageUUID: endpoint.Job, 26 | VMUUID: endpoint.Instance, 27 | VMAlias: endpoint.Address, 28 | ServerUUID: endpoint.MetricsPath, 29 | VMBrand: endpoint.Scheme, 30 | }) 31 | } 32 | 33 | return TritonDiscoveryResponse{ 34 | Containers: containers, 35 | } 36 | } 37 | 38 | func serviceInstancesToTritonContainers(services []Service) TritonDiscoveryResponse { 39 | return metricsEndpointToTritonResponse(serviceToMetricsEndpoints(services)) 40 | } 41 | -------------------------------------------------------------------------------- /cmd/promswarmconnect/tritonadapter_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/function61/gokit/testing/assert" 7 | ) 8 | 9 | func TestServiceInstancesToTritonContainers(t *testing.T) { 10 | dummySvc1WithoutProperEnvVar := Service{ 11 | Name: "hellohttp", 12 | Image: "joonas/hellohttp:latest", 13 | ENVs: map[string]string{ 14 | "foo": "bar", 15 | }, 16 | Instances: []ServiceInstance{ 17 | { 18 | DockerTaskId: "task1", 19 | NodeID: "node1", 20 | NodeHostname: "node1.example.com", 21 | IPv4: "10.0.0.2", 22 | }, 23 | }, 24 | } 25 | 26 | dummySvc2 := Service{ 27 | Name: "hellohttp", 28 | Image: "joonas/hellohttp:latest", 29 | ENVs: map[string]string{ 30 | "METRICS_ENDPOINT": ":80/metrics", 31 | }, 32 | Instances: []ServiceInstance{ 33 | { 34 | DockerTaskId: "task1", 35 | NodeID: "node1", 36 | NodeHostname: "node1.example.com", 37 | IPv4: "10.0.0.2", 38 | }, 39 | { 40 | DockerTaskId: "task2", 41 | NodeID: "node1", 42 | NodeHostname: "node1.example.com", 43 | IPv4: "10.0.0.3", 44 | }, 45 | }, 46 | } 47 | 48 | noProperEnvVarResult := serviceInstancesToTritonContainers([]Service{dummySvc1WithoutProperEnvVar}) 49 | assert.Assert(t, len(noProperEnvVarResult.Containers) == 0) 50 | 51 | assert.EqualJson(t, serviceInstancesToTritonContainers([]Service{dummySvc2}), `{ 52 | "containers": [ 53 | { 54 | "server_uuid": "/metrics", 55 | "vm_alias": "10.0.0.2:80", 56 | "vm_brand": "http", 57 | "vm_image_uuid": "hellohttp", 58 | "vm_uuid": "task1" 59 | }, 60 | { 61 | "server_uuid": "/metrics", 62 | "vm_alias": "10.0.0.3:80", 63 | "vm_brand": "http", 64 | "vm_image_uuid": "hellohttp", 65 | "vm_uuid": "task2" 66 | } 67 | ] 68 | }`) 69 | } 70 | 71 | func TestHttps(t *testing.T) { 72 | result := serviceInstancesToTritonContainers([]Service{ 73 | { 74 | Name: "hellohttp", 75 | Image: "joonas/hellohttp:latest", 76 | ENVs: map[string]string{ 77 | "METRICS_ENDPOINT": ":443/metrics", 78 | }, 79 | Instances: []ServiceInstance{ 80 | { 81 | DockerTaskId: "task1", 82 | NodeID: "node1", 83 | NodeHostname: "node1.example.com", 84 | IPv4: "10.0.0.2", 85 | }, 86 | }, 87 | }, 88 | }) 89 | 90 | assert.EqualJson(t, result, `{ 91 | "containers": [ 92 | { 93 | "server_uuid": "/metrics", 94 | "vm_alias": "10.0.0.2:443", 95 | "vm_brand": "https", 96 | "vm_image_uuid": "hellohttp", 97 | "vm_uuid": "task1" 98 | } 99 | ] 100 | }`) 101 | } 102 | -------------------------------------------------------------------------------- /docs/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/function61/promswarmconnect/8a99a26b5aac9a316a9f1724df83e94652b4cf2c/docs/architecture.png -------------------------------------------------------------------------------- /docs/architecture.xml: -------------------------------------------------------------------------------- 1 | 7Vhdb5swFP01eWyF7Tghj22afUibGimV2j5VLjjgFTAzpgn99bODCVDTpF3JUm0jUoSPr7/uucf2ZYCm8fqzIGn4nfs0GkDHXw/QxQBCd+yqfw0UBnCcEggE80sI1MCCPVEDVmY582nWMpScR5KlbdDjSUI92cKIEHzVNlvyqD1qSgJqAQuPRDZ6zXwZGhRUy9AVXygLQjO0i01FTCpjA2Qh8fmqAaHZAE0F57J8i9dTGmnfVX4p2316oXY7MUET+ZoG9PI+LZCAV+nJ5YwNn37O7+IT08sjiXKz4MWKiFhBiWLSTFwWlTcEzxOf6g6dATpfhUzSRUo8XbtS9CsslHGkSkC9PlIhmfLkWcSCRGGSawNiSp6aNhUKWLIomvKIi80QaIn1T+GZFPyBNmpGm0e34Ils4OWjcLMWNSxdv+gksHW9ClnKYypFoUxMg7Ehy0TrxBRXNfVbLGywviWZmHALtj3XjKgXQ8pbCEIWCdRXEWqKXMiQBzwh0axGz9s0NSihayZvNHyKTenWGCn/iKJRpYu3ptUPKmVhpElyyRVUj/uNa1o3duVM9fR2e1+thufCozuWDY3UiQio3GGHutkUNCKSPbbn0Ts30BKPz70HKjL1nwq+Lt6nn31K8Ql1l16nUjyX3i/7UQTAuCUJiGxNANihidGhJIEst19s3K6wavM6m3/9G30P8LF9P7R8f81F6fvywHBAz47vPkU+1KGBJr93aoDxoWjCe2mC/2lCztF5Gls8zYXuOqR5dgyC/sy2NoTwtL2xoRG2qYDYpmKCD8SEazFxJZjkiT5ULnqmog8XDtuxPOyI5c6TAR8qlCeWA9UVKM70gVzlZv9QQAM4Pj12SAN7j+8jdWgmDnWucFOZVYlDWXeE1KH6crA3d4DdnL46d9g0PROCFA2DlLNEZo2e5xpoHEKoLVzg4ibRe+2rq10dGOUM6jDZLuUdkePs3g3L+7VD41y5Sgnq422P42dyHB17ewT2vbiXPB7uSOThR8jk3VeqETjdjB5WjsNnH3yq+99LcsQO3mX/VjmqYv0BsDSvv6Ki2S8= -------------------------------------------------------------------------------- /docs/security.md: -------------------------------------------------------------------------------- 1 | Security policy 2 | =============== 3 | 4 | Supported versions 5 | ------------------ 6 | 7 | Currently, we don't support old versions of this project - security updates will only be made 8 | against the main branch (= latest version). 9 | To stay secure, always use the latest version of this project. 10 | 11 | 12 | Reporting a vulnerability 13 | ------------------------- 14 | 15 | If you think you've found a vulnerability, 16 | [responsible disclosure](https://en.wikipedia.org/wiki/Responsible_disclosure) is appreciated! 17 | Instructions are found from our company-wide policy. 18 | 19 | 20 | Company-wide policy 21 | ------------------- 22 | 23 | More details/instructions available via our company-wide policy at 24 | [function61.com/security](https://function61.com/security/) 25 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/function61/promswarmconnect 2 | 3 | go 1.13 4 | 5 | require github.com/function61/gokit v0.0.0-20210702104928-d82199d64092 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 3 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 4 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 6 | github.com/apex/gateway v1.1.1/go.mod h1:x7iPY22zu9D8sfrynawEwh1wZEO/kQTRaOM5ye02tWU= 7 | github.com/aws/aws-lambda-go v1.13.2/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= 8 | github.com/aws/aws-sdk-go v1.16.15/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= 9 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 10 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 11 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 12 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 13 | github.com/cubewise-code/go-mime v0.0.0-20190322015324-9c5316ef3e8e/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= 14 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 15 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 16 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 17 | github.com/function61/gokit v0.0.0-20200302141937-14d21ef1b462 h1:2q/9JN4YtpJK5cKHCErb8Iv5kUe5FTpa8dB3cJCaoPM= 18 | github.com/function61/gokit v0.0.0-20200302141937-14d21ef1b462/go.mod h1:f6JhYQwMbwfAX472K/2A46CKet7BrpugMzuCobtqPQo= 19 | github.com/function61/gokit v0.0.0-20200715130529-d3e870268fc9 h1:bni93qJbPc8zSrE+dYj5BctgYdx+J1o4x1+CZPbDg8U= 20 | github.com/function61/gokit v0.0.0-20200715130529-d3e870268fc9/go.mod h1:9nT4wyoyrlvYOlvTovXSmUGIx6klsr+cgqkGTw7XNgs= 21 | github.com/function61/gokit v0.0.0-20210630170103-9f51059ede2a h1:wIPKzD4JUU5YD3PplOzxg7H/pec0ta0VGSUGN4ppW/U= 22 | github.com/function61/gokit v0.0.0-20210630170103-9f51059ede2a/go.mod h1:nfJiV01CxBDMlVDv35jnAACc7vOBFGXlAZRILvTnD0E= 23 | github.com/function61/gokit v0.0.0-20210702104928-d82199d64092 h1:bl8ArJB6IF42CHR2CQUVoSlvP9i9GeHb9ipwC93QPRg= 24 | github.com/function61/gokit v0.0.0-20210702104928-d82199d64092/go.mod h1:nfJiV01CxBDMlVDv35jnAACc7vOBFGXlAZRILvTnD0E= 25 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 26 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 27 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 28 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 29 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 30 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 31 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 32 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 33 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 34 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 35 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 36 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 37 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 38 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= 39 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 40 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 41 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 42 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 43 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 44 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 45 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 46 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 47 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 48 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 49 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 50 | github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= 51 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 52 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 53 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 54 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 55 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 56 | github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= 57 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 58 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 59 | github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 60 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 61 | github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= 62 | github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= 63 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 64 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 65 | github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= 66 | github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= 67 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 68 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 69 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 70 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 71 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 72 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 73 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 74 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 75 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 76 | github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 77 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 78 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 79 | golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 80 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 81 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 82 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 83 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 84 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 85 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 86 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 87 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 88 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 89 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 90 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 91 | golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 92 | golang.org/x/sys v0.0.0-20200121082415-34d275377bf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 93 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 94 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 95 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 96 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 97 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 98 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 99 | -------------------------------------------------------------------------------- /turbobob.json: -------------------------------------------------------------------------------- 1 | { 2 | "for_description_of_this_file_see": "https://github.com/function61/turbobob", 3 | "version_major": 1, 4 | "project_name": "promswarmconnect", 5 | "builders": [ 6 | { 7 | "name": "default", 8 | "uses": "docker://fn61/buildkit-golang:20210702_0854_7adda4a2", 9 | "mount_destination": "/workspace", 10 | "workdir": "/workspace", 11 | "commands": { 12 | "build": ["bin/build.sh"], 13 | "dev": ["bash"] 14 | } 15 | } 16 | ], 17 | "docker_images": [ 18 | { 19 | "image": "fn61/promswarmconnect", 20 | "dockerfile_path": "Dockerfile", 21 | "auth_type": "creds_from_env" 22 | } 23 | ], 24 | "os_arches": { 25 | "linux-amd64": true 26 | } 27 | } 28 | --------------------------------------------------------------------------------