├── .github └── workflows │ └── go.yml ├── .gitignore ├── .jscs.json ├── .prettierrc.js ├── LICENSE ├── Makefile ├── README.md ├── ci └── jobs │ └── .gitkeep ├── go.mod ├── go.sum ├── package-lock.json ├── package.json ├── pkg ├── credentials.go ├── datasource.go ├── datasource_test.go ├── main.go └── query.go ├── src ├── README.md ├── components │ ├── ConfigEditor.tsx │ ├── QueryEditor.tsx │ └── index.ts ├── datasource.ts ├── module.ts ├── plugin.json └── types.ts └── tsconfig.json /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | on: [release] 3 | jobs: 4 | build: 5 | name: Build 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Set up Go 1.14 9 | uses: actions/setup-go@v1 10 | with: 11 | go-version: 1.14 12 | id: go 13 | 14 | - name: Use Node.js 10.x 15 | uses: actions/setup-node@v1 16 | with: 17 | node-version: 10.x 18 | 19 | - name: Check out code into the Go module directory 20 | uses: actions/checkout@v1 21 | 22 | - name: npm install, build #, and test 23 | run: | 24 | npm install 25 | npm run build --if-present 26 | #npm test 27 | 28 | - name: Build 29 | env: 30 | GO111MODULE: on 31 | run: make build 32 | 33 | - name: Package 34 | run: npx grafana-toolkit plugin:ci-package 35 | 36 | - name: Publish 37 | uses: Shopify/upload-to-release@master 38 | with: 39 | name: grafana-aws-athena-datasource-${{github.event.release.tag_name}}.zip 40 | path: ci/packages/mtanda-aws-athena-datasource-${{github.event.release.tag_name}}.zip 41 | repo-token: ${{ secrets.GITHUB_TOKEN }} 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | coverage/ 4 | .aws-config.json 5 | awsconfig 6 | /emails/dist 7 | /public_gen 8 | /tmp 9 | vendor/phantomjs/phantomjs 10 | 11 | docs/AWS_S3_BUCKET 12 | docs/GIT_BRANCH 13 | docs/VERSION 14 | docs/GITCOMMIT 15 | docs/changed-files 16 | docs/changed-files 17 | 18 | # locally required config files 19 | public/css/*.min.css 20 | 21 | # Editor junk 22 | *.sublime-workspace 23 | *.swp 24 | .idea/ 25 | *.iml 26 | 27 | /data/* 28 | /bin/* 29 | 30 | conf/custom.ini 31 | fig.yml 32 | profile.cov 33 | grafana 34 | .notouch 35 | 36 | # Test artifacts 37 | /dist/test/ 38 | -------------------------------------------------------------------------------- /.jscs.json: -------------------------------------------------------------------------------- 1 | { 2 | "esnext": true, 3 | "disallowImplicitTypeConversion": ["string"], 4 | "disallowKeywords": ["with"], 5 | "disallowMultipleLineBreaks": true, 6 | "disallowMixedSpacesAndTabs": true, 7 | "disallowTrailingWhitespace": true, 8 | "requireSpacesInFunctionExpression": { 9 | "beforeOpeningCurlyBrace": true 10 | }, 11 | "disallowSpacesInsideArrayBrackets": true, 12 | "disallowSpacesInsideParentheses": true, 13 | "validateIndentation": 2 14 | } 15 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ...require('@grafana/toolkit/src/config/prettier.plugin.config.json'), 3 | }; 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: webpack build 2 | 3 | webpack: 4 | npm run build 5 | 6 | build: 7 | GOOS=linux GOARCH=amd64 go build -o ./dist/aws-athena-plugin_linux_amd64 ./pkg 8 | GOOS=darwin GOARCH=amd64 go build -o ./dist/aws-athena-plugin_darwin_amd64 ./pkg 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grafana aws athena datasource 2 | 3 | Grafana plugin for queryng AWS Athena as data source 4 | 5 | ## Installation 6 | 7 | ```sh 8 | docker run -d --name=grafana -p 3000:3000 -e GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=mtanda-aws-athena-datasource grafana/grafana 9 | 10 | docker exec -it grafana /bin/bash 11 | # inside container 12 | grafana-cli --pluginUrl https://github.com/mtanda/grafana-aws-athena-datasource/releases/download/2.2.7/grafana-aws-athena-datasource-2.2.7.zip plugins install grafana-aws-athena-datasource 13 | exit 14 | 15 | # outside container 16 | docker restart grafana 17 | ``` 18 | -------------------------------------------------------------------------------- /ci/jobs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtanda/grafana-aws-athena-datasource/4af26402677617f9ec709b4c3a5afbc0349fc649/ci/jobs/.gitkeep -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/mtanda/grafana-aws-athena-datasource 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/aws/aws-sdk-go v1.19.37 7 | github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 8 | github.com/davecgh/go-spew v1.1.1 9 | github.com/grafana/grafana v6.0.1+incompatible 10 | github.com/grafana/grafana-plugin-model v0.0.0-20200514130833-df1eb6bdf4c5 11 | github.com/grafana/grafana-plugin-sdk-go v0.79.0 12 | github.com/hashicorp/go-hclog v0.8.0 // indirect 13 | github.com/hashicorp/go-plugin v1.2.2 14 | github.com/kr/pretty v0.1.0 // indirect 15 | github.com/magefile/mage v1.10.0 // indirect 16 | github.com/mitchellh/go-testing-interface v1.0.0 // indirect 17 | github.com/patrickmn/go-cache v2.1.0+incompatible 18 | github.com/prometheus/client_golang v1.3.0 19 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e 20 | google.golang.org/api v0.27.0 21 | gotest.tools v2.2.0+incompatible 22 | ) 23 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= 5 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= 6 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= 7 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= 8 | cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= 9 | cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= 10 | cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= 11 | cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= 12 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= 13 | cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= 14 | cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= 15 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= 16 | cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= 17 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= 18 | cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= 19 | cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= 20 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= 21 | cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= 22 | cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= 23 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 24 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 25 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 26 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 27 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 28 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 29 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 30 | github.com/apache/arrow/go/arrow v0.0.0-20200629181129-68b1273cbbf7 h1:dgL2mSOuj63SXOyojjWKq2ni3FQpQ+KrLKD7Pbq6t/4= 31 | github.com/apache/arrow/go/arrow v0.0.0-20200629181129-68b1273cbbf7/go.mod h1:QNYViu/X0HXDHw7m3KXzWSVXIbfUvJqBFe6Gj8/pYA0= 32 | github.com/aws/aws-sdk-go v1.19.37 h1:LUgXlZAnlkB8z7OcazfYma5TzFEJBD6K7aVpOy2tZ9k= 33 | github.com/aws/aws-sdk-go v1.19.37/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= 34 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 35 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 36 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 37 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 38 | github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= 39 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 40 | github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= 41 | github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 42 | github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= 43 | github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= 44 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 45 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 46 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 47 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 48 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 49 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 50 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 51 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 52 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 53 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 54 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 55 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 56 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 57 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 58 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 59 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 60 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 61 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 62 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 63 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 64 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 65 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 66 | github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 67 | github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 68 | github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 69 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 70 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 71 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= 72 | github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= 73 | github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= 74 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 75 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 76 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 77 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 78 | github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 79 | github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls= 80 | github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= 81 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 82 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 83 | github.com/google/flatbuffers v1.11.0 h1:O7CEyB8Cb3/DmtxODGtLHcEvpr81Jm5qLg/hsHnxA2A= 84 | github.com/google/flatbuffers v1.11.0/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= 85 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 86 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 87 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 88 | github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= 89 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 90 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 91 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 92 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 93 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 94 | github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 95 | github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 96 | github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 97 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 98 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 99 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= 100 | github.com/grafana/grafana v6.0.1+incompatible/go.mod h1:U8QyUclJHj254BFcuw45p6sg7eeGYX44qn1ShYo5rGE= 101 | github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4/go.mod h1:nc0XxBzjeGcrMltCDw269LoWF9S8ibhgxolCdA1R8To= 102 | github.com/grafana/grafana-plugin-model v0.0.0-20200514130833-df1eb6bdf4c5 h1:+biXr1VLrV5VtGa9tSDWzglcwgQ88lq6S6JIGWM1DXw= 103 | github.com/grafana/grafana-plugin-model v0.0.0-20200514130833-df1eb6bdf4c5/go.mod h1:nc0XxBzjeGcrMltCDw269LoWF9S8ibhgxolCdA1R8To= 104 | github.com/grafana/grafana-plugin-sdk-go v0.70.0 h1:tbwf0KMp8QEQQYF3bDBOOv/npegD6YP8T90OWbLr7n4= 105 | github.com/grafana/grafana-plugin-sdk-go v0.70.0/go.mod h1:NvxLzGkVhnoBKwzkst6CFfpMFKwAdIUZ1q8ssuLeF60= 106 | github.com/grafana/grafana-plugin-sdk-go v0.79.0 h1:7NVEIMlF8G9H7XUdLX9jH/g01FllE1GEBcFvzXZD+Kw= 107 | github.com/grafana/grafana-plugin-sdk-go v0.79.0/go.mod h1:NvxLzGkVhnoBKwzkst6CFfpMFKwAdIUZ1q8ssuLeF60= 108 | github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 h1:0IKlLyQ3Hs9nDaiK5cSHAGmcQEIC8l2Ts1u6x5Dfrqg= 109 | github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9GbyCZHuPgZsrbyIbyKhSzOpg6s= 110 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= 111 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 112 | github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= 113 | github.com/hashicorp/go-hclog v0.8.0 h1:z3ollgGRg8RjfJH6UVBaG54R70GFd++QOkvnJH3VSBY= 114 | github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= 115 | github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY= 116 | github.com/hashicorp/go-plugin v1.2.2 h1:mgDpq0PkoK5gck2w4ivaMpWRHv/matdOR4xmeScmf/w= 117 | github.com/hashicorp/go-plugin v1.2.2/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0= 118 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 119 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 120 | github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= 121 | github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= 122 | github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= 123 | github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= 124 | github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= 125 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= 126 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= 127 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 128 | github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 129 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 130 | github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= 131 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 132 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 133 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 134 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 135 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 136 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 137 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 138 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 139 | github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE= 140 | github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= 141 | github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= 142 | github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= 143 | github.com/mattetti/filebuffer v1.0.0 h1:ixTvQ0JjBTwWbdpDZ98lLrydo7KRi8xNRIi5RFszsbY= 144 | github.com/mattetti/filebuffer v1.0.0/go.mod h1:X6nyAIge2JGVmuJt2MFCqmHrb/5IHiphfHtot0s5cnI= 145 | github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= 146 | github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= 147 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 148 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 149 | github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= 150 | github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= 151 | github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= 152 | github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= 153 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 154 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 155 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 156 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 157 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 158 | github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= 159 | github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= 160 | github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8= 161 | github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= 162 | github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= 163 | github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= 164 | github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= 165 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 166 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 167 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 168 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 169 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 170 | github.com/prometheus/client_golang v1.3.0 h1:miYCvYqFXtl/J9FIy8eNpBfYthAEFg+Ys0XyUVEcDsc= 171 | github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= 172 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 173 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 174 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 175 | github.com/prometheus/client_model v0.1.0 h1:ElTg5tNp4DqfV7UQjDqv2+RJlNzsDtvNAWccbItceIE= 176 | github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 177 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 178 | github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= 179 | github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= 180 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 181 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 182 | github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8= 183 | github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= 184 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 185 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 186 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 187 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 188 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 189 | github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 190 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 191 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 192 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 193 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 194 | github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 195 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 196 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 197 | go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 198 | go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 199 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 200 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 201 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 202 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 203 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 204 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 205 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 206 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 207 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 208 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 209 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 210 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= 211 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= 212 | golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 213 | golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 214 | golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 215 | golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= 216 | golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= 217 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 218 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 219 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 220 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 221 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 222 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 223 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 224 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 225 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 226 | golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= 227 | golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= 228 | golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= 229 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 230 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 231 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 232 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 233 | golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 234 | golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 235 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 236 | golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 237 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 238 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 239 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 240 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 241 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 242 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 243 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 244 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 245 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 246 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 247 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 248 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 249 | golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 250 | golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 251 | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 252 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 253 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 254 | golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 255 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 256 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= 257 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 258 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 259 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 260 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 261 | golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 262 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 263 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 264 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 265 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 266 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 267 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 268 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 269 | golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 270 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 271 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 272 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 273 | golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 274 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 275 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 276 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 277 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 278 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 279 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 280 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 281 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 282 | golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 283 | golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 284 | golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 285 | golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 286 | golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 287 | golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 288 | golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 289 | golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 290 | golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 291 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 292 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 293 | golang.org/x/sys v0.0.0-20200331124033-c3d80250170d h1:nc5K6ox/4lTFbMVSL9WRR81ixkcwXThoiF6yf+R9scA= 294 | golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 295 | golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 296 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 297 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 298 | golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= 299 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 300 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 301 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 302 | golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 303 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 304 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 305 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 306 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 307 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 308 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 309 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 310 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 311 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 312 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 313 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 314 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 315 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 316 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 317 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 318 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 319 | golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 320 | golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 321 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 322 | golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 323 | golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 324 | golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 325 | golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 326 | golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 327 | golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 328 | golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 329 | golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 330 | golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 331 | golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 332 | golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 333 | golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= 334 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 335 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 336 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 337 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 338 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 339 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= 340 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 341 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 342 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 343 | google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 344 | google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 345 | google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 346 | google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 347 | google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 348 | google.golang.org/api v0.27.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= 349 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 350 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 351 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 352 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 353 | google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 354 | google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 355 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 356 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 357 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 358 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 359 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 360 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 361 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 362 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= 363 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 364 | google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 365 | google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 366 | google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 367 | google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 368 | google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 369 | google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= 370 | google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 371 | google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 372 | google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940 h1:MRHtG0U6SnaUb+s+LhNE1qt1FQ1wlhqr5E4usBKC0uA= 373 | google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 374 | google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= 375 | google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= 376 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 377 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 378 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 379 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 380 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 381 | google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 382 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 383 | google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 384 | google.golang.org/grpc v1.28.0 h1:bO/TA4OxCOummhSf10siHuG7vJOiwh7SpRpFZDkOgl4= 385 | google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= 386 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 387 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 388 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 389 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 390 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 391 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 392 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 393 | gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 394 | gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= 395 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 396 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 397 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 398 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 399 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 400 | honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= 401 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 402 | rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= 403 | rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= 404 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grafana-aws-athena-datasource", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "build": "grafana-toolkit plugin:build", 7 | "test": "grafana-toolkit plugin:test", 8 | "dev": "grafana-toolkit plugin:dev", 9 | "watch": "grafana-toolkit plugin:dev --watch" 10 | }, 11 | "author": "Mitsuhiro Tanda", 12 | "license": "Apache", 13 | "dependencies": { 14 | "lodash": "^4.17.15" 15 | }, 16 | "devDependencies": { 17 | "@grafana/data": "^7.3.1", 18 | "@grafana/runtime": "^7.3.1", 19 | "@grafana/toolkit": "^7.3.1", 20 | "@grafana/ui": "^7.3.1", 21 | "@types/jest": "^24.0.17", 22 | "@types/lodash": "^4.14.136", 23 | "@types/react": "^16.2.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pkg/credentials.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "os" 7 | "sync" 8 | "time" 9 | 10 | "github.com/aws/aws-sdk-go/service/athena" 11 | "github.com/aws/aws-sdk-go/service/ec2" 12 | "github.com/grafana/grafana-plugin-sdk-go/backend" 13 | 14 | "github.com/aws/aws-sdk-go/aws" 15 | "github.com/aws/aws-sdk-go/aws/credentials" 16 | "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds" 17 | "github.com/aws/aws-sdk-go/aws/credentials/endpointcreds" 18 | "github.com/aws/aws-sdk-go/aws/defaults" 19 | "github.com/aws/aws-sdk-go/aws/ec2metadata" 20 | "github.com/aws/aws-sdk-go/aws/session" 21 | "github.com/aws/aws-sdk-go/service/sts" 22 | ) 23 | 24 | type credentialCache struct { 25 | credential *credentials.Credentials 26 | expiration *time.Time 27 | } 28 | 29 | var awsCredentialCache = make(map[string]credentialCache) 30 | var credentialCacheLock sync.RWMutex 31 | 32 | type DatasourceInfo struct { 33 | Region string 34 | DefaultRegion string 35 | Profile string `json:"profile"` 36 | AuthType string `json:"authType"` 37 | AssumeRoleArn string `json:"assumeRoleArn"` 38 | 39 | AccessKey string 40 | SecretKey string 41 | } 42 | 43 | func GetCredentials(dsInfo *DatasourceInfo) (*credentials.Credentials, error) { 44 | cacheKey := dsInfo.AccessKey + ":" + dsInfo.Profile + ":" + dsInfo.AssumeRoleArn 45 | credentialCacheLock.RLock() 46 | if _, ok := awsCredentialCache[cacheKey]; ok { 47 | if awsCredentialCache[cacheKey].expiration != nil && 48 | (*awsCredentialCache[cacheKey].expiration).After(time.Now().UTC()) { 49 | result := awsCredentialCache[cacheKey].credential 50 | credentialCacheLock.RUnlock() 51 | return result, nil 52 | } 53 | } 54 | credentialCacheLock.RUnlock() 55 | 56 | accessKeyId := "" 57 | secretAccessKey := "" 58 | sessionToken := "" 59 | var expiration *time.Time = nil 60 | if dsInfo.AuthType == "arn" { 61 | params := &sts.AssumeRoleInput{ 62 | RoleArn: aws.String(dsInfo.AssumeRoleArn), 63 | RoleSessionName: aws.String("GrafanaSession"), 64 | DurationSeconds: aws.Int64(900), 65 | } 66 | 67 | stsSess, err := session.NewSession() 68 | if err != nil { 69 | return nil, err 70 | } 71 | stsCreds := credentials.NewChainCredentials( 72 | []credentials.Provider{ 73 | &credentials.EnvProvider{}, 74 | &credentials.SharedCredentialsProvider{Filename: "", Profile: dsInfo.Profile}, 75 | remoteCredProvider(stsSess), 76 | }) 77 | stsConfig := &aws.Config{ 78 | Region: aws.String(dsInfo.Region), 79 | Credentials: stsCreds, 80 | } 81 | 82 | sess, err := session.NewSession(stsConfig) 83 | if err != nil { 84 | return nil, err 85 | } 86 | svc := sts.New(sess, stsConfig) 87 | resp, err := svc.AssumeRole(params) 88 | if err != nil { 89 | return nil, err 90 | } 91 | if resp.Credentials != nil { 92 | accessKeyId = *resp.Credentials.AccessKeyId 93 | secretAccessKey = *resp.Credentials.SecretAccessKey 94 | sessionToken = *resp.Credentials.SessionToken 95 | expiration = resp.Credentials.Expiration 96 | } 97 | } else { 98 | now := time.Now() 99 | e := now.Add(5 * time.Minute) 100 | expiration = &e 101 | } 102 | 103 | sess, err := session.NewSession() 104 | if err != nil { 105 | return nil, err 106 | } 107 | creds := credentials.NewChainCredentials( 108 | []credentials.Provider{ 109 | &credentials.StaticProvider{Value: credentials.Value{ 110 | AccessKeyID: accessKeyId, 111 | SecretAccessKey: secretAccessKey, 112 | SessionToken: sessionToken, 113 | }}, 114 | &credentials.EnvProvider{}, 115 | &credentials.StaticProvider{Value: credentials.Value{ 116 | AccessKeyID: dsInfo.AccessKey, 117 | SecretAccessKey: dsInfo.SecretKey, 118 | }}, 119 | &credentials.SharedCredentialsProvider{Filename: "", Profile: dsInfo.Profile}, 120 | remoteCredProvider(sess), 121 | }) 122 | 123 | credentialCacheLock.Lock() 124 | awsCredentialCache[cacheKey] = credentialCache{ 125 | credential: creds, 126 | expiration: expiration, 127 | } 128 | credentialCacheLock.Unlock() 129 | 130 | return creds, nil 131 | } 132 | 133 | func remoteCredProvider(sess *session.Session) credentials.Provider { 134 | ecsCredURI := os.Getenv("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI") 135 | 136 | if len(ecsCredURI) > 0 { 137 | return ecsCredProvider(sess, ecsCredURI) 138 | } 139 | return ec2RoleProvider(sess) 140 | } 141 | 142 | func ecsCredProvider(sess *session.Session, uri string) credentials.Provider { 143 | const host = `169.254.170.2` 144 | 145 | d := defaults.Get() 146 | return endpointcreds.NewProviderClient( 147 | *d.Config, 148 | d.Handlers, 149 | fmt.Sprintf("http://%s%s", host, uri), 150 | func(p *endpointcreds.Provider) { p.ExpiryWindow = 5 * time.Minute }) 151 | } 152 | 153 | func ec2RoleProvider(sess *session.Session) credentials.Provider { 154 | return &ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(sess), ExpiryWindow: 5 * time.Minute} 155 | } 156 | 157 | func (t *AwsAthenaDatasource) getDsInfo(datasourceInfo *backend.DataSourceInstanceSettings, region string) (*DatasourceInfo, error) { 158 | var dsInfo DatasourceInfo 159 | if err := json.Unmarshal([]byte(datasourceInfo.JSONData), &dsInfo); err != nil { 160 | return nil, err 161 | } 162 | 163 | if region == "default" || region == "" { 164 | dsInfo.Region = dsInfo.DefaultRegion 165 | } else { 166 | dsInfo.Region = region 167 | } 168 | if v, ok := datasourceInfo.DecryptedSecureJSONData["accessKey"]; ok { 169 | dsInfo.AccessKey = v 170 | } 171 | if v, ok := datasourceInfo.DecryptedSecureJSONData["secretKey"]; ok { 172 | dsInfo.SecretKey = v 173 | } 174 | 175 | return &dsInfo, nil 176 | } 177 | 178 | func (t *AwsAthenaDatasource) getAwsConfig(dsInfo *DatasourceInfo) (*aws.Config, error) { 179 | creds, err := GetCredentials(dsInfo) 180 | if err != nil { 181 | return nil, err 182 | } 183 | 184 | cfg := &aws.Config{ 185 | Region: aws.String(dsInfo.Region), 186 | Credentials: creds, 187 | } 188 | return cfg, nil 189 | } 190 | 191 | func (t *AwsAthenaDatasource) getClient(datasourceInfo *backend.DataSourceInstanceSettings, region string) (*athena.Athena, error) { 192 | dsInfo, err := t.getDsInfo(datasourceInfo, region) 193 | if err != nil { 194 | return nil, err 195 | } 196 | cfg, err := t.getAwsConfig(dsInfo) 197 | if err != nil { 198 | return nil, err 199 | } 200 | 201 | sess, err := session.NewSession(cfg) 202 | if err != nil { 203 | return nil, err 204 | } 205 | 206 | client := athena.New(sess, cfg) 207 | return client, nil 208 | } 209 | 210 | func (t *AwsAthenaDatasource) getEC2Client(datasourceInfo *backend.DataSourceInstanceSettings, region string) (*ec2.EC2, error) { 211 | dsInfo, err := t.getDsInfo(datasourceInfo, region) 212 | if err != nil { 213 | return nil, err 214 | } 215 | cfg, err := t.getAwsConfig(dsInfo) 216 | if err != nil { 217 | return nil, err 218 | } 219 | 220 | sess, err := session.NewSession(cfg) 221 | if err != nil { 222 | return nil, err 223 | } 224 | 225 | client := ec2.New(sess, cfg) 226 | return client, nil 227 | } 228 | -------------------------------------------------------------------------------- /pkg/datasource.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "math" 8 | "net/http" 9 | "regexp" 10 | "sort" 11 | "strconv" 12 | "strings" 13 | "time" 14 | 15 | "golang.org/x/net/context" 16 | 17 | "github.com/aws/aws-sdk-go/aws" 18 | "github.com/aws/aws-sdk-go/service/athena" 19 | "github.com/aws/aws-sdk-go/service/ec2" 20 | "github.com/patrickmn/go-cache" 21 | "github.com/prometheus/client_golang/prometheus" 22 | 23 | "github.com/grafana/grafana-plugin-sdk-go/backend" 24 | "github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter" 25 | "github.com/grafana/grafana-plugin-sdk-go/data" 26 | ) 27 | 28 | type AwsAthenaDatasource struct { 29 | cache *cache.Cache 30 | metrics *AwsAthenaMetrics 31 | } 32 | 33 | type AwsAthenaMetrics struct { 34 | queriesTotal *prometheus.CounterVec 35 | dataScannedBytesTotal *prometheus.CounterVec 36 | } 37 | 38 | var ( 39 | legendFormatPattern *regexp.Regexp 40 | clientCache = make(map[string]*athena.Athena) 41 | ) 42 | 43 | const ( 44 | DEFAULT_MAX_ROWS = 1000 45 | AWS_API_RESULT_MAX_LENGTH = 50 46 | QUERY_WAIT_COUNT = 30 47 | ) 48 | 49 | func init() { 50 | legendFormatPattern = regexp.MustCompile(`\{\{\s*(.+?)\s*\}\}`) 51 | } 52 | 53 | const metricNamespace = "aws_athena_datasource" 54 | 55 | func NewDataSource(mux *http.ServeMux) *AwsAthenaDatasource { 56 | ds := &AwsAthenaDatasource{ 57 | cache: cache.New(300*time.Second, 5*time.Second), 58 | } 59 | 60 | metrics := &AwsAthenaMetrics{ 61 | queriesTotal: prometheus.NewCounterVec( 62 | prometheus.CounterOpts{ 63 | Name: "data_query_total", 64 | Help: "data query counter", 65 | Namespace: metricNamespace, 66 | }, 67 | []string{"region"}, 68 | ), 69 | dataScannedBytesTotal: prometheus.NewCounterVec( 70 | prometheus.CounterOpts{ 71 | Name: "data_scanned_bytes_total", 72 | Help: "scanned data size counter", 73 | Namespace: metricNamespace, 74 | }, 75 | []string{"region"}, 76 | ), 77 | } 78 | prometheus.MustRegister(metrics.queriesTotal) 79 | prometheus.MustRegister(metrics.dataScannedBytesTotal) 80 | ds.metrics = metrics 81 | 82 | mux.HandleFunc("/regions", ds.handleResourceRegions) 83 | mux.HandleFunc("/workgroup_names", ds.handleResourceWorkgroupNames) 84 | mux.HandleFunc("/named_query_names", ds.handleResourceNamedQueryNames) 85 | mux.HandleFunc("/named_query_queries", ds.handleResourceNamedQueryQueries) 86 | mux.HandleFunc("/query_executions", ds.handleResourceQueryExecutions) 87 | mux.HandleFunc("/query_executions_by_name", ds.handleResourceQueryExecutionsByName) 88 | 89 | return ds 90 | } 91 | 92 | func (ds *AwsAthenaDatasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) { 93 | res := &backend.CheckHealthResult{} 94 | 95 | if req.PluginContext.DataSourceInstanceSettings == nil { 96 | res.Status = backend.HealthStatusOk 97 | res.Message = "Plugin is Running" 98 | return res, nil 99 | } 100 | 101 | svc, err := ds.getClient(req.PluginContext.DataSourceInstanceSettings, "us-east-1") 102 | if err != nil { 103 | res.Status = backend.HealthStatusError 104 | res.Message = "Unable to create client" 105 | return res, nil 106 | } 107 | 108 | _, err = svc.ListNamedQueriesWithContext(ctx, &athena.ListNamedQueriesInput{}) 109 | if err != nil { 110 | res.Status = backend.HealthStatusError 111 | res.Message = "Unable to call Athena API" 112 | return res, nil 113 | } 114 | 115 | res.Status = backend.HealthStatusOk 116 | res.Message = "Success" 117 | return res, nil 118 | } 119 | 120 | func (ds *AwsAthenaDatasource) QueryData(ctx context.Context, tsdbReq *backend.QueryDataRequest) (*backend.QueryDataResponse, error) { 121 | responses := &backend.QueryDataResponse{ 122 | Responses: map[string]backend.DataResponse{}, 123 | } 124 | 125 | targets := make([]AwsAthenaQuery, 0) 126 | for _, query := range tsdbReq.Queries { 127 | target := AwsAthenaQuery{} 128 | if err := json.Unmarshal([]byte(query.JSON), &target); err != nil { 129 | return nil, err 130 | } 131 | target.From = query.TimeRange.From 132 | target.To = query.TimeRange.To 133 | 134 | svc, err := ds.getClient(tsdbReq.PluginContext.DataSourceInstanceSettings, target.Region) 135 | if err != nil { 136 | return nil, err 137 | } 138 | dsInfo, err := ds.getDsInfo(tsdbReq.PluginContext.DataSourceInstanceSettings, target.Region) 139 | if err != nil { 140 | return nil, err 141 | } 142 | if target.Region == "default" || target.Region == "" { 143 | target.Region = dsInfo.DefaultRegion 144 | } 145 | target.client = svc 146 | target.cache = ds.cache 147 | target.metrics = ds.metrics 148 | target.datasourceID = tsdbReq.PluginContext.DataSourceInstanceSettings.ID 149 | 150 | targets = append(targets, target) 151 | } 152 | 153 | for _, target := range targets { 154 | result, err := target.getQueryResults(ctx, tsdbReq.PluginContext) 155 | if err != nil { 156 | responses.Responses[target.RefId] = backend.DataResponse{ 157 | Error: err, 158 | } 159 | continue 160 | } 161 | 162 | timeFormat := target.TimeFormat 163 | if timeFormat == "" { 164 | timeFormat = time.RFC3339Nano 165 | } 166 | 167 | if frames, err := parseResponse(result, target.RefId, target.From, target.To, target.TimestampColumn, target.ValueColumn, target.LegendFormat, timeFormat); err != nil { 168 | responses.Responses[target.RefId] = backend.DataResponse{ 169 | Error: err, 170 | } 171 | } else { 172 | responses.Responses[target.RefId] = backend.DataResponse{ 173 | Frames: append(responses.Responses[target.RefId].Frames, frames...), 174 | } 175 | } 176 | } 177 | 178 | return responses, nil 179 | } 180 | 181 | func parseResponse(resp *athena.GetQueryResultsOutput, refId string, from time.Time, to time.Time, timestampColumn string, valueColumn string, legendFormat string, timeFormat string) ([]*data.Frame, error) { 182 | warnings := []string{} 183 | 184 | timestampIndex := -1 185 | converters := make([]data.FieldConverter, len(resp.ResultSet.ResultSetMetadata.ColumnInfo)) 186 | for i, c := range resp.ResultSet.ResultSetMetadata.ColumnInfo { 187 | fc, ok := converterMap[*c.Type] 188 | if !ok { 189 | warning := fmt.Sprintf("unknown column type: %s", *c.Type) 190 | warnings = append(warnings, warning) 191 | fc = stringFieldConverter 192 | } 193 | if *c.Name == timestampColumn { 194 | timestampIndex = i 195 | if *c.Type == "varchar" { 196 | fc = genTimeFieldConverter(timeFormat) 197 | } 198 | } 199 | if *c.Name == valueColumn { 200 | fc = floatFieldConverter 201 | } 202 | converters[i] = fc 203 | } 204 | 205 | if timestampIndex != -1 { 206 | n := 0 207 | // filter row without timestamp 208 | for _, row := range resp.ResultSet.Rows { 209 | if row.Data[timestampIndex].VarCharValue == nil { 210 | continue 211 | } 212 | resp.ResultSet.Rows[n] = row 213 | n++ 214 | } 215 | resp.ResultSet.Rows = resp.ResultSet.Rows[:n] 216 | 217 | // sort by timestamp 218 | sort.Slice(resp.ResultSet.Rows, func(i, j int) bool { 219 | return *resp.ResultSet.Rows[i].Data[timestampIndex].VarCharValue < *resp.ResultSet.Rows[j].Data[timestampIndex].VarCharValue 220 | }) 221 | } 222 | 223 | fieldNames := make([]string, 0) 224 | for _, column := range resp.ResultSet.ResultSetMetadata.ColumnInfo { 225 | fieldNames = append(fieldNames, *column.Name) 226 | } 227 | 228 | fm := make(map[string]*data.Frame) 229 | for _, row := range resp.ResultSet.Rows { 230 | kv := make(map[string]string) 231 | for columnIdx, cell := range row.Data { 232 | if cell == nil || cell.VarCharValue == nil { 233 | continue 234 | } 235 | columnName := *resp.ResultSet.ResultSetMetadata.ColumnInfo[columnIdx].Name 236 | if columnName == timestampColumn || columnName == valueColumn { 237 | continue 238 | } 239 | kv[columnName] = *cell.VarCharValue 240 | } 241 | name := formatLegend(kv, legendFormat) 242 | frame, ok := fm[name] 243 | if !ok { 244 | fTypes := make([]data.FieldType, len(converters)) 245 | for i, fc := range converters { 246 | fTypes[i] = fc.OutputFieldType 247 | } 248 | frame = data.NewFrameOfFieldTypes("", 0, fTypes...) 249 | 250 | frame.RefID = refId 251 | frame.Name = name 252 | meta := make(map[string]interface{}) 253 | meta["warnings"] = warnings 254 | frame.Meta = &data.FrameMeta{Custom: meta} 255 | if err := frame.SetFieldNames(fieldNames...); err != nil { 256 | return nil, err 257 | } 258 | fm[name] = frame 259 | } 260 | newRow := make([]interface{}, 0, len(row.Data)) 261 | for columnIdx, cell := range row.Data { 262 | if cell == nil || cell.VarCharValue == nil { 263 | newRow = append(newRow, nil) 264 | } else if converters[columnIdx].Converter == nil { 265 | return nil, fmt.Errorf("converter should set") 266 | } else { 267 | convertedCell, err := converters[columnIdx].Converter(*cell.VarCharValue) 268 | if err != nil { 269 | return nil, err 270 | } else { 271 | newRow = append(newRow, convertedCell) 272 | } 273 | } 274 | } 275 | if len(newRow) == len(row.Data) { 276 | frame.AppendRow(newRow...) 277 | } 278 | } 279 | 280 | frames := make([]*data.Frame, 0) 281 | keys := make([]string, 0) 282 | for key := range fm { 283 | keys = append(keys, key) 284 | } 285 | sort.Strings(keys) 286 | for _, key := range keys { 287 | // skip out of time range data 288 | if timestampIndex != -1 { 289 | timeField := fm[key].Fields[timestampIndex] 290 | l := timeField.Len() 291 | if l > 0 { 292 | v := timeField.At(l - 1) 293 | lastTime, ok := v.(*time.Time) 294 | if !ok { 295 | return nil, fmt.Errorf("expected time input but got type %T", v) 296 | } 297 | if lastTime.Before(from) { 298 | continue 299 | } 300 | } 301 | } 302 | frames = append(frames, fm[key]) 303 | } 304 | 305 | return frames, nil 306 | } 307 | 308 | var converterMap = map[string]data.FieldConverter{ 309 | "varchar": stringFieldConverter, 310 | "integer": intFieldConverter, 311 | "tinyint": intFieldConverter, 312 | "smallint": intFieldConverter, 313 | "bigint": intFieldConverter, 314 | "float": floatFieldConverter, 315 | "double": floatFieldConverter, 316 | "boolean": boolFieldConverter, 317 | "date": genTimeFieldConverter("2006-01-02"), 318 | "timestamp": genTimeFieldConverter("2006-01-02 15:04:05.000"), 319 | } 320 | 321 | func genTimeFieldConverter(timeFormat string) data.FieldConverter { 322 | return data.FieldConverter{ 323 | OutputFieldType: data.FieldTypeNullableTime, 324 | Converter: func(v interface{}) (interface{}, error) { 325 | val, ok := v.(string) 326 | if !ok { 327 | return nil, fmt.Errorf("expected string input but got type %T", v) 328 | } 329 | if t, err := time.Parse(timeFormat, val); err != nil { 330 | return nil, err 331 | } else { 332 | return aws.Time(t), nil 333 | } 334 | }, 335 | } 336 | } 337 | 338 | var stringFieldConverter = data.FieldConverter{ 339 | OutputFieldType: data.FieldTypeNullableString, 340 | Converter: func(v interface{}) (interface{}, error) { 341 | val, ok := v.(string) 342 | if !ok { 343 | return nil, fmt.Errorf("expected string input but got type %T", v) 344 | } 345 | return aws.String(val), nil 346 | }, 347 | } 348 | 349 | var intFieldConverter = data.FieldConverter{ 350 | OutputFieldType: data.FieldTypeNullableInt64, 351 | Converter: func(v interface{}) (interface{}, error) { 352 | val, ok := v.(string) 353 | if !ok { 354 | return nil, fmt.Errorf("expected string input but got type %T", v) 355 | } 356 | if cval, err := strconv.ParseInt(val, 10, 64); err != nil { 357 | return nil, err 358 | } else { 359 | return aws.Int64(cval), nil 360 | } 361 | }, 362 | } 363 | 364 | var floatFieldConverter = data.FieldConverter{ 365 | OutputFieldType: data.FieldTypeNullableFloat64, 366 | Converter: func(v interface{}) (interface{}, error) { 367 | val, ok := v.(string) 368 | if !ok { 369 | return nil, fmt.Errorf("expected string input but got type %T", v) 370 | } 371 | if cval, err := strconv.ParseFloat(val, 64); err != nil { 372 | return nil, err 373 | } else { 374 | return aws.Float64(cval), nil 375 | } 376 | }, 377 | } 378 | 379 | var boolFieldConverter = data.FieldConverter{ 380 | OutputFieldType: data.FieldTypeNullableBool, 381 | Converter: func(v interface{}) (interface{}, error) { 382 | val, ok := v.(string) 383 | if !ok { 384 | return nil, fmt.Errorf("expected string input but got type %T", v) 385 | } 386 | return aws.Bool(val == "true"), nil 387 | }, 388 | } 389 | 390 | func formatLegend(kv map[string]string, legendFormat string) string { 391 | if legendFormat == "" { 392 | l := make([]string, 0) 393 | for k, v := range kv { 394 | l = append(l, fmt.Sprintf("%s=\"%s\"", k, v)) 395 | } 396 | return "{" + strings.Join(l, ",") + "}" 397 | } 398 | 399 | result := legendFormatPattern.ReplaceAllFunc([]byte(legendFormat), func(in []byte) []byte { 400 | columnName := strings.Replace(string(in), "{{", "", 1) 401 | columnName = strings.Replace(columnName, "}}", "", 1) 402 | columnName = strings.TrimSpace(columnName) 403 | if val, exists := kv[columnName]; exists { 404 | return []byte(val) 405 | } 406 | 407 | return in 408 | }) 409 | 410 | return string(result) 411 | } 412 | 413 | func writeResult(rw http.ResponseWriter, path string, val interface{}, err error) { 414 | response := make(map[string]interface{}) 415 | code := http.StatusOK 416 | if err != nil { 417 | response["error"] = err.Error() 418 | code = http.StatusBadRequest 419 | } else { 420 | response[path] = val 421 | } 422 | 423 | body, err := json.Marshal(response) 424 | if err != nil { 425 | body = []byte(err.Error()) 426 | code = http.StatusInternalServerError 427 | } 428 | _, err = rw.Write(body) 429 | if err != nil { 430 | code = http.StatusInternalServerError 431 | } 432 | rw.WriteHeader(code) 433 | } 434 | 435 | func (ds *AwsAthenaDatasource) handleResourceRegions(rw http.ResponseWriter, req *http.Request) { 436 | backend.Logger.Debug("Received resource call", "url", req.URL.String(), "method", req.Method) 437 | if req.Method != http.MethodGet { 438 | return 439 | } 440 | 441 | ctx := req.Context() 442 | pluginContext := httpadapter.PluginConfigFromContext(ctx) 443 | 444 | svc, err := ds.getEC2Client(pluginContext.DataSourceInstanceSettings, "us-east-1") 445 | if err != nil { 446 | writeResult(rw, "?", nil, err) 447 | return 448 | } 449 | 450 | regions := []string{"default"} 451 | ro, err := svc.DescribeRegions(&ec2.DescribeRegionsInput{}) 452 | if err != nil { 453 | // ignore error 454 | regions = append(regions, []string{ 455 | "ap-east-1", 456 | "ap-northeast-1", 457 | "ap-northeast-2", 458 | "ap-northeast-3", 459 | "ap-south-1", 460 | "ap-southeast-1", 461 | "ap-southeast-2", 462 | "ca-central-1", 463 | "cn-north-1", 464 | "cn-northwest-1", 465 | "eu-central-1", 466 | "eu-north-1", 467 | "eu-west-1", 468 | "eu-west-2", 469 | "eu-west-3", 470 | "me-south-1", 471 | "sa-east-1", 472 | "us-east-1", 473 | "us-east-2", 474 | "us-gov-east-1", 475 | "us-gov-west-1", 476 | "us-iso-east-1", 477 | "us-isob-east-1", 478 | "us-west-1", 479 | "us-west-2", 480 | }...) 481 | } else { 482 | for _, r := range ro.Regions { 483 | regions = append(regions, *r.RegionName) 484 | } 485 | } 486 | sort.Strings(regions) 487 | 488 | writeResult(rw, "regions", regions, err) 489 | } 490 | 491 | func (ds *AwsAthenaDatasource) handleResourceWorkgroupNames(rw http.ResponseWriter, req *http.Request) { 492 | backend.Logger.Debug("Received resource call", "url", req.URL.String(), "method", req.Method) 493 | if req.Method != http.MethodGet { 494 | return 495 | } 496 | 497 | ctx := req.Context() 498 | pluginContext := httpadapter.PluginConfigFromContext(ctx) 499 | urlQuery := req.URL.Query() 500 | region := urlQuery.Get("region") 501 | 502 | svc, err := ds.getClient(pluginContext.DataSourceInstanceSettings, region) 503 | if err != nil { 504 | writeResult(rw, "?", nil, err) 505 | return 506 | } 507 | 508 | workgroupNames := make([]string, 0) 509 | li := &athena.ListWorkGroupsInput{} 510 | lo := &athena.ListWorkGroupsOutput{} 511 | err = svc.ListWorkGroupsPagesWithContext(ctx, li, 512 | func(page *athena.ListWorkGroupsOutput, lastPage bool) bool { 513 | lo.WorkGroups = append(lo.WorkGroups, page.WorkGroups...) 514 | return !lastPage 515 | }) 516 | if err != nil { 517 | writeResult(rw, "?", nil, err) 518 | return 519 | } 520 | for _, w := range lo.WorkGroups { 521 | workgroupNames = append(workgroupNames, *w.Name) 522 | } 523 | 524 | writeResult(rw, "workgroup_names", workgroupNames, err) 525 | } 526 | 527 | func (ds *AwsAthenaDatasource) handleResourceNamedQueryNames(rw http.ResponseWriter, req *http.Request) { 528 | backend.Logger.Debug("Received resource call", "url", req.URL.String(), "method", req.Method) 529 | if req.Method != http.MethodGet { 530 | return 531 | } 532 | 533 | ctx := req.Context() 534 | pluginContext := httpadapter.PluginConfigFromContext(ctx) 535 | urlQuery := req.URL.Query() 536 | region := urlQuery.Get("region") 537 | workGroup := urlQuery.Get("workGroup") 538 | 539 | svc, err := ds.getClient(pluginContext.DataSourceInstanceSettings, region) 540 | if err != nil { 541 | writeResult(rw, "?", nil, err) 542 | return 543 | } 544 | 545 | data := make([]string, 0) 546 | var workGroupParam *string 547 | workGroupParam = nil 548 | if workGroup != "" { 549 | workGroupParam = &workGroup 550 | } 551 | li := &athena.ListNamedQueriesInput{ 552 | WorkGroup: workGroupParam, 553 | } 554 | lo := &athena.ListNamedQueriesOutput{} 555 | if err := svc.ListNamedQueriesPagesWithContext(ctx, li, 556 | func(page *athena.ListNamedQueriesOutput, lastPage bool) bool { 557 | lo.NamedQueryIds = append(lo.NamedQueryIds, page.NamedQueryIds...) 558 | return !lastPage 559 | }); err != nil { 560 | writeResult(rw, "?", nil, err) 561 | return 562 | } 563 | for i := 0; i < len(lo.NamedQueryIds); i += AWS_API_RESULT_MAX_LENGTH { 564 | e := int64(math.Min(float64(i+AWS_API_RESULT_MAX_LENGTH), float64(len(lo.NamedQueryIds)))) 565 | bi := &athena.BatchGetNamedQueryInput{NamedQueryIds: lo.NamedQueryIds[i:e]} 566 | bo, err := svc.BatchGetNamedQueryWithContext(ctx, bi) 567 | if err != nil { 568 | writeResult(rw, "?", nil, err) 569 | return 570 | } 571 | for _, q := range bo.NamedQueries { 572 | data = append(data, *q.Name) 573 | } 574 | } 575 | writeResult(rw, "named_query_names", data, err) 576 | } 577 | 578 | func (ds *AwsAthenaDatasource) getNamedQueryQueries(ctx context.Context, pluginContext backend.PluginContext, region string, workGroup string, pattern string) ([]string, error) { 579 | svc, err := ds.getClient(pluginContext.DataSourceInstanceSettings, region) 580 | if err != nil { 581 | return nil, err 582 | } 583 | 584 | data := make([]string, 0) 585 | var workGroupParam *string 586 | workGroupParam = nil 587 | if workGroup != "" { 588 | workGroupParam = &workGroup 589 | } 590 | r := regexp.MustCompile(pattern) 591 | li := &athena.ListNamedQueriesInput{ 592 | WorkGroup: workGroupParam, 593 | } 594 | lo := &athena.ListNamedQueriesOutput{} 595 | err = svc.ListNamedQueriesPagesWithContext(ctx, li, 596 | func(page *athena.ListNamedQueriesOutput, lastPage bool) bool { 597 | lo.NamedQueryIds = append(lo.NamedQueryIds, page.NamedQueryIds...) 598 | return !lastPage 599 | }) 600 | if err != nil { 601 | return nil, err 602 | } 603 | for i := 0; i < len(lo.NamedQueryIds); i += AWS_API_RESULT_MAX_LENGTH { 604 | e := int64(math.Min(float64(i+AWS_API_RESULT_MAX_LENGTH), float64(len(lo.NamedQueryIds)))) 605 | bi := &athena.BatchGetNamedQueryInput{NamedQueryIds: lo.NamedQueryIds[i:e]} 606 | bo, err := svc.BatchGetNamedQueryWithContext(ctx, bi) 607 | if err != nil { 608 | return nil, err 609 | } 610 | for _, q := range bo.NamedQueries { 611 | if r.MatchString(*q.Name) { 612 | data = append(data, *q.QueryString) 613 | } 614 | } 615 | } 616 | 617 | return data, nil 618 | } 619 | 620 | func (ds *AwsAthenaDatasource) handleResourceNamedQueryQueries(rw http.ResponseWriter, req *http.Request) { 621 | backend.Logger.Debug("Received resource call", "url", req.URL.String(), "method", req.Method) 622 | if req.Method != http.MethodGet { 623 | return 624 | } 625 | 626 | ctx := req.Context() 627 | pluginContext := httpadapter.PluginConfigFromContext(ctx) 628 | urlQuery := req.URL.Query() 629 | region := urlQuery.Get("region") 630 | pattern := urlQuery.Get("pattern") 631 | workGroup := urlQuery.Get("workGroup") 632 | 633 | data, err := ds.getNamedQueryQueries(ctx, pluginContext, region, workGroup, pattern) 634 | if err != nil { 635 | writeResult(rw, "?", nil, err) 636 | return 637 | } 638 | 639 | writeResult(rw, "named_query_queries", data, err) 640 | } 641 | 642 | func (ds *AwsAthenaDatasource) getQueryExecutions(ctx context.Context, pluginContext backend.PluginContext, region string, workGroup string, pattern string, to time.Time) ([]*athena.QueryExecution, error) { 643 | svc, err := ds.getClient(pluginContext.DataSourceInstanceSettings, region) 644 | if err != nil { 645 | return nil, err 646 | } 647 | 648 | var workGroupParam *string 649 | workGroupParam = nil 650 | if workGroup != "" { 651 | workGroupParam = &workGroup 652 | } 653 | r := regexp.MustCompile(pattern) 654 | 655 | var lastQueryExecutionID string 656 | lastQueryExecutionIDCacheKey := "LastQueryExecutionId/" + strconv.FormatInt(pluginContext.DataSourceInstanceSettings.ID, 10) + "/" + region + "/" + workGroup 657 | if item, _, found := ds.cache.GetWithExpiration(lastQueryExecutionIDCacheKey); found { 658 | if id, ok := item.(string); ok { 659 | lastQueryExecutionID = id 660 | } 661 | } 662 | 663 | li := &athena.ListQueryExecutionsInput{ 664 | WorkGroup: workGroupParam, 665 | } 666 | lo := &athena.ListQueryExecutionsOutput{} 667 | err = svc.ListQueryExecutionsPagesWithContext(ctx, li, 668 | func(page *athena.ListQueryExecutionsOutput, lastPage bool) bool { 669 | lo.QueryExecutionIds = append(lo.QueryExecutionIds, page.QueryExecutionIds...) 670 | if *lo.QueryExecutionIds[0] == lastQueryExecutionID { 671 | return false // valid cache exists, get query executions from cache 672 | } 673 | return !lastPage 674 | }) 675 | if err != nil { 676 | return nil, err 677 | } 678 | 679 | allQueryExecution := make([]*athena.QueryExecution, 0) 680 | QueryExecutionsCacheKey := "QueryExecutions/" + strconv.FormatInt(pluginContext.DataSourceInstanceSettings.ID, 10) + "/" + region + "/" + workGroup 681 | if *lo.QueryExecutionIds[0] == lastQueryExecutionID { 682 | if item, _, found := ds.cache.GetWithExpiration(QueryExecutionsCacheKey); found { 683 | if aqe, ok := item.([]*athena.QueryExecution); ok { 684 | allQueryExecution = aqe 685 | } 686 | } 687 | } else { 688 | for i := 0; i < len(lo.QueryExecutionIds); i += AWS_API_RESULT_MAX_LENGTH { 689 | e := int64(math.Min(float64(i+AWS_API_RESULT_MAX_LENGTH), float64(len(lo.QueryExecutionIds)))) 690 | bi := &athena.BatchGetQueryExecutionInput{QueryExecutionIds: lo.QueryExecutionIds[i:e]} 691 | bo, err := svc.BatchGetQueryExecutionWithContext(ctx, bi) 692 | if err != nil { 693 | return nil, err 694 | } 695 | allQueryExecution = append(allQueryExecution, bo.QueryExecutions...) 696 | } 697 | 698 | ds.cache.Set(lastQueryExecutionIDCacheKey, *lo.QueryExecutionIds[0], time.Duration(24)*time.Hour) 699 | ds.cache.Set(QueryExecutionsCacheKey, allQueryExecution, time.Duration(24)*time.Hour) 700 | } 701 | 702 | fbo := make([]*athena.QueryExecution, 0) 703 | for _, q := range allQueryExecution { 704 | if *q.Status.State != "SUCCEEDED" { 705 | continue 706 | } 707 | if (*q.Status.CompletionDateTime).After(to) { 708 | continue 709 | } 710 | if r.MatchString(*q.Query) { 711 | fbo = append(fbo, q) 712 | } 713 | } 714 | sort.Slice(fbo, func(i, j int) bool { 715 | return fbo[i].Status.CompletionDateTime.After(*fbo[j].Status.CompletionDateTime) 716 | }) 717 | return fbo, nil 718 | } 719 | 720 | func (ds *AwsAthenaDatasource) handleResourceQueryExecutions(rw http.ResponseWriter, req *http.Request) { 721 | backend.Logger.Debug("Received resource call", "url", req.URL.String(), "method", req.Method) 722 | if req.Method != http.MethodGet { 723 | return 724 | } 725 | 726 | ctx := req.Context() 727 | pluginContext := httpadapter.PluginConfigFromContext(ctx) 728 | urlQuery := req.URL.Query() 729 | region := urlQuery.Get("region") 730 | pattern := urlQuery.Get("pattern") 731 | limit, err := strconv.ParseInt(urlQuery.Get("limit"), 10, 64) 732 | if err != nil { 733 | writeResult(rw, "?", nil, err) 734 | return 735 | } 736 | workGroup := urlQuery.Get("workGroup") 737 | to, err := time.Parse(time.RFC3339, urlQuery.Get("to")) 738 | if err != nil { 739 | writeResult(rw, "?", nil, err) 740 | return 741 | } 742 | 743 | queryExecutions, err := ds.getQueryExecutions(ctx, pluginContext, region, workGroup, pattern, to) 744 | if err != nil { 745 | writeResult(rw, "?", nil, err) 746 | return 747 | } 748 | 749 | if limit != -1 { 750 | limit = int64(math.Min(float64(limit), float64(len(queryExecutions)))) 751 | queryExecutions = queryExecutions[0:limit] 752 | } 753 | 754 | writeResult(rw, "query_executions", queryExecutions, err) 755 | } 756 | 757 | func (ds *AwsAthenaDatasource) handleResourceQueryExecutionsByName(rw http.ResponseWriter, req *http.Request) { 758 | backend.Logger.Info("handleResourceQueryExecutionsByName Received resource call", "url", req.URL.String(), "method", req.Method) 759 | if req.Method != http.MethodGet { 760 | return 761 | } 762 | 763 | ctx := req.Context() 764 | pluginContext := httpadapter.PluginConfigFromContext(ctx) 765 | urlQuery := req.URL.Query() 766 | region := urlQuery.Get("region") 767 | pattern := urlQuery.Get("pattern") 768 | limit, err := strconv.ParseInt(urlQuery.Get("limit"), 10, 64) 769 | if err != nil { 770 | writeResult(rw, "?", nil, err) 771 | return 772 | } 773 | workGroup := urlQuery.Get("workGroup") 774 | 775 | to, err := time.Parse(time.RFC3339, urlQuery.Get("to")) 776 | if err != nil { 777 | writeResult(rw, "?", nil, err) 778 | return 779 | } 780 | 781 | namedQueryQueries, err := ds.getNamedQueryQueries(ctx, pluginContext, region, workGroup, pattern) 782 | if err != nil { 783 | writeResult(rw, "?", nil, err) 784 | return 785 | } 786 | //if we did not find the named query based on the string, we return nil 787 | if len(namedQueryQueries) == 0 { 788 | writeResult(rw, "?", nil, errors.New("No query with that name found")) 789 | return 790 | } 791 | sql := namedQueryQueries[0] 792 | sql = strings.TrimRight(sql, " ") 793 | sql = strings.TrimRight(sql, ";") 794 | 795 | queryExecutions, err := ds.getQueryExecutions(ctx, pluginContext, region, workGroup, "^"+sql+"$", to) 796 | if err != nil { 797 | writeResult(rw, "?", nil, err) 798 | return 799 | } 800 | 801 | if limit != -1 { 802 | limit = int64(math.Min(float64(limit), float64(len(queryExecutions)))) 803 | queryExecutions = queryExecutions[0:limit] 804 | } 805 | 806 | writeResult(rw, "query_executions_by_name", queryExecutions, err) 807 | } 808 | 809 | type Duration time.Duration 810 | 811 | func (d *Duration) UnmarshalJSON(b []byte) error { 812 | var v interface{} 813 | if err := json.Unmarshal(b, &v); err != nil { 814 | return err 815 | } 816 | switch value := v.(type) { 817 | case string: 818 | if value == "" { 819 | value = "0s" 820 | } 821 | tmp, err := time.ParseDuration(value) 822 | if err != nil { 823 | return err 824 | } 825 | *d = Duration(tmp) 826 | return nil 827 | default: 828 | return errors.New("invalid duration") 829 | } 830 | } 831 | -------------------------------------------------------------------------------- /pkg/datasource_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "testing" 6 | "time" 7 | 8 | "github.com/aws/aws-sdk-go/aws" 9 | "github.com/aws/aws-sdk-go/service/athena" 10 | "github.com/grafana/grafana-plugin-sdk-go/backend" 11 | "golang.org/x/net/context" 12 | "gotest.tools/assert" 13 | ) 14 | 15 | func TestAwsAthenaDatasource(t *testing.T) { 16 | t.Run("QueryData", func(t *testing.T) { 17 | t.Run("simple query", func(t *testing.T) { 18 | ctx := context.Background() 19 | q, _ := json.Marshal(Target{ 20 | RefId: "A", 21 | Format: "timeserie", 22 | Region: "us-east-1", 23 | Inputs: []athena.GetQueryResultsInput{ 24 | athena.GetQueryResultsInput{ 25 | QueryExecutionId: aws.String("43bcaae3-22f0-4dcf-a861-bbab3084d6a2"), 26 | }, 27 | }, 28 | TimestampColumn: "ts", 29 | ValueColumn: "_col2", 30 | LegendFormat: "", 31 | timeFormat: "", 32 | From: time.Now().Add(time.Duration(-24) * time.Hour), 33 | To: time.Now(), 34 | }) 35 | query := &backend.QueryDataRequest{ 36 | PluginContext: backend.PluginContext{ 37 | DataSourceInstanceSettings: &backend.DataSourceInstanceSettings{ 38 | JSONData: []byte("{}"), 39 | }, 40 | }, 41 | Queries: []backend.DataQuery{ 42 | backend.DataQuery{ 43 | JSON: q, 44 | }, 45 | }, 46 | } 47 | ds := &AwsAthenaDatasource{} 48 | result, err := ds.QueryData(ctx, query) 49 | assert.Equal(t, nil, err) 50 | r := result.Responses["A"].Frames[0].Fields[0].CopyAt(0) 51 | s, ok := r.(string) 52 | assert.Equal(t, true, ok) 53 | assert.Equal(t, "2020-06-08T17:00:00.000000000Z", s) 54 | }) 55 | }) 56 | 57 | t.Run("parseResponse", func(t *testing.T) { 58 | t.Run("simple response", func(t *testing.T) { 59 | response := &athena.GetQueryResultsOutput{ 60 | ResultSet: &athena.ResultSet{ 61 | ResultSetMetadata: &athena.ResultSetMetadata{ 62 | ColumnInfo: []*athena.ColumnInfo{ 63 | &athena.ColumnInfo{ 64 | Name: aws.String("timestamp"), 65 | Label: aws.String("timestamp"), 66 | Type: aws.String("timestamp"), 67 | }, 68 | &athena.ColumnInfo{ 69 | Name: aws.String("value"), 70 | Label: aws.String("value"), 71 | Type: aws.String("bigint"), 72 | }, 73 | }, 74 | }, 75 | Rows: []*athena.Row{ 76 | &athena.Row{ 77 | Data: []*athena.Datum{ 78 | &athena.Datum{ 79 | VarCharValue: aws.String("2006-01-02 01:04:05.000"), 80 | }, 81 | &athena.Datum{ 82 | VarCharValue: aws.String("100"), 83 | }, 84 | }, 85 | }, 86 | &athena.Row{ 87 | Data: []*athena.Datum{ 88 | &athena.Datum{ 89 | VarCharValue: aws.String("2006-01-02 02:04:05.000"), 90 | }, 91 | &athena.Datum{ 92 | VarCharValue: aws.String("200"), 93 | }, 94 | }, 95 | }, 96 | }, 97 | }, 98 | } 99 | 100 | from, _ := time.Parse("2006-01-02 15:04:05.000", "2006-01-02 00:04:05.000") 101 | to, _ := time.Parse("2006-01-02 15:04:05.000", "2006-01-02 23:04:05.000") 102 | frames, err := parseResponse(response, "A", from, to, "timestamp", "value", "", "2006-01-02 15:04:05.000") 103 | assert.Equal(t, nil, err) 104 | assert.Equal(t, "A", frames[0].RefID) 105 | assert.Equal(t, "timestamp", frames[0].Fields[0].Name) 106 | assert.Equal(t, "value", frames[0].Fields[1].Name) 107 | assert.Equal(t, float64(100), frames[0].Fields[1].At(0)) 108 | assert.Equal(t, float64(200), frames[0].Fields[1].At(1)) 109 | et1, _ := time.Parse("2006-01-02 15:04:05.000", "2006-01-02 01:04:05.000") 110 | t1, ok := frames[0].Fields[0].At(0).(*time.Time) 111 | assert.Equal(t, true, ok) 112 | assert.Equal(t, et1, *t1) 113 | et2, _ := time.Parse("2006-01-02 15:04:05.000", "2006-01-02 02:04:05.000") 114 | t2, ok := frames[0].Fields[0].At(1).(*time.Time) 115 | assert.Equal(t, true, ok) 116 | assert.Equal(t, et2, *t2) 117 | }) 118 | }) 119 | } 120 | -------------------------------------------------------------------------------- /pkg/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | "os" 6 | 7 | "github.com/grafana/grafana-plugin-sdk-go/backend" 8 | "github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter" 9 | ) 10 | 11 | func main() { 12 | backend.SetupPluginEnvironment("mtanda-aws-athena-datasource") 13 | 14 | mux := http.NewServeMux() 15 | ds := NewDataSource(mux) 16 | httpResourceHandler := httpadapter.New(mux) 17 | 18 | err := backend.Serve(backend.ServeOpts{ 19 | CallResourceHandler: httpResourceHandler, 20 | QueryDataHandler: ds, 21 | CheckHealthHandler: ds, 22 | }) 23 | if err != nil { 24 | backend.Logger.Error(err.Error()) 25 | os.Exit(1) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pkg/query.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | "strconv" 7 | "time" 8 | 9 | "github.com/aws/aws-sdk-go/aws" 10 | "github.com/aws/aws-sdk-go/aws/awserr" 11 | "github.com/aws/aws-sdk-go/service/athena" 12 | "github.com/grafana/grafana-plugin-sdk-go/backend" 13 | "github.com/patrickmn/go-cache" 14 | "github.com/prometheus/client_golang/prometheus" 15 | "golang.org/x/net/context" 16 | ) 17 | 18 | type AwsAthenaQuery struct { 19 | client *athena.Athena 20 | cache *cache.Cache 21 | metrics *AwsAthenaMetrics 22 | datasourceID int64 23 | waitQueryExecutionIds []*string 24 | RefId string 25 | Region string 26 | Inputs []athena.GetQueryResultsInput 27 | TimestampColumn string 28 | ValueColumn string 29 | LegendFormat string 30 | TimeFormat string 31 | MaxRows string 32 | CacheDuration Duration 33 | WorkGroup string 34 | QueryString string 35 | OutputLocation string 36 | From time.Time 37 | To time.Time 38 | } 39 | 40 | func (query *AwsAthenaQuery) getQueryResults(ctx context.Context, pluginContext backend.PluginContext) (*athena.GetQueryResultsOutput, error) { 41 | var err error 42 | 43 | if query.QueryString == "" { 44 | dedupe := true // TODO: add query option? 45 | if dedupe { 46 | allQueryExecution := make([]*athena.QueryExecution, 0) 47 | for i := 0; i < len(query.Inputs); i += AWS_API_RESULT_MAX_LENGTH { 48 | e := int64(math.Min(float64(i+AWS_API_RESULT_MAX_LENGTH), float64(len(query.Inputs)))) 49 | bi := &athena.BatchGetQueryExecutionInput{} 50 | for _, input := range query.Inputs[i:e] { 51 | bi.QueryExecutionIds = append(bi.QueryExecutionIds, input.QueryExecutionId) 52 | } 53 | bo, err := query.client.BatchGetQueryExecutionWithContext(ctx, bi) 54 | if aerr, ok := err.(awserr.Error); ok && aerr.Code() == athena.ErrCodeInvalidRequestException { 55 | backend.Logger.Warn("Batch Get Query Execution Warning", "warn", aerr.Message()) 56 | bo = &athena.BatchGetQueryExecutionOutput{QueryExecutions: make([]*athena.QueryExecution, 0)} 57 | } else if err != nil { 58 | return nil, err 59 | } 60 | allQueryExecution = append(allQueryExecution, bo.QueryExecutions...) 61 | } 62 | 63 | dupCheck := make(map[string]bool) 64 | query.Inputs = make([]athena.GetQueryResultsInput, 0) 65 | for _, q := range allQueryExecution { 66 | if _, dup := dupCheck[*q.Query]; dup { 67 | continue 68 | } 69 | dupCheck[*q.Query] = true 70 | query.Inputs = append(query.Inputs, athena.GetQueryResultsInput{ 71 | QueryExecutionId: q.QueryExecutionId, 72 | }) 73 | } 74 | } 75 | } else { 76 | workgroup, err := query.getWorkgroup(ctx, pluginContext, query.Region, query.WorkGroup) 77 | if err != nil { 78 | return nil, err 79 | } 80 | if workgroup.WorkGroup.Configuration.BytesScannedCutoffPerQuery == nil { 81 | return nil, fmt.Errorf("should set scan data limit") 82 | } 83 | 84 | queryExecutionID, err := query.startQueryExecution(ctx) 85 | if err != nil { 86 | return nil, err 87 | } 88 | 89 | query.Inputs = append(query.Inputs, athena.GetQueryResultsInput{ 90 | QueryExecutionId: aws.String(queryExecutionID), 91 | }) 92 | } 93 | 94 | // wait until query completed 95 | if len(query.waitQueryExecutionIds) > 0 { 96 | if err := query.waitForQueryCompleted(ctx, query.waitQueryExecutionIds); err != nil { 97 | return nil, err 98 | } 99 | } 100 | 101 | maxRows := int64(DEFAULT_MAX_ROWS) 102 | if query.MaxRows != "" { 103 | maxRows, err = strconv.ParseInt(query.MaxRows, 10, 64) 104 | if err != nil { 105 | return nil, err 106 | } 107 | } 108 | result := athena.GetQueryResultsOutput{ 109 | ResultSet: &athena.ResultSet{ 110 | Rows: make([]*athena.Row, 0), 111 | ResultSetMetadata: &athena.ResultSetMetadata{ 112 | ColumnInfo: make([]*athena.ColumnInfo, 0), 113 | }, 114 | }, 115 | } 116 | for _, input := range query.Inputs { 117 | var resp *athena.GetQueryResultsOutput 118 | 119 | cacheKey := "QueryResults/" + strconv.FormatInt(pluginContext.DataSourceInstanceSettings.ID, 10) + "/" + query.Region + "/" + *input.QueryExecutionId + "/" + query.MaxRows 120 | if item, _, found := query.cache.GetWithExpiration(cacheKey); found && query.CacheDuration > 0 { 121 | if r, ok := item.(*athena.GetQueryResultsOutput); ok { 122 | resp = r 123 | } 124 | } else { 125 | err := query.client.GetQueryResultsPagesWithContext(ctx, &input, 126 | func(page *athena.GetQueryResultsOutput, lastPage bool) bool { 127 | query.metrics.queriesTotal.With(prometheus.Labels{"region": query.Region}).Inc() 128 | if resp == nil { 129 | resp = page 130 | } else { 131 | resp.ResultSet.Rows = append(resp.ResultSet.Rows, page.ResultSet.Rows...) 132 | } 133 | // result include extra header row, +1 here 134 | if maxRows != -1 && int64(len(resp.ResultSet.Rows)) > maxRows+1 { 135 | resp.ResultSet.Rows = resp.ResultSet.Rows[0 : maxRows+1] 136 | return false 137 | } 138 | return !lastPage 139 | }) 140 | if aerr, ok := err.(awserr.Error); ok && aerr.Code() == athena.ErrCodeInvalidRequestException { 141 | backend.Logger.Warn("Get Query Results Warning", "warn", aerr.Message()) 142 | } else if err != nil { 143 | return nil, err 144 | } 145 | 146 | if query.CacheDuration > 0 { 147 | query.cache.Set(cacheKey, resp, time.Duration(query.CacheDuration)*time.Second) 148 | } 149 | } 150 | 151 | if resp == nil { 152 | continue 153 | } 154 | 155 | result.ResultSet.ResultSetMetadata = resp.ResultSet.ResultSetMetadata 156 | result.ResultSet.Rows = append(result.ResultSet.Rows, resp.ResultSet.Rows[1:]...) // trim header row 157 | } 158 | 159 | return &result, nil 160 | } 161 | 162 | func (query *AwsAthenaQuery) getWorkgroup(ctx context.Context, pluginContext backend.PluginContext, region string, workGroup string) (*athena.GetWorkGroupOutput, error) { 163 | WorkgroupCacheKey := "Workgroup/" + strconv.FormatInt(pluginContext.DataSourceInstanceSettings.ID, 10) + "/" + region + "/" + workGroup 164 | if item, _, found := query.cache.GetWithExpiration(WorkgroupCacheKey); found { 165 | if workgroup, ok := item.(*athena.GetWorkGroupOutput); ok { 166 | return workgroup, nil 167 | } 168 | } 169 | workgroup, err := query.client.GetWorkGroupWithContext(ctx, &athena.GetWorkGroupInput{WorkGroup: aws.String(workGroup)}) 170 | if err != nil { 171 | return nil, err 172 | } 173 | query.cache.Set(WorkgroupCacheKey, workgroup, time.Duration(5)*time.Minute) 174 | 175 | return workgroup, nil 176 | } 177 | 178 | func (query *AwsAthenaQuery) startQueryExecution(ctx context.Context) (string, error) { 179 | // cache instant query result by query string 180 | var queryExecutionID string 181 | cacheKey := "StartQueryExecution/" + strconv.FormatInt(query.datasourceID, 10) + "/" + query.Region + "/" + query.QueryString + "/" + query.MaxRows 182 | if item, _, found := query.cache.GetWithExpiration(cacheKey); found && query.CacheDuration > 0 { 183 | if id, ok := item.(string); ok { 184 | queryExecutionID = id 185 | } 186 | } else { 187 | si := &athena.StartQueryExecutionInput{ 188 | QueryString: aws.String(query.QueryString), 189 | WorkGroup: aws.String(query.WorkGroup), 190 | ResultConfiguration: &athena.ResultConfiguration{ 191 | OutputLocation: aws.String(query.OutputLocation), 192 | }, 193 | } 194 | so, err := query.client.StartQueryExecutionWithContext(ctx, si) 195 | if err != nil { 196 | return "", err 197 | } 198 | queryExecutionID = *so.QueryExecutionId 199 | if query.CacheDuration > 0 { 200 | query.cache.Set(cacheKey, queryExecutionID, time.Duration(query.CacheDuration)*time.Second) 201 | } 202 | query.waitQueryExecutionIds = append(query.waitQueryExecutionIds, &queryExecutionID) 203 | } 204 | return queryExecutionID, nil 205 | } 206 | 207 | func (query *AwsAthenaQuery) waitForQueryCompleted(ctx context.Context, waitQueryExecutionIds []*string) error { 208 | for i := 0; i < QUERY_WAIT_COUNT; i++ { 209 | completeCount := 0 210 | bi := &athena.BatchGetQueryExecutionInput{QueryExecutionIds: waitQueryExecutionIds} 211 | bo, err := query.client.BatchGetQueryExecutionWithContext(ctx, bi) 212 | if err != nil { 213 | return err 214 | } 215 | for _, e := range bo.QueryExecutions { 216 | // TODO: add warning for FAILED or CANCELLED 217 | if !(*e.Status.State == "QUEUED" || *e.Status.State == "RUNNING") { 218 | completeCount++ 219 | } 220 | } 221 | if len(waitQueryExecutionIds) == completeCount { 222 | for _, e := range bo.QueryExecutions { 223 | query.metrics.dataScannedBytesTotal.With(prometheus.Labels{"region": query.Region}).Add(float64(*e.Statistics.DataScannedInBytes)) 224 | } 225 | break 226 | } else { 227 | time.Sleep(1 * time.Second) 228 | } 229 | } 230 | return nil 231 | } 232 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | ## AWS Athena Datasource Plugin for Grafana 2 | 3 | ### Features: 4 | * Graph/Table view 5 | * Cache query result 6 | * Post query to AWS Athena (experimental) 7 | 8 | ### Setup 9 | #### Install Plugin 10 | Follow [Installing Plugins Manually](https://grafana.com/docs/plugins/installation/) steps, and install plugin from released zip file. 11 | 12 | #### IAM Policy 13 | Allow following API for IAM User/Role. 14 | 15 | - athena:GetQueryResults 16 | - athena:BatchGetNamedQuery 17 | - athena:BatchGetQueryExecution 18 | - athena:ListNamedQueries 19 | - athena:ListQueryExecutions 20 | - athena:ListWorkGroups 21 | 22 | If use experimental query posting feature, allow following. 23 | - athena:StartQueryExecution 24 | - athena:GetWorkGroup 25 | 26 | ### Adding the DataSource to Grafana 27 | See also CloudWatch DataSource Authentication doc to setup datasource. 28 | https://grafana.com/docs/grafana/latest/features/datasources/cloudwatch/#authentication 29 | 30 | | Name | Description | 31 | | -------------------------- | ------------------------------------------------------------------------------------------------------- | 32 | | _Name_ | The data source name. This is how you refer to the data source in panels and queries. | 33 | | _Default Region_ | Used in query editor to set region (can be changed on per query basis) | 34 | | _Auth Provider_ | Specify the provider to get credentials. | 35 | | _Credentials_ profile name | Specify the name of the profile to use (if you use `~/.aws/credentials` file), leave blank for default. | 36 | | _Assume Role Arn_ | Specify the ARN of the role to assume | 37 | | _Output Location_ | Specify the S3 Output Location for Athena query result. (experimental feature) | 38 | 39 | ### Query 40 | #### Query Editor 41 | 42 | | Name | Description | 43 | | -------------------------- | ------------------------------------------------------------------------------------------------------- | 44 | | _Region_ | Specify the Region. (To use default region, specify "default") | 45 | | _Work Group_ | Specify the Work Group. (Work as filter for query execution id, or posting target workgroup) | 46 | | _Query Execution Id_ | Specify the comma separated Query Execution Ids to get result. (result format should be same) | 47 | | _Query String_ | Specify the AWS Athena Query. (experimental) | 48 | | _Legend Format_ | Specify the Legend Format. | 49 | | _Max Rows_ | Specify the Max Rows to get result. (default is 1000, -1 is unlimited) | 50 | | _Cache Duration_ | Specify the Cache Duration for caching query result. (cache key is query execution id and max rows) | 51 | | _Timestamp Column_ | Specify the Timestamp Column for time series. | 52 | | _Value Column_ | Specify the Value Column for time series. | 53 | | _Time Format_ | Specify the Time Format of Timestamp column. (default format is RFC3339) | 54 | 55 | #### Query variable 56 | 57 | | Name | Description | 58 | | --------------------------------------------------------------------------- | -------------------------------------------------------------------------- | 59 | | *regions()* | Returns a list of regions. | 60 | | *workgroup_names(region)* | Returns a list of workgroup names. | 61 | | *named_query_names(region, work_group?)* | Returns a list of named query names. | 62 | | *named_query_queries(region, pattern, work_group?)* | Returns a list of named query expressions which name match `pattern`. | 63 | | *query_execution_ids(region, limit, pattern, work_group?)* | Returns a list of query execution ids which query match `pattern`. | 64 | | *query_execution_ids_by_name(region, limit, named query name, work_group?)* | Returns a list of query execution ids which query match named query query. | 65 | 66 | If a `work_group` is specified, result is filtered by that work_group. 67 | The `query_execution_ids()` and `query_execution_ids_by_name()` results are always sorted by `CompletionDateTime` in descending order. 68 | 69 | ### Caution 70 | This plugin experimentally support posting query. 71 | To use the feature, set S3 output location in datasource settings. 72 | 73 | And, limit data usage in workgroup settings. 74 | https://docs.aws.amazon.com/athena/latest/ug/workgroups-setting-control-limits-cloudwatch.html 75 | 76 | Every time when opening dashboard, Grafana post query without user acknowledgement, so it may cause too much AWS cost. 77 | Please use carefully posting feature. 78 | -------------------------------------------------------------------------------- /src/components/ConfigEditor.tsx: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | import { InlineFormLabel, LegacyForms, Button } from '@grafana/ui'; 3 | const { Select, Input } = LegacyForms; 4 | import { 5 | DataSourcePluginOptionsEditorProps, 6 | SelectableValue, 7 | onUpdateDatasourceJsonDataOptionSelect, 8 | onUpdateDatasourceResetOption, 9 | onUpdateDatasourceJsonDataOption, 10 | onUpdateDatasourceSecureJsonDataOption, 11 | } from '@grafana/data'; 12 | import { AwsAthenaOptions, AwsAthenaSecureJsonData } from '../types'; 13 | 14 | const authProviderOptions: Array> = [ 15 | { label: 'Access & secret key', value: 'keys' }, 16 | { label: 'Credentials file', value: 'credentials' }, 17 | { label: 'ARN', value: 'arn' }, 18 | ]; 19 | 20 | const regions: Array> = [ 21 | 'ap-east-1', 22 | 'ap-northeast-1', 23 | 'ap-northeast-2', 24 | 'ap-northeast-3', 25 | 'ap-south-1', 26 | 'ap-southeast-1', 27 | 'ap-southeast-2', 28 | 'ca-central-1', 29 | 'cn-north-1', 30 | 'cn-northwest-1', 31 | 'eu-central-1', 32 | 'eu-north-1', 33 | 'eu-west-1', 34 | 'eu-west-2', 35 | 'eu-west-3', 36 | 'me-south-1', 37 | 'sa-east-1', 38 | 'us-east-1', 39 | 'us-east-2', 40 | 'us-gov-east-1', 41 | 'us-gov-west-1', 42 | 'us-iso-east-1', 43 | 'us-isob-east-1', 44 | 'us-west-1', 45 | 'us-west-2', 46 | ].map(r => { 47 | return { label: r, value: r }; 48 | }); 49 | 50 | export type Props = DataSourcePluginOptionsEditorProps; 51 | 52 | export class ConfigEditor extends PureComponent { 53 | constructor(props: Props) { 54 | super(props); 55 | } 56 | 57 | render() { 58 | const { options } = this.props; 59 | const secureJsonData = (options.secureJsonData || {}) as AwsAthenaSecureJsonData; 60 | 61 | return ( 62 | <> 63 |

Aws Athena Details

64 |
65 |
66 |
67 | Auth Provider 68 | 98 |
99 |
100 |
101 | )} 102 | {options.jsonData.authType === 'keys' && ( 103 |
104 | {options.secureJsonFields?.accessKey ? ( 105 |
106 |
107 | Access Key ID 108 | 109 |
110 |
111 |
112 | 119 |
120 |
121 |
122 | ) : ( 123 |
124 |
125 | Access Key ID 126 |
127 | 132 |
133 |
134 |
135 | )} 136 | {options.secureJsonFields?.secretKey ? ( 137 |
138 |
139 | Secret Access Key 140 | 141 |
142 |
143 |
144 | 151 |
152 |
153 |
154 | ) : ( 155 |
156 |
157 | Secret Access Key 158 |
159 | 164 |
165 |
166 |
167 | )} 168 |
169 | )} 170 | {options.jsonData.authType === 'arn' && ( 171 |
172 |
173 | 174 | Assume Role ARN 175 | 176 |
177 | 183 |
184 |
185 |
186 | )} 187 |
188 |
189 | 193 | Default Region 194 | 195 | 214 |
215 |
216 | 217 | 218 | 219 | ); 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /src/components/QueryEditor.tsx: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | import { QueryEditorProps } from '@grafana/data'; 3 | import { InlineFormLabel, SegmentAsync, QueryField } from '@grafana/ui'; 4 | import { DataSource } from '../datasource'; 5 | import { AwsAthenaQuery, AwsAthenaOptions } from '../types'; 6 | 7 | type Props = QueryEditorProps; 8 | 9 | interface State { 10 | region: string; 11 | workgroup: string; 12 | queryExecutionId: string; 13 | timestampColumn: string; 14 | valueColumn: string; 15 | legendFormat: string; 16 | timeFormat: string; 17 | maxRows: string; 18 | cacheDuration: string; 19 | queryString: string; 20 | } 21 | 22 | export class QueryEditor extends PureComponent { 23 | query: AwsAthenaQuery; 24 | 25 | constructor(props: Props) { 26 | super(props); 27 | const defaultQuery: Partial = { 28 | region: 'default', 29 | workgroup: '', 30 | queryExecutionId: '', 31 | timestampColumn: '', 32 | valueColumn: '', 33 | legendFormat: '', 34 | timeFormat: '', 35 | maxRows: '', 36 | cacheDuration: '', 37 | queryString: '', 38 | }; 39 | const query = Object.assign({}, defaultQuery, props.query); 40 | this.query = query; 41 | this.state = { 42 | region: query.region, 43 | workgroup: query.workgroup, 44 | queryExecutionId: query.queryExecutionId, 45 | timestampColumn: query.timestampColumn, 46 | valueColumn: query.valueColumn, 47 | legendFormat: query.legendFormat, 48 | timeFormat: query.timeFormat, 49 | maxRows: query.maxRows, 50 | cacheDuration: query.cacheDuration, 51 | queryString: query.queryString, 52 | }; 53 | } 54 | 55 | onRegionChange = (item: any) => { 56 | const { query, onChange, onRunQuery } = this.props; 57 | let region = 'default'; 58 | if (item.value) { 59 | region = item.value; 60 | } 61 | this.query.region = region; 62 | this.setState({ region }); 63 | if (onChange) { 64 | onChange({ ...query, region: region }); 65 | if (onRunQuery) { 66 | onRunQuery(); 67 | } 68 | } 69 | }; 70 | 71 | onWorkgroupChange = (item: any) => { 72 | const { query, onChange, onRunQuery } = this.props; 73 | let workgroup = 'primary'; 74 | if (item.value) { 75 | workgroup = item.value; 76 | } 77 | this.query.workgroup = workgroup; 78 | this.setState({ workgroup }); 79 | if (onChange) { 80 | onChange({ ...query, workgroup: workgroup }); 81 | if (onRunQuery && query.queryString !== '') { 82 | onRunQuery(); 83 | } 84 | } 85 | }; 86 | 87 | onQueryExecutionIdChange = (item: any) => { 88 | const { query, onChange, onRunQuery } = this.props; 89 | if (!item.value) { 90 | return; 91 | } 92 | const queryExecutionId = item.value; 93 | this.query.queryExecutionId = queryExecutionId; 94 | this.setState({ queryExecutionId }); 95 | if (onChange) { 96 | onChange({ ...query, queryExecutionId: queryExecutionId }); 97 | if (onRunQuery) { 98 | onRunQuery(); 99 | } 100 | } 101 | }; 102 | 103 | onTimestampColumnChange = (e: React.SyntheticEvent) => { 104 | const timestampColumn = e.currentTarget.value; 105 | this.query.timestampColumn = timestampColumn; 106 | this.setState({ timestampColumn }); 107 | }; 108 | 109 | onValueColumnChange = (e: React.SyntheticEvent) => { 110 | const valueColumn = e.currentTarget.value; 111 | this.query.valueColumn = valueColumn; 112 | this.setState({ valueColumn }); 113 | }; 114 | 115 | onLegendFormatChange = (e: React.SyntheticEvent) => { 116 | const legendFormat = e.currentTarget.value; 117 | this.query.legendFormat = legendFormat; 118 | this.setState({ legendFormat }); 119 | }; 120 | 121 | onTimeFormatChange = (e: React.SyntheticEvent) => { 122 | const timeFormat = e.currentTarget.value; 123 | this.query.timeFormat = timeFormat; 124 | this.setState({ timeFormat }); 125 | }; 126 | 127 | onMaxRowsChange = (e: React.SyntheticEvent) => { 128 | const maxRows = e.currentTarget.value; 129 | this.query.maxRows = maxRows; 130 | this.setState({ maxRows }); 131 | }; 132 | 133 | onCacheDurationChange = (e: React.SyntheticEvent) => { 134 | const cacheDuration = e.currentTarget.value; 135 | this.query.cacheDuration = cacheDuration; 136 | this.setState({ cacheDuration }); 137 | }; 138 | 139 | onQueryStringChange = (value: string, override?: boolean) => { 140 | const { query, onChange, onRunQuery } = this.props; 141 | const queryString = value; 142 | this.query.queryString = queryString; 143 | this.setState({ queryString }); 144 | if (onChange) { 145 | onChange({ ...query, queryString: queryString }); 146 | if (override && onRunQuery) { 147 | onRunQuery(); 148 | } 149 | } 150 | }; 151 | 152 | onRunQuery = () => { 153 | const { query } = this; 154 | this.props.onChange(query); 155 | this.props.onRunQuery(); 156 | }; 157 | 158 | render() { 159 | const { datasource } = this.props; 160 | const { 161 | region, 162 | workgroup, 163 | queryExecutionId, 164 | timestampColumn, 165 | valueColumn, 166 | legendFormat, 167 | timeFormat, 168 | maxRows, 169 | cacheDuration, 170 | queryString, 171 | } = this.state; 172 | return ( 173 | <> 174 |
175 |
176 | Region 177 | datasource.getRegionOptions()} 179 | placeholder="Enter Region" 180 | value={region} 181 | allowCustomValue={true} 182 | onChange={this.onRegionChange} 183 | > 184 |
185 | 186 |
187 | Workgroup 188 | datasource.getWorkgroupNameOptions(region)} 190 | placeholder="Enter Workgroup" 191 | value={workgroup} 192 | allowCustomValue={true} 193 | onChange={this.onWorkgroupChange} 194 | > 195 |
196 |
197 | 198 | {queryString === '' && ( 199 |
200 |
201 | Query Execution Id 202 | datasource.getQueryExecutionIdOptions(region, workgroup)} 204 | placeholder="Enter Query Execution Id" 205 | value={queryExecutionId} 206 | allowCustomValue={true} 207 | onChange={this.onQueryExecutionIdChange} 208 | > 209 |
210 |
211 | )} 212 | 213 | {datasource.outputLocation !== '' && ( 214 |
215 |
216 | Query String 217 | 225 |
226 |
227 | )} 228 | 229 |
230 |
231 | Legend Format 232 | 240 |
241 | 242 |
243 | Max Rows 244 | 252 |
253 | 254 |
255 | Cache Duration 256 | 264 |
265 |
266 | 267 |
268 |
269 | Timestamp Column 270 | 278 |
279 | 280 |
281 | Value Column 282 | 290 |
291 | 292 |
293 | Time Format 294 | 302 |
303 |
304 | 305 | ); 306 | } 307 | } 308 | -------------------------------------------------------------------------------- /src/components/index.ts: -------------------------------------------------------------------------------- 1 | export { QueryEditor } from './QueryEditor'; 2 | export { ConfigEditor } from './ConfigEditor'; 3 | -------------------------------------------------------------------------------- /src/datasource.ts: -------------------------------------------------------------------------------- 1 | import { DataSourceInstanceSettings, MetricFindValue, SelectableValue, ScopedVars } from '@grafana/data'; 2 | import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime'; 3 | import { AwsAthenaQuery, AwsAthenaOptions } from './types'; 4 | 5 | export class DataSource extends DataSourceWithBackend { 6 | defaultRegion: string; 7 | outputLocation: string; 8 | 9 | constructor(instanceSettings: DataSourceInstanceSettings) { 10 | super(instanceSettings); 11 | this.defaultRegion = instanceSettings.jsonData.defaultRegion || 'us-east-1'; 12 | this.outputLocation = instanceSettings.jsonData.outputLocation; 13 | } 14 | 15 | applyTemplateVariables(query: AwsAthenaQuery, scopedVars: ScopedVars) { 16 | // TODO: pass scopedVars to templateSrv.replace() 17 | const templateSrv = getTemplateSrv(); 18 | query.region = templateSrv.replace(query.region, scopedVars); 19 | query.maxRows = query.maxRows || ''; 20 | query.cacheDuration = query.cacheDuration || ''; 21 | if (typeof query.queryString === 'undefined' || query.queryString === '') { 22 | query.queryExecutionId = templateSrv.replace(query.queryExecutionId, scopedVars); 23 | query.inputs = query.queryExecutionId.split(/,/).map(id => { 24 | return { 25 | queryExecutionId: id, 26 | }; 27 | }); 28 | } else { 29 | query.queryExecutionId = ''; 30 | query.inputs = []; 31 | } 32 | query.queryString = templateSrv.replace(query.queryString, scopedVars) || ''; 33 | query.outputLocation = this.outputLocation; 34 | return query; 35 | } 36 | 37 | async getRegionOptions(): Promise>> { 38 | const regions = await this.getRegions(); 39 | return regions.map(name => ({ label: name, value: name } as SelectableValue)); 40 | } 41 | 42 | async getRegions(): Promise { 43 | return (await this.getResource('regions'))['regions']; 44 | } 45 | 46 | async getWorkgroupNameOptions(region: string): Promise>> { 47 | const workgroupNames = await this.getWorkgroupNames(region); 48 | return workgroupNames.map(name => ({ label: name, value: name } as SelectableValue)); 49 | } 50 | 51 | async getWorkgroupNames(region: string): Promise { 52 | return (await this.getResource('workgroup_names', { region: region }))['workgroup_names']; 53 | } 54 | 55 | async getNamedQueryNames(region: string, workGroup: string): Promise { 56 | return (await this.getResource('named_query_names', { region: region, workGroup: workGroup }))['named_query_names']; 57 | } 58 | 59 | async getNamedQueryQueries(region: string, pattern: string, workGroup: string): Promise { 60 | return (await this.getResource('named_query_queries', { region: region, pattern: pattern, workGroup: workGroup }))[ 61 | 'named_query_queries' 62 | ]; 63 | } 64 | 65 | async getQueryExecutionIdOptions(region: string, workgroup: string): Promise>> { 66 | const templateSrv = getTemplateSrv(); 67 | const to = new Date(parseInt(templateSrv.replace('$__to'), 10)).toISOString(); 68 | const queryExecutions = await this.getQueryExecutions(region, -1, '.*', workgroup, to); 69 | return queryExecutions.map(e => { 70 | const id = e.QueryExecutionId; 71 | const query = e.Query; 72 | const completionDateTime = e.Status.CompletionDateTime; 73 | const label = `${completionDateTime} ${id} ${query}`; 74 | return { label: label, value: id } as SelectableValue; 75 | }); 76 | } 77 | 78 | async getQueryExecutions( 79 | region: string, 80 | limit: number, 81 | pattern: string, 82 | workGroup: string, 83 | to: string 84 | ): Promise { 85 | return ( 86 | await this.getResource('query_executions', { 87 | region: region, 88 | limit: limit, 89 | pattern: pattern, 90 | workGroup: workGroup, 91 | to: to, 92 | }) 93 | )['query_executions']; 94 | } 95 | 96 | async getQueryExecutionsByName( 97 | region: string, 98 | limit: number, 99 | pattern: string, 100 | workGroup: string, 101 | to: string 102 | ): Promise { 103 | return ( 104 | await this.getResource('query_executions_by_name', { 105 | region: region, 106 | limit: limit, 107 | pattern: pattern, 108 | workGroup: workGroup, 109 | to: to, 110 | }) 111 | )['query_executions_by_name']; 112 | } 113 | 114 | async metricFindQuery?(query: any, options?: any): Promise { 115 | const templateSrv = getTemplateSrv(); 116 | 117 | const regionsQuery = query.match(/^regions\(\)/); 118 | if (regionsQuery) { 119 | const regions = await this.getRegions(); 120 | return regions.map(n => { 121 | return { text: n, value: n }; 122 | }); 123 | } 124 | 125 | const workgroupNamesQuery = query.match(/^workgroup_names\(([^\)]+?)\)/); 126 | if (workgroupNamesQuery) { 127 | const region = templateSrv.replace(workgroupNamesQuery[1]); 128 | const workgroupNames = await this.getWorkgroupNames(region); 129 | return workgroupNames.map(n => { 130 | return { text: n, value: n }; 131 | }); 132 | } 133 | 134 | const namedQueryNamesQuery = query.match(/^named_query_names\(([^\)]+?)(,\s?.+)?\)/); 135 | if (namedQueryNamesQuery) { 136 | const region = templateSrv.replace(namedQueryNamesQuery[1]); 137 | let workGroup = namedQueryNamesQuery[2]; 138 | if (workGroup) { 139 | workGroup = workGroup.substr(1); //remove the comma 140 | workGroup = workGroup.trim(); 141 | } else { 142 | workGroup = ''; 143 | } 144 | workGroup = templateSrv.replace(workGroup); 145 | const namedQueryNames = await this.getNamedQueryNames(region, workGroup); 146 | return namedQueryNames.map(n => { 147 | return { text: n, value: n }; 148 | }); 149 | } 150 | 151 | const namedQueryQueryQuery = query.match(/^named_query_queries\(([^,]+?),\s?([^,]+)(,\s?.+)?\)/); 152 | if (namedQueryQueryQuery) { 153 | const region = templateSrv.replace(namedQueryQueryQuery[1]); 154 | const pattern = templateSrv.replace(namedQueryQueryQuery[2], {}, 'regex'); 155 | let workGroup = namedQueryQueryQuery[3]; 156 | if (workGroup) { 157 | workGroup = workGroup.substr(1); //remove the comma 158 | workGroup = workGroup.trim(); 159 | } else { 160 | workGroup = ''; 161 | } 162 | workGroup = templateSrv.replace(workGroup); 163 | const namedQueryQueries = await this.getNamedQueryQueries(region, pattern, workGroup); 164 | return namedQueryQueries.map(n => { 165 | return { text: n, value: n }; 166 | }); 167 | } 168 | 169 | const queryExecutionIdsQuery = query.match(/^query_execution_ids\(([^,]+?),\s?([^,]+?),\s?([^,]+)(,\s?.+)?\)/); 170 | if (queryExecutionIdsQuery) { 171 | const region = templateSrv.replace(queryExecutionIdsQuery[1]); 172 | const limit = parseInt(templateSrv.replace(queryExecutionIdsQuery[2]), 10); 173 | const pattern = templateSrv.replace(queryExecutionIdsQuery[3], {}, 'regex'); 174 | let workGroup = queryExecutionIdsQuery[4]; 175 | if (workGroup) { 176 | workGroup = workGroup.substr(1); //remove the comma 177 | workGroup = workGroup.trim(); 178 | } else { 179 | workGroup = ''; 180 | } 181 | workGroup = templateSrv.replace(workGroup); 182 | const to = new Date(parseInt(templateSrv.replace('$__to'), 10)).toISOString(); 183 | 184 | const queryExecutions = await this.getQueryExecutions(region, limit, pattern, workGroup, to); 185 | return queryExecutions.map(n => { 186 | const id = n.QueryExecutionId; 187 | return { text: id, value: id }; 188 | }); 189 | } 190 | 191 | const queryExecutionIdsByNameQuery = query.match( 192 | /^query_execution_ids_by_name\(([^,]+?),\s?([^,]+?),\s?([^,]+)(,\s?.+)?\)/ 193 | ); 194 | if (queryExecutionIdsByNameQuery) { 195 | const region = templateSrv.replace(queryExecutionIdsByNameQuery[1]); 196 | const limit = parseInt(templateSrv.replace(queryExecutionIdsByNameQuery[2]), 10); 197 | const pattern = templateSrv.replace(queryExecutionIdsByNameQuery[3], {}, 'regex'); 198 | let workGroup = queryExecutionIdsByNameQuery[4]; 199 | if (workGroup) { 200 | workGroup = workGroup.substr(1); //remove the comma 201 | workGroup = workGroup.trim(); 202 | } else { 203 | workGroup = ''; 204 | } 205 | workGroup = templateSrv.replace(workGroup); 206 | const to = new Date(parseInt(templateSrv.replace('$__to'), 10)).toISOString(); 207 | 208 | const queryExecutionsByName = await this.getQueryExecutionsByName(region, limit, pattern, workGroup, to); 209 | return queryExecutionsByName.map(n => { 210 | const id = n.QueryExecutionId; 211 | return { text: id, value: id }; 212 | }); 213 | } 214 | 215 | return []; 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/module.ts: -------------------------------------------------------------------------------- 1 | import { DataSource } from './datasource'; 2 | import { DataSourcePlugin } from '@grafana/data'; 3 | import { ConfigEditor, QueryEditor } from './components'; 4 | import { AwsAthenaQuery, AwsAthenaOptions } from './types'; 5 | 6 | export const plugin = new DataSourcePlugin(DataSource) 7 | .setConfigEditor(ConfigEditor) 8 | .setQueryEditor(QueryEditor); 9 | -------------------------------------------------------------------------------- /src/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "AWS Athena datasource", 3 | "id": "mtanda-aws-athena-datasource", 4 | "type": "datasource", 5 | "partials": { 6 | "config": "public/app/plugins/datasource/mtanda-aws-athena-datasource/config.html" 7 | }, 8 | "metrics": true, 9 | "annotations": false, 10 | "hiddenQueries": true, 11 | "backend": true, 12 | "executable": "aws-athena-plugin", 13 | "info": { 14 | "description": "AWS Athena datasource", 15 | "author": { 16 | "name": "Mitsuhiro Tanda" 17 | }, 18 | "links": [ 19 | { 20 | "name": "GitHub", 21 | "url": "https://github.com/mtanda/grafana-aws-athena-datasource" 22 | }, 23 | { 24 | "name": "Apache License", 25 | "url": "https://github.com/mtanda/grafana-aws-athena-datasource/blob/master/LICENSE" 26 | } 27 | ], 28 | "version": "2.2.8", 29 | "updated": "2020-10-04" 30 | }, 31 | "dependencies": { 32 | "grafanaVersion": "7.x.x", 33 | "plugins": [] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import { DataQuery, DataSourceJsonData } from '@grafana/data'; 2 | 3 | export interface AwsAthenaOptions extends DataSourceJsonData { 4 | defaultRegion: string; 5 | profile: string; 6 | assumeRoleArn: string; 7 | outputLocation: string; 8 | } 9 | 10 | export interface AwsAthenaSecureJsonData { 11 | accessKey: string; 12 | secretKey: string; 13 | } 14 | 15 | export enum AwsAuthType { 16 | KEY = 'keys', 17 | CREDENTIALS = 'credentials', 18 | ARN = 'arn', 19 | } 20 | 21 | export interface AwsAthenaQuery extends DataQuery { 22 | refId: string; 23 | region: string; 24 | workgroup: string; 25 | queryExecutionId: string; 26 | inputs: any; 27 | timestampColumn: string; 28 | valueColumn: string; 29 | legendFormat: string; 30 | timeFormat: string; 31 | maxRows: string; 32 | cacheDuration: string; 33 | queryString: string; 34 | outputLocation: string; 35 | } 36 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "target": "es5", 5 | "module": "es6", 6 | "moduleResolution": "node", 7 | "rootDir": "./src", 8 | "jsx": "react", 9 | "lib": [ 10 | "dom", 11 | "es2015", 12 | "es2016" 13 | ], 14 | "declaration": false, 15 | "allowSyntheticDefaultImports": true, 16 | "inlineSourceMap": false, 17 | "sourceMap": true, 18 | "noEmitOnError": false, 19 | "emitDecoratorMetadata": false, 20 | "experimentalDecorators": true, 21 | "noImplicitReturns": true, 22 | "noImplicitThis": false, 23 | "noImplicitUseStrict": false, 24 | "noImplicitAny": false, 25 | "noUnusedLocals": true, 26 | "strictNullChecks": true 27 | }, 28 | "include": [ 29 | "./src/**/*.ts", 30 | "./src/**/*.tsx" 31 | ], 32 | "exclude": [ 33 | "node_modules" 34 | ] 35 | } --------------------------------------------------------------------------------