diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 79a22cbabc5..c01ccc64d70 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -17,7 +17,6 @@ jobs: include: - GOOS: windows - GOOS: linux - - GOOS: darwin name: lint runs-on: ubuntu-latest steps: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 7d0e4395040..67e58e382fe 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -11,6 +11,38 @@ on: - 8.* jobs: + golangci: + runs-on: macos-latest + name: lint + steps: + - uses: actions/checkout@v2 + - name: Fetch Go version from .go-version + run: echo "GO_VERSION=$(cat .go-version)" >> $GITHUB_ENV + - uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + - name: golangci-lint + env: + CGO_ENABLED: 1 + uses: golangci/golangci-lint-action@v2 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.44.2 + + # Give the job more time to execute. + # Regarding `--whole-files`, the linter is supposed to support linting of changed a patch only but, + # for some reason, it's very unreliable this way - sometimes it does not report any or some + # issues without linting the whole files, so we have to use `--whole-files` + # which can lead to some frustration from developers who would like to + # fix a single line in an existing codebase and the linter would force them + # into fixing all linting issues in the whole file instead. + args: --timeout=30m --whole-files + + # Optional: if set to true then the action will use pre-installed Go. + skip-go-installation: true + + # Optional: show only new issues if it's a pull request. The default value is `false`. + only-new-issues: true macos: runs-on: macos-latest steps: diff --git a/.golangci.yml b/.golangci.yml index c6c08105a81..0d4e9e5b454 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,6 +36,7 @@ linters: # 'replace' is used in go.mod for many dependencies that come from libbeat. We should work to remove those, # so we can re-enable this linter. # - gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. + - gomodguard - gosimple # linter for Go source code that specializes in simplifying a code - misspell # finds commonly misspelled English words in comments - nakedret # finds naked returns in functions greater than a specified function length @@ -100,6 +101,14 @@ linters-settings: # Allow local `replace` directives. Default is false. replace-local: false + gomodguard: + blocked: + # List of blocked modules. + modules: + - github.com/elastic/beats/v7: + reason: "There must be no Beats dependency, use elastic-agent-libs instead." + + gosimple: # Select the Go version to target. The default is '1.13'. go: "1.17" diff --git a/NOTICE.txt b/NOTICE.txt index 4a780bf7e78..7daeea9689c 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -607,6 +607,217 @@ or more contributor license agreements. Licensed under the Elastic License; you may not use this file except in compliance with the Elastic License. +-------------------------------------------------------------------------------- +Dependency : github.com/elastic/elastic-agent-autodiscover +Version: v0.0.0-20220404145827-89887023c1ab +Licence type (autodetected): Apache-2.0 +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.0.0-20220404145827-89887023c1ab/LICENSE: + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-client/v7 Version: v7.0.0-20210727140539-f0905d9377f6 @@ -1052,13 +1263,12 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-l -------------------------------------------------------------------------------- -Dependency : github.com/elastic/go-licenser -Version: v0.4.0 +Dependency : github.com/elastic/elastic-agent-system-metrics +Version: v0.1.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/go-licenser@v0.4.0/LICENSE: - +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-system-metrics@v0.1.0/LICENSE.txt: Apache License Version 2.0, January 2004 @@ -1248,7 +1458,7 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-licenser@v0. same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018 Elasticsearch B.V. + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -1264,12 +1474,12 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-licenser@v0. -------------------------------------------------------------------------------- -Dependency : github.com/elastic/go-sysinfo -Version: v1.7.1 +Dependency : github.com/elastic/go-licenser +Version: v0.4.0 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/go-sysinfo@v1.7.1/LICENSE.txt: +Contents of probable licence file $GOMODCACHE/github.com/elastic/go-licenser@v0.4.0/LICENSE: Apache License @@ -1460,7 +1670,7 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-sysinfo@v1.7 same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2018 Elasticsearch B.V. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -1476,12 +1686,13 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-sysinfo@v1.7 -------------------------------------------------------------------------------- -Dependency : github.com/elastic/go-ucfg -Version: v0.8.4 +Dependency : github.com/elastic/go-sysinfo +Version: v1.7.1 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/go-ucfg@v0.8.4/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/go-sysinfo@v1.7.1/LICENSE.txt: + Apache License Version 2.0, January 2004 @@ -1663,7 +1874,7 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-ucfg@v0.8.4/ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" + boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a @@ -1671,7 +1882,7 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-ucfg@v0.8.4/ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -1687,25 +1898,236 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-ucfg@v0.8.4/ -------------------------------------------------------------------------------- -Dependency : github.com/gofrs/flock -Version: v0.8.1 -Licence type (autodetected): BSD-3-Clause +Dependency : github.com/elastic/go-ucfg +Version: v0.8.4 +Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/gofrs/flock@v0.8.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/go-ucfg@v0.8.4/LICENSE: -Copyright (c) 2015-2020, Tim Heckman -All rights reserved. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. + 1. Definitions. -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +-------------------------------------------------------------------------------- +Dependency : github.com/gofrs/flock +Version: v0.8.1 +Licence type (autodetected): BSD-3-Clause +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/gofrs/flock@v0.8.1/LICENSE: + +Copyright (c) 2015-2020, Tim Heckman +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. * Neither the name of gofrs nor the names of its contributors may be used to endorse or promote products derived from this software without @@ -4281,11 +4703,11 @@ Contents of probable licence file $GOMODCACHE/go.elastic.co/apm/module/apmgrpc@v -------------------------------------------------------------------------------- Dependency : go.elastic.co/ecszap -Version: v1.0.0 +Version: v1.0.1 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/go.elastic.co/ecszap@v1.0.0/LICENSE: +Contents of probable licence file $GOMODCACHE/go.elastic.co/ecszap@v1.0.1/LICENSE: Apache License @@ -4807,11 +5229,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : golang.org/x/sys -Version: v0.0.0-20220209214540-3681064d5158 +Version: v0.0.0-20220405052023-b1e9470b6e64 Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/golang.org/x/sys@v0.0.0-20220209214540-3681064d5158/LICENSE: +Contents of probable licence file $GOMODCACHE/golang.org/x/sys@v0.0.0-20220405052023-b1e9470b6e64/LICENSE: Copyright (c) 2009 The Go Authors. All rights reserved. @@ -5576,11 +5998,11 @@ Contents of probable licence file $GOMODCACHE/gotest.tools/gotestsum@v1.7.0/LICE -------------------------------------------------------------------------------- Dependency : k8s.io/api -Version: v0.23.1 +Version: v0.23.4 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/k8s.io/api@v0.23.1/LICENSE: +Contents of probable licence file $GOMODCACHE/k8s.io/api@v0.23.4/LICENSE: Apache License @@ -5788,11 +6210,11 @@ Contents of probable licence file $GOMODCACHE/k8s.io/api@v0.23.1/LICENSE: -------------------------------------------------------------------------------- Dependency : k8s.io/apimachinery -Version: v0.23.1 +Version: v0.23.4 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/k8s.io/apimachinery@v0.23.1/LICENSE: +Contents of probable licence file $GOMODCACHE/k8s.io/apimachinery@v0.23.4/LICENSE: Apache License @@ -6000,11 +6422,11 @@ Contents of probable licence file $GOMODCACHE/k8s.io/apimachinery@v0.23.1/LICENS -------------------------------------------------------------------------------- Dependency : k8s.io/client-go -Version: v0.23.1 +Version: v0.23.4 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/k8s.io/client-go@v0.23.1/LICENSE: +Contents of probable licence file $GOMODCACHE/k8s.io/client-go@v0.23.4/LICENSE: Apache License @@ -7389,11 +7811,11 @@ Apache License -------------------------------------------------------------------------------- Dependency : github.com/docker/docker -Version: v20.10.7+incompatible +Version: v20.10.12+incompatible Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/docker/docker@v20.10.7+incompatible/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/docker/docker@v20.10.12+incompatible/LICENSE: Apache License @@ -10330,11 +10752,11 @@ OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- Dependency : github.com/hashicorp/errwrap -Version: v1.0.0 +Version: v1.1.0 Licence type (autodetected): MPL-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/hashicorp/errwrap@v1.0.0/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/hashicorp/errwrap@v1.1.0/LICENSE: Mozilla Public License, version 2.0 @@ -14322,6 +14744,428 @@ Contents of probable licence file $GOMODCACHE/go.elastic.co/apm/module/apmhttp@v limitations under the License. +-------------------------------------------------------------------------------- +Dependency : go.elastic.co/apm/module/apmhttp/v2 +Version: v2.0.0 +Licence type (autodetected): Apache-2.0 +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/go.elastic.co/apm/module/apmhttp/v2@v2.0.0/LICENSE: + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018 Elasticsearch BV + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +-------------------------------------------------------------------------------- +Dependency : go.elastic.co/apm/v2 +Version: v2.0.0 +Licence type (autodetected): Apache-2.0 +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/go.elastic.co/apm/v2@v2.0.0/LICENSE: + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018 Elasticsearch BV + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + -------------------------------------------------------------------------------- Dependency : go.elastic.co/fastjson Version: v1.1.0 @@ -14483,11 +15327,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : golang.org/x/net -Version: v0.0.0-20211209124913-491a49abca63 +Version: v0.0.0-20220225172249-27dd8689420f Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/golang.org/x/net@v0.0.0-20211209124913-491a49abca63/LICENSE: +Contents of probable licence file $GOMODCACHE/golang.org/x/net@v0.0.0-20220225172249-27dd8689420f/LICENSE: Copyright (c) 2009 The Go Authors. All rights reserved. @@ -14594,11 +15438,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : golang.org/x/term -Version: v0.0.0-20210615171337-6886f2dfbf5b +Version: v0.0.0-20210927222741-03fcf44c2211 Licence type (autodetected): BSD-3-Clause -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/golang.org/x/term@v0.0.0-20210615171337-6886f2dfbf5b/LICENSE: +Contents of probable licence file $GOMODCACHE/golang.org/x/term@v0.0.0-20210927222741-03fcf44c2211/LICENSE: Copyright (c) 2009 The Go Authors. All rights reserved. @@ -16054,11 +16898,11 @@ Contents of probable licence file $GOMODCACHE/k8s.io/kube-openapi@v0.0.0-2021111 -------------------------------------------------------------------------------- Dependency : k8s.io/utils -Version: v0.0.0-20210930125809-cb0fa318a74b +Version: v0.0.0-20211116205334-6203023598ed Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/k8s.io/utils@v0.0.0-20210930125809-cb0fa318a74b/LICENSE: +Contents of probable licence file $GOMODCACHE/k8s.io/utils@v0.0.0-20211116205334-6203023598ed/LICENSE: Apache License @@ -16514,11 +17358,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- Dependency : sigs.k8s.io/structured-merge-diff/v4 -Version: v4.1.2 +Version: v4.2.1 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/sigs.k8s.io/structured-merge-diff/v4@v4.1.2/LICENSE: +Contents of probable licence file $GOMODCACHE/sigs.k8s.io/structured-merge-diff/v4@v4.2.1/LICENSE: Apache License Version 2.0, January 2004 diff --git a/go.mod b/go.mod index 2dbcb511cc1..f5c81b16d4d 100644 --- a/go.mod +++ b/go.mod @@ -10,8 +10,10 @@ require ( github.com/coreos/go-systemd/v22 v22.3.2 github.com/docker/go-units v0.4.0 github.com/elastic/e2e-testing v1.99.2-0.20220117192005-d3365c99b9c4 + github.com/elastic/elastic-agent-autodiscover v0.0.0-20220404145827-89887023c1ab github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6 github.com/elastic/elastic-agent-libs v0.2.1 + github.com/elastic/elastic-agent-system-metrics v0.1.0 github.com/elastic/go-licenser v0.4.0 github.com/elastic/go-sysinfo v1.7.1 github.com/elastic/go-ucfg v0.8.4 @@ -38,21 +40,21 @@ require ( github.com/spf13/cobra v1.3.0 github.com/stretchr/testify v1.7.0 github.com/tsg/go-daemon v0.0.0-20200207173439-e704b93fd89b - go.elastic.co/ecszap v1.0.0 + go.elastic.co/ecszap v1.0.1 go.elastic.co/go-licence-detector v0.5.0 go.uber.org/zap v1.21.0 golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 - golang.org/x/sys v0.0.0-20220209214540-3681064d5158 + golang.org/x/sys v0.0.0-20220405052023-b1e9470b6e64 golang.org/x/tools v0.1.9 google.golang.org/grpc v1.42.0 google.golang.org/protobuf v1.27.1 gopkg.in/yaml.v2 v2.4.0 gotest.tools v2.2.0+incompatible gotest.tools/gotestsum v1.7.0 - k8s.io/api v0.23.1 - k8s.io/apimachinery v0.23.1 - k8s.io/client-go v0.23.1 + k8s.io/api v0.23.4 + k8s.io/apimachinery v0.23.4 + k8s.io/client-go v0.23.4 ) require ( @@ -65,7 +67,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v20.10.7+incompatible // indirect + github.com/docker/docker v20.10.12+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/elastic/go-structform v0.0.9 // indirect github.com/elastic/go-windows v1.0.1 // indirect @@ -82,7 +84,7 @@ require ( github.com/google/licenseclassifier v0.0.0-20200402202327-879cb1424de0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/googleapis/gnostic v0.5.5 // indirect - github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jcchavezs/porto v0.1.0 // indirect @@ -109,14 +111,16 @@ require ( github.com/tklauser/numcpus v0.3.0 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect go.elastic.co/apm/module/apmhttp v1.15.0 // indirect + go.elastic.co/apm/module/apmhttp/v2 v2.0.0 // indirect + go.elastic.co/apm/v2 v2.0.0 // indirect go.elastic.co/fastjson v1.1.0 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.8.0 // indirect golang.org/x/mod v0.5.1 // indirect - golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect + golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect + golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect @@ -127,9 +131,9 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect howett.net/plist v1.0.0 // indirect k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect - k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect + k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect sigs.k8s.io/yaml v1.2.0 // indirect ) diff --git a/go.sum b/go.sum index e9074321de8..87b422b19de 100644 --- a/go.sum +++ b/go.sum @@ -493,8 +493,9 @@ github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6 github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v17.12.0-ce-rc1.0.20200618181300-9dc6525e6118+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v20.10.6+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/docker v20.10.7+incompatible h1:Z6O9Nhsjv+ayUEeI1IojKbYcsGdgYSNqxe1s2MYzUhQ= github.com/docker/docker v20.10.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v20.10.12+incompatible h1:CEeNmFM0QZIsJCZKMkZx0ZcahTiewkrgiwfYD+dfl1U= +github.com/docker/docker v20.10.12+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= @@ -527,10 +528,16 @@ github.com/elastic/beats/v7 v7.0.0-alpha2.0.20220303073437-a28c413604b8 h1:JVruc github.com/elastic/beats/v7 v7.0.0-alpha2.0.20220303073437-a28c413604b8/go.mod h1:deRXxthy5Roatme8Gj9Udv+oOGGy7y0ay6QV2+6ITXA= github.com/elastic/e2e-testing v1.99.2-0.20220117192005-d3365c99b9c4 h1:uYT+Krd8dsvnhnLK9pe/JHZkYtXEGPfbV4Wt1JPPol0= github.com/elastic/e2e-testing v1.99.2-0.20220117192005-d3365c99b9c4/go.mod h1:UcNuf4pX/qDVNQr0zybm1NL2YoWik+jKBaINZqQCA40= +github.com/elastic/elastic-agent-autodiscover v0.0.0-20220404145827-89887023c1ab h1:Jk6Mfk5BF8gtfE7X0bNCiDGBtwJVxRI79b4wLCAsP+A= +github.com/elastic/elastic-agent-autodiscover v0.0.0-20220404145827-89887023c1ab/go.mod h1:Gg1fsQI+rVms9FJ2DefBSojfPIzgkV8xlyG8fPG0DE8= github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6 h1:nFvXHBjYK3e9+xF0WKDeAKK4aOO51uC28s+L9rBmilo= github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6/go.mod h1:uh/Gj9a0XEbYoM4NYz4LvaBVARz3QXLmlNjsrKY9fTc= +github.com/elastic/elastic-agent-libs v0.0.0-20220303160015-5b4e674da3dd/go.mod h1://82M1l73IHx0wDbS2Tzkq6Fx9fkmytS1KgkIyzvNTM= +github.com/elastic/elastic-agent-libs v0.1.3-0.20220413130536-4b45f2742994/go.mod h1:1xDLBhIqBIjhJ7lr2s+xRFFkQHpitSp8q2zzv1Dqg+s= github.com/elastic/elastic-agent-libs v0.2.1 h1:v6dxLeyC7jsyUcRXLPRqRHxqREx2wYWp9epxDu1VasM= github.com/elastic/elastic-agent-libs v0.2.1/go.mod h1:1xDLBhIqBIjhJ7lr2s+xRFFkQHpitSp8q2zzv1Dqg+s= +github.com/elastic/elastic-agent-system-metrics v0.1.0 h1:7zMcA4ai+5mqnJQDL+JdztawsnCHfgi80X9COKukgPY= +github.com/elastic/elastic-agent-system-metrics v0.1.0/go.mod h1:YUsjilmJSuMGt1iG0fSF/5uJPWsl+qf+8gndtPEsWEA= github.com/elastic/elastic-package v0.32.1/go.mod h1:l1fEnF52XRBL6a5h6uAemtdViz2bjtjUtgdQcuRhEAY= github.com/elastic/go-concert v0.2.0/go.mod h1:HWjpO3IAEJUxOeaJOWXWEp7imKd27foxz9V5vegC/38= github.com/elastic/go-elasticsearch/v7 v7.16.0/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4= @@ -961,8 +968,9 @@ github.com/hashicorp/consul/sdk v0.7.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPA github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= github.com/hashicorp/cronexpr v1.1.0/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= @@ -1340,6 +1348,7 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.0/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= @@ -1701,11 +1710,14 @@ go.elastic.co/apm/module/apmhttp v1.7.2/go.mod h1:sTFWiWejnhSdZv6+dMgxGec2Nxe/ZK go.elastic.co/apm/module/apmhttp v1.10.0/go.mod h1:Y4timwcJ8sQWbWpcw3Y7Mat1OssNpGhpwyfUnpqIDew= go.elastic.co/apm/module/apmhttp v1.15.0 h1:Le/DhI0Cqpr9wG/NIGOkbz7+rOMqJrfE4MRG6q/+leU= go.elastic.co/apm/module/apmhttp v1.15.0/go.mod h1:NruY6Jq8ALLzWUVUQ7t4wIzn+onKoiP5woJJdTV7GMg= +go.elastic.co/apm/module/apmhttp/v2 v2.0.0 h1:GNfmK1LD4nE5fYqbLxROCpg1ucyjSFG5iwulxwAJ+3o= go.elastic.co/apm/module/apmhttp/v2 v2.0.0/go.mod h1:5KmxcNN7hkJh8sVW3Ggl/pYgnwiNenygE46bZoUb9RE= +go.elastic.co/apm/v2 v2.0.0 h1:5BeBh+oIrVbMwPrW3uO9Uxm4w7HpKy92lYl5Rfj69Kg= go.elastic.co/apm/v2 v2.0.0/go.mod h1:KGQn56LtRmkQjt2qw4+c1Jz8gv9rCBUU/m21uxrqcps= go.elastic.co/ecszap v0.3.0/go.mod h1:HTUi+QRmr3EuZMqxPX+5fyOdMNfUu5iPebgfhgsTJYQ= -go.elastic.co/ecszap v1.0.0 h1:PdQkRUeraR3XHJ14T7JMa+ncU0XXrVrcEN/BoRa2nMI= go.elastic.co/ecszap v1.0.0/go.mod h1:HTUi+QRmr3EuZMqxPX+5fyOdMNfUu5iPebgfhgsTJYQ= +go.elastic.co/ecszap v1.0.1 h1:mBxqEJAEXBlpi5+scXdzL7LTFGogbuxipJC0KTZicyA= +go.elastic.co/ecszap v1.0.1/go.mod h1:SVjazT+QgNeHSGOCUHvRgN+ZRj5FkB7IXQQsncdF57A= go.elastic.co/fastjson v1.0.0/go.mod h1:PmeUOMMtLHQr9ZS9J9owrAVg0FkaZDRZJEFTTGHtchs= go.elastic.co/fastjson v1.1.0 h1:3MrGBWWVIxe/xvsbpghtkFoPciPhOCmjsR/HfwEeQR4= go.elastic.co/fastjson v1.1.0/go.mod h1:boNGISWMjQsUPy/t6yqt2/1Wx4YNPSe+mZjlyw9vKKI= @@ -1957,8 +1969,9 @@ golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211209124913-491a49abca63 h1:iocB37TsdFuN6IBRZ+ry36wrkoV51/tl5vOWqkcPGvY= golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190130055435-99b60b757ec1/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -2129,14 +2142,17 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220405052023-b1e9470b6e64 h1:D1v9ucDTYBtbz5vNuBbAhIMAGhQhJ6Ym5ah3maMVNX4= +golang.org/x/sys v0.0.0-20220405052023-b1e9470b6e64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= -golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -2528,8 +2544,9 @@ k8s.io/api v0.20.6/go.mod h1:X9e8Qag6JV/bL5G6bU8sdVRltWKmdHsFUGS3eVndqE8= k8s.io/api v0.21.1/go.mod h1:FstGROTmsSHBarKc8bylzXih8BLNYTiS3TZcsoEDg2s= k8s.io/api v0.22.4/go.mod h1:Rgs+9gIGYC5laXQSZZ9JqT5NevNgoGiOdVWi1BAB3qk= k8s.io/api v0.23.0/go.mod h1:8wmDdLBHBNxtOIytwLstXt5E9PddnZb0GaMcqsvDBpg= -k8s.io/api v0.23.1 h1:ncu/qfBfUoClqwkTGbeRqqOqBCRoUAflMuOaOD7J0c8= k8s.io/api v0.23.1/go.mod h1:WfXnOnwSqNtG62Y1CdjoMxh7r7u9QXGCkA1u0na2jgo= +k8s.io/api v0.23.4 h1:85gnfXQOWbJa1SiWGpE9EEtHs0UVvDyIsSMpEtl2D4E= +k8s.io/api v0.23.4/go.mod h1:i77F4JfyNNrhOjZF7OwwNJS5Y1S9dpwvb9iYRYRczfI= k8s.io/apiextensions-apiserver v0.22.4/go.mod h1:kH9lxD8dbJ+k0ZizGET55lFgdGjO8t45fgZnCVdZEpw= k8s.io/apimachinery v0.17.5/go.mod h1:ioIo1G/a+uONV7Tv+ZmCbMG1/a3kVw5YcDdncd8ugQ0= k8s.io/apimachinery v0.20.1/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= @@ -2538,8 +2555,9 @@ k8s.io/apimachinery v0.20.6/go.mod h1:ejZXtW1Ra6V1O5H8xPBGz+T3+4gfkTCeExAHKU57MA k8s.io/apimachinery v0.21.1/go.mod h1:jbreFvJo3ov9rj7eWT7+sYiRx+qZuCYXwWT1bcDswPY= k8s.io/apimachinery v0.22.4/go.mod h1:yU6oA6Gnax9RrxGzVvPFFJ+mpnW6PBSqp0sx0I0HHW0= k8s.io/apimachinery v0.23.0/go.mod h1:fFCTTBKvKcwTPFzjlcxp91uPFZr+JA0FubU4fLzzFYc= -k8s.io/apimachinery v0.23.1 h1:sfBjlDFwj2onG0Ijx5C+SrAoeUscPrmghm7wHP+uXlo= k8s.io/apimachinery v0.23.1/go.mod h1:SADt2Kl8/sttJ62RRsi9MIV4o8f5S3coArm0Iu3fBno= +k8s.io/apimachinery v0.23.4 h1:fhnuMd/xUL3Cjfl64j5ULKZ1/J9n8NuQEgNL+WXWfdM= +k8s.io/apimachinery v0.23.4/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM= k8s.io/apiserver v0.20.1/go.mod h1:ro5QHeQkgMS7ZGpvf4tSMx6bBOgPfE+f52KwvXfScaU= k8s.io/apiserver v0.20.4/go.mod h1:Mc80thBKOyy7tbvFtB4kJv1kbdD0eIH8k8vianJcbFM= k8s.io/apiserver v0.20.6/go.mod h1:QIJXNt6i6JB+0YQRNcS0hdRHJlMhflFmsBDeSgT1r8Q= @@ -2553,8 +2571,9 @@ k8s.io/client-go v0.20.6/go.mod h1:nNQMnOvEUEsOzRRFIIkdmYOjAZrC8bgq0ExboWSU1I0= k8s.io/client-go v0.21.1/go.mod h1:/kEw4RgW+3xnBGzvp9IWxKSNA+lXn3A7AuH3gdOAzLs= k8s.io/client-go v0.22.4/go.mod h1:Yzw4e5e7h1LNHA4uqnMVrpEpUs1hJOiuBsJKIlRCHDA= k8s.io/client-go v0.23.0/go.mod h1:hrDnpnK1mSr65lHHcUuIZIXDgEbzc7/683c6hyG4jTA= -k8s.io/client-go v0.23.1 h1:Ma4Fhf/p07Nmj9yAB1H7UwbFHEBrSPg8lviR24U2GiQ= k8s.io/client-go v0.23.1/go.mod h1:6QSI8fEuqD4zgFK0xbdwfB/PthBsIxCJMa3s17WlcO0= +k8s.io/client-go v0.23.4 h1:YVWvPeerA2gpUudLelvsolzH7c2sFoXXR5wM/sWqNFU= +k8s.io/client-go v0.23.4/go.mod h1:PKnIL4pqLuvYUK1WU7RLTMYKPiIh7MYShLshtRY9cj0= k8s.io/code-generator v0.22.4/go.mod h1:qjYl54pQ/emhkT0UxbufbREYJMWsHNNV/jSVwhYZQGw= k8s.io/component-base v0.20.1/go.mod h1:guxkoJnNoh8LNrbtiQOlyp2Y2XFCZQmrcg2n/DeYNLk= k8s.io/component-base v0.20.4/go.mod h1:t4p9EdiagbVCJKrQ1RsA5/V4rFQNDfRlevJajlGwgjI= @@ -2595,8 +2614,9 @@ k8s.io/utils v0.0.0-20200414100711-2df71ebbae66/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b h1:wxEMGetGMur3J1xuGLQY7GEQYg9bZxKn3tKo5k/eYcs= k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= +k8s.io/utils v0.0.0-20211116205334-6203023598ed h1:ck1fRPWPJWsMd8ZRFsWc6mh/zHp5fZ/shhbrgPUxDAE= +k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= kernel.org/pub/linux/libs/security/libcap/cap v1.2.57/go.mod h1:uI99C3r4SXvJeuqoEtx/eWt7UbmfqqZ80H8q+9t/A7I= kernel.org/pub/linux/libs/security/libcap/psx v1.2.57/go.mod h1:+l6Ee2F59XiJ2I6WR5ObpC1utCQJZ/VLsEbQCD8RG24= oras.land/oras-go v0.4.0/go.mod h1:VJcU+VE4rkclUbum5C0O7deEZbBYnsnpbGSACwTjOcg= @@ -2620,8 +2640,9 @@ sigs.k8s.io/structured-merge-diff/v2 v2.0.1/go.mod h1:Wb7vfKAodbKgf6tn1Kl0VvGj7m sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= sigs.k8s.io/structured-merge-diff/v4 v4.0.3/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= -sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3nu+sPzynno= sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4= +sigs.k8s.io/structured-merge-diff/v4 v4.2.1 h1:bKCqE9GvQ5tiVHn5rfn1r+yao3aLQEaLzkkmAkf+A6Y= +sigs.k8s.io/structured-merge-diff/v4 v4.2.1/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/internal/pkg/agent/cmd/common.go b/internal/pkg/agent/cmd/common.go index 57c249bbf32..35aef4d4339 100644 --- a/internal/pkg/agent/cmd/common.go +++ b/internal/pkg/agent/cmd/common.go @@ -13,7 +13,7 @@ import ( "github.com/spf13/cobra" // import logp flags - _ "github.com/elastic/beats/v7/libbeat/logp/configure" + _ "github.com/elastic/elastic-agent-libs/logp/configure" "github.com/elastic/elastic-agent/internal/pkg/basecmd" "github.com/elastic/elastic-agent/internal/pkg/cli" @@ -40,7 +40,8 @@ func NewCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command { // path flags cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.home")) cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.home.unversioned")) - cmd.PersistentFlags().MarkHidden("path.home.unversioned") // hidden used internally by container subcommand + // hidden used internally by container subcommand + cmd.PersistentFlags().MarkHidden("path.home.unversioned") //nolint:errcheck // it's hidden cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.config")) cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("c")) cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.logs")) diff --git a/internal/pkg/agent/cmd/container.go b/internal/pkg/agent/cmd/container.go index 651d2c08309..526d7c5062f 100644 --- a/internal/pkg/agent/cmd/container.go +++ b/internal/pkg/agent/cmd/container.go @@ -22,15 +22,14 @@ import ( "syscall" "time" - "github.com/elastic/elastic-agent/internal/pkg/agent/configuration" - "github.com/spf13/cobra" "gopkg.in/yaml.v2" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" - "github.com/elastic/beats/v7/libbeat/common/transport/tlscommon" - "github.com/elastic/beats/v7/libbeat/kibana" + "github.com/elastic/elastic-agent-libs/kibana" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/tlscommon" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" + "github.com/elastic/elastic-agent/internal/pkg/agent/configuration" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/agent/program" "github.com/elastic/elastic-agent/internal/pkg/artifact" @@ -40,6 +39,7 @@ import ( "github.com/elastic/elastic-agent/internal/pkg/core/process" "github.com/elastic/elastic-agent/internal/pkg/release" "github.com/elastic/elastic-agent/pkg/core/logger" + "github.com/elastic/elastic-agent/version" ) const ( @@ -133,7 +133,7 @@ all the above actions will be skipped, because the Elastic Agent has already bee occurs on every start of the container set FLEET_FORCE to 1. `, Run: func(c *cobra.Command, args []string) { - if err := logContainerCmd(streams, c); err != nil { + if err := logContainerCmd(streams); err != nil { logError(streams, err) os.Exit(1) } @@ -150,7 +150,7 @@ func logInfo(streams *cli.IOStreams, a ...interface{}) { fmt.Fprintln(streams.Out, a...) } -func logContainerCmd(streams *cli.IOStreams, cmd *cobra.Command) error { +func logContainerCmd(streams *cli.IOStreams) error { logsPath := envWithDefault("", "LOGS_PATH") if logsPath != "" { // log this entire command to a file as well as to the passed streams @@ -166,10 +166,10 @@ func logContainerCmd(streams *cli.IOStreams, cmd *cobra.Command) error { streams.Out = io.MultiWriter(streams.Out, w) streams.Err = io.MultiWriter(streams.Out, w) } - return containerCmd(streams, cmd) + return containerCmd(streams) } -func containerCmd(streams *cli.IOStreams, cmd *cobra.Command) error { +func containerCmd(streams *cli.IOStreams) error { // set paths early so all action below use the defined paths if err := setPaths("", "", "", true); err != nil { return err @@ -234,12 +234,12 @@ func containerCmd(streams *cli.IOStreams, cmd *cobra.Command) error { wg.Done() // sending kill signal to current process (elastic-agent) logInfo(streams, "Initiate shutdown elastic-agent.") - mainProc.Signal(syscall.SIGTERM) + _ = mainProc.Signal(syscall.SIGTERM) }() defer func() { if apmProc != nil { - apmProc.Stop() + _ = apmProc.Stop() logInfo(streams, "Initiate shutdown legacy apm-server.") } }() @@ -248,14 +248,14 @@ func containerCmd(streams *cli.IOStreams, cmd *cobra.Command) error { if runAgent { // run the main elastic-agent container command - err = runContainerCmd(streams, cmd, cfg) + err = runContainerCmd(streams, cfg) } // wait until APM Server shut down wg.Wait() return err } -func runContainerCmd(streams *cli.IOStreams, cmd *cobra.Command, cfg setupConfig) error { +func runContainerCmd(streams *cli.IOStreams, cfg setupConfig) error { var err error var client *kibana.Client executable, err := os.Executable() @@ -266,7 +266,7 @@ func runContainerCmd(streams *cli.IOStreams, cmd *cobra.Command, cfg setupConfig _, err = os.Stat(paths.AgentConfigFile()) if !os.IsNotExist(err) && !cfg.Fleet.Force { // already enrolled, just run the standard run - return run(streams, logToStderr) + return run(logToStderr) } if cfg.Kibana.Fleet.Setup || cfg.FleetServer.Enable { @@ -331,7 +331,7 @@ func runContainerCmd(streams *cli.IOStreams, cmd *cobra.Command, cfg setupConfig } } - return run(streams, logToStderr) + return run(logToStderr) } // TokenResp is used to decode a response for generating a service token @@ -538,7 +538,7 @@ func kibanaClient(cfg kibanaConfig, headers map[string]string) (*kibana.Client, IgnoreVersion: true, Transport: transport, Headers: headers, - }, 0, "Elastic-Agent") + }, 0, "Elastic-Agent", version.GetDefaultVersion(), version.Commit(), version.BuildTime().String()) } func findPolicy(cfg setupConfig, policies []kibanaPolicy) (*kibanaPolicy, error) { diff --git a/internal/pkg/agent/cmd/enroll.go b/internal/pkg/agent/cmd/enroll.go index 9412372f1c9..c17b5c118ed 100644 --- a/internal/pkg/agent/cmd/enroll.go +++ b/internal/pkg/agent/cmd/enroll.go @@ -16,7 +16,6 @@ import ( "github.com/spf13/cobra" - c "github.com/elastic/beats/v7/libbeat/common/cli" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" "github.com/elastic/elastic-agent/internal/pkg/agent/configuration" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" @@ -31,7 +30,7 @@ func newEnrollCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command Short: "Enroll the Agent into Fleet", Long: "This will enroll the Agent into Fleet.", Run: func(c *cobra.Command, args []string) { - if err := enroll(streams, c, args); err != nil { + if err := enroll(streams, c); err != nil { fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) os.Exit(1) } @@ -43,7 +42,7 @@ func newEnrollCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command // used by install command cmd.Flags().BoolP("from-install", "", false, "Set by install command to signal this was executed from install") - cmd.Flags().MarkHidden("from-install") + _ = cmd.Flags().MarkHidden("from-install") return cmd } @@ -227,7 +226,7 @@ func buildEnrollmentFlags(cmd *cobra.Command, url string, token string) []string return args } -func enroll(streams *cli.IOStreams, cmd *cobra.Command, args []string) error { +func enroll(streams *cli.IOStreams, cmd *cobra.Command) error { err := validateEnrollFlags(cmd) if err != nil { return err @@ -266,7 +265,7 @@ func enroll(streams *cli.IOStreams, cmd *cobra.Command, args []string) error { // prompt only when it is not forced and is already enrolled if !force && (cfg.Fleet != nil && cfg.Fleet.Enabled) { - confirm, err := c.Confirm("This will replace your current settings. Do you want to continue?", true) + confirm, err := cli.Confirm("This will replace your current settings. Do you want to continue?", true) if err != nil { return errors.New(err, "problem reading prompt response") } @@ -366,7 +365,7 @@ func handleSignal(ctx context.Context) context.Context { ctx, cfunc := context.WithCancel(ctx) sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGQUIT) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) go func() { select { diff --git a/internal/pkg/agent/cmd/enroll_cmd.go b/internal/pkg/agent/cmd/enroll_cmd.go index a7eb9b6625a..e7277c1936f 100644 --- a/internal/pkg/agent/cmd/enroll_cmd.go +++ b/internal/pkg/agent/cmd/enroll_cmd.go @@ -18,8 +18,8 @@ import ( "go.elastic.co/apm" "gopkg.in/yaml.v2" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" - "github.com/elastic/beats/v7/libbeat/common/transport/tlscommon" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/tlscommon" "github.com/elastic/elastic-agent/internal/pkg/agent/application" "github.com/elastic/elastic-agent/internal/pkg/agent/application/filelock" "github.com/elastic/elastic-agent/internal/pkg/agent/application/info" @@ -309,11 +309,9 @@ func (c *enrollCmd) fleetServerBootstrap(ctx context.Context, persistentConfig m return "", err } - agentConfig, err := c.createAgentConfig("", persistentConfig, c.options.FleetServer.Headers) - if err != nil { - return "", err - } + agentConfig := c.createAgentConfig("", persistentConfig, c.options.FleetServer.Headers) + //nolint:dupl // duplicate because same params are passed fleetConfig, err := createFleetServerBootstrapConfig( c.options.FleetServer.ConnStr, c.options.FleetServer.ServiceToken, c.options.FleetServer.PolicyID, @@ -367,7 +365,7 @@ func (c *enrollCmd) fleetServerBootstrap(ctx context.Context, persistentConfig m func (c *enrollCmd) prepareFleetTLS() error { host := c.options.FleetServer.Host if host == "" { - host = "localhost" + host = defaultFleetServerInternalHost } port := c.options.FleetServer.Port if port == 0 { @@ -383,7 +381,7 @@ func (c *enrollCmd) prepareFleetTLS() error { if c.options.FleetServer.Insecure { // running insecure, force the binding to localhost (unless specified) if c.options.FleetServer.Host == "" { - c.options.FleetServer.Host = "localhost" + c.options.FleetServer.Host = defaultFleetServerInternalHost } c.options.URL = fmt.Sprintf("http://%s:%d", host, port) c.options.Insecure = true @@ -513,13 +511,11 @@ func (c *enrollCmd) enroll(ctx context.Context, persistentConfig map[string]inte return err } - agentConfig, err := c.createAgentConfig(resp.Item.ID, persistentConfig, c.options.FleetServer.Headers) - if err != nil { - return err - } + agentConfig := c.createAgentConfig(resp.Item.ID, persistentConfig, c.options.FleetServer.Headers) localFleetServer := c.options.FleetServer.ConnStr != "" if localFleetServer { + //nolint:dupl // not duplicates, just similar params are passed serverConfig, err := createFleetServerBootstrapConfig( c.options.FleetServer.ConnStr, c.options.FleetServer.ServiceToken, c.options.FleetServer.PolicyID, @@ -609,7 +605,7 @@ func (c *enrollCmd) startAgent(ctx context.Context) (<-chan *os.ProcessState, er func (c *enrollCmd) stopAgent() { if c.agentProc != nil { - c.agentProc.StopWait() + _ = c.agentProc.StopWait() c.agentProc = nil } } @@ -623,7 +619,7 @@ func yamlToReader(in interface{}) (io.Reader, error) { } func delay(ctx context.Context, d time.Duration) { - t := time.NewTimer(time.Duration(rand.Int63n(int64(d)))) + t := time.NewTimer(time.Duration(rand.Int63n(int64(d)))) //nolint:gosec // the RNG is allowed to be weak defer t.Stop() select { case <-ctx.Done(): @@ -848,7 +844,9 @@ func storeAgentInfo(s saver, reader io.Reader) error { if err := fileLock.TryLock(); err != nil { return err } - defer fileLock.Unlock() + defer func() { + _ = fileLock.Unlock() + }() if err := s.Save(reader); err != nil { return errors.New(err, "could not save enrollment information", errors.TypeFilesystem) @@ -962,7 +960,7 @@ func createFleetConfigFromEnroll(accessAPIKey string, cli remote.Config) (*confi return cfg, nil } -func (c *enrollCmd) createAgentConfig(agentID string, pc map[string]interface{}, headers map[string]string) (map[string]interface{}, error) { +func (c *enrollCmd) createAgentConfig(agentID string, pc map[string]interface{}, headers map[string]string) map[string]interface{} { agentConfig := map[string]interface{}{ "id": agentID, } @@ -982,7 +980,7 @@ func (c *enrollCmd) createAgentConfig(agentID string, pc map[string]interface{}, agentConfig[k] = v } - return agentConfig, nil + return agentConfig } func getPersistentConfig(pathConfigFile string) (map[string]interface{}, error) { diff --git a/internal/pkg/agent/cmd/inspect.go b/internal/pkg/agent/cmd/inspect.go index 76746fac1be..e6284d56487 100644 --- a/internal/pkg/agent/cmd/inspect.go +++ b/internal/pkg/agent/cmd/inspect.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/cobra" "gopkg.in/yaml.v2" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/application/filters" "github.com/elastic/elastic-agent/internal/pkg/agent/application/info" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" @@ -49,12 +49,12 @@ func newInspectCommandWithArgs(s []string, streams *cli.IOStreams) *cobra.Comman }, } - cmd.AddCommand(newInspectOutputCommandWithArgs(s, streams)) + cmd.AddCommand(newInspectOutputCommandWithArgs(s)) return cmd } -func newInspectOutputCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command { +func newInspectOutputCommandWithArgs(_ []string) *cobra.Command { cmd := &cobra.Command{ Use: "output", Short: "Displays configuration generated for output", @@ -121,8 +121,8 @@ func printMapStringConfig(mapStr map[string]interface{}) error { return errors.New(err, "could not marshal to YAML") } - fmt.Println(string(data)) - return nil + _, err = os.Stdout.WriteString(string(data)) + return err } func printConfig(cfg *config.Config) error { @@ -170,7 +170,7 @@ func listOutputsFromConfig(log *logger.Logger, agentInfo *info.AgentInfo, cfg *c } for k := range programsGroup { - fmt.Println(k) + _, _ = os.Stdout.WriteString(k) } return nil @@ -223,9 +223,12 @@ func printOutputFromConfig(log *logger.Logger, agentInfo *info.AgentInfo, output } programFound = true - fmt.Printf("[%s] %s:\n", k, p.Spec.Cmd) - printMapStringConfig(p.Configuration()) - fmt.Println("---") + _, _ = os.Stdout.WriteString(fmt.Sprintf("[%s] %s:\n", k, p.Spec.Cmd)) + err = printMapStringConfig(p.Configuration()) + if err != nil { + return fmt.Errorf("cannot print configuration of program '%s': %w", programName, err) + } + _, _ = os.Stdout.WriteString("---") } if !programFound { diff --git a/internal/pkg/agent/cmd/install.go b/internal/pkg/agent/cmd/install.go index 1bf9c8952d1..f111d4d4618 100644 --- a/internal/pkg/agent/cmd/install.go +++ b/internal/pkg/agent/cmd/install.go @@ -27,8 +27,8 @@ func newInstallCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Comman Unless all the require command-line parameters are provided or -f is used this command will ask questions on how you would like the Agent to operate. `, - Run: func(c *cobra.Command, args []string) { - if err := installCmd(streams, c, args); err != nil { + Run: func(c *cobra.Command, _ []string) { + if err := installCmd(streams, c); err != nil { fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) os.Exit(1) } @@ -42,7 +42,7 @@ would like the Agent to operate. return cmd } -func installCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error { +func installCmd(streams *cli.IOStreams, cmd *cobra.Command) error { err := validateEnrollFlags(cmd) if err != nil { return err @@ -78,7 +78,7 @@ func installCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error } return err } - locker.Unlock() + _ = locker.Unlock() if status == install.Broken { if !force && !nonInteractive { @@ -168,7 +168,7 @@ func installCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error defer func() { if err != nil { - install.Uninstall(cfgFile) + _ = install.Uninstall(cfgFile) } }() @@ -181,7 +181,7 @@ func installCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error defer func() { if err != nil { - install.StopService() + _ = install.StopService() } }() } @@ -190,7 +190,7 @@ func installCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error if enroll { enrollArgs := []string{"enroll", "--from-install"} enrollArgs = append(enrollArgs, buildEnrollmentFlags(cmd, url, token)...) - enrollCmd := exec.Command(install.ExecutablePath(), enrollArgs...) + enrollCmd := exec.Command(install.ExecutablePath(), enrollArgs...) //nolint:gosec // it's not tainted enrollCmd.Stdin = os.Stdin enrollCmd.Stdout = os.Stdout enrollCmd.Stderr = os.Stderr @@ -202,7 +202,7 @@ func installCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error if err != nil { if status != install.PackageInstall { var exitErr *exec.ExitError - install.Uninstall(cfgFile) + _ = install.Uninstall(cfgFile) if err != nil && errors.As(err, &exitErr) { return fmt.Errorf("enroll command failed with exit code: %d", exitErr.ExitCode()) } diff --git a/internal/pkg/agent/cmd/metrics.go b/internal/pkg/agent/cmd/metrics.go new file mode 100644 index 00000000000..3ff429b2cd3 --- /dev/null +++ b/internal/pkg/agent/cmd/metrics.go @@ -0,0 +1,128 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package cmd + +import ( + "fmt" + "runtime" + "time" + + "github.com/gofrs/uuid" + + "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/monitoring" + "github.com/elastic/elastic-agent-system-metrics/metric/system/process" + "github.com/elastic/elastic-agent-system-metrics/report" +) + +var ( + systemMetrics *monitoring.Registry + beatMetrics *monitoring.Registry + + processStats *process.Stats + ephemeralID uuid.UUID + startTime time.Time +) + +func init() { + systemMetrics = monitoring.Default.NewRegistry("system") + beatMetrics = monitoring.Default.NewRegistry("beat") + startTime = time.Now() + + var err error + ephemeralID, err = uuid.NewV4() + if err != nil { + logp.Err("Error while generating ephemeral ID for Beat") + } +} + +// monitoringCgroupsHierarchyOverride is an undocumented environment variable which +// overrides the cgroups path under /sys/fs/cgroup, which should be set to "/" when running +// Elastic Agent under Docker. +const monitoringCgroupsHierarchyOverride = "LIBBEAT_MONITORING_CGROUPS_HIERARCHY_OVERRIDE" + +func initMetrics(logger *logp.Logger, name, version string) error { + monitoring.NewFunc(systemMetrics, "cpu", report.ReportSystemCPUUsage, monitoring.Report) + + name = processName(name) + processStats = &process.Stats{ + Procs: []string{name}, + EnvWhitelist: nil, + CPUTicks: true, + CacheCmdLine: true, + IncludeTop: process.IncludeTopConfig{}, + } + + err := processStats.Init() + if err != nil { + return fmt.Errorf("failed to init process stats for agent: %w", err) + } + + monitoring.NewFunc(beatMetrics, "memstats", report.MemStatsReporter(logger, processStats), monitoring.Report) + monitoring.NewFunc(beatMetrics, "cpu", report.InstanceCPUReporter(logger, processStats), monitoring.Report) + monitoring.NewFunc(beatMetrics, "runtime", report.ReportRuntime, monitoring.Report) + monitoring.NewFunc(beatMetrics, "info", infoReporter(name, version), monitoring.Report) + + setupPlatformSpecificMetrics(logger, processStats) + + return nil +} + +// processName truncates the name if it is longer than 15 characters, so we don't fail process checks later on +// On *nix, the process name comes from /proc/PID/stat, which uses a comm value of 16 bytes, plus the null byte +func processName(name string) string { + if (isLinux() || isDarwin()) && len(name) > 15 { + name = name[:15] + } + return name +} + +func isDarwin() bool { + return runtime.GOOS == "darwin" +} + +func isLinux() bool { + return runtime.GOOS == "linux" +} + +func isWindows() bool { + return runtime.GOOS == "windows" +} + +func infoReporter(serviceName, version string) func(_ monitoring.Mode, V monitoring.Visitor) { + return func(_ monitoring.Mode, V monitoring.Visitor) { + V.OnRegistryStart() + defer V.OnRegistryFinished() + + delta := time.Since(startTime) + uptime := int64(delta / time.Millisecond) + monitoring.ReportNamespace(V, "uptime", func() { + monitoring.ReportInt(V, "ms", uptime) + }) + + monitoring.ReportString(V, "ephemeral_id", ephemeralID.String()) + monitoring.ReportString(V, "name", serviceName) + monitoring.ReportString(V, "version", version) + } +} + +func setupPlatformSpecificMetrics(logger *logp.Logger, processStats *process.Stats) { + if isLinux() { + monitoring.NewFunc(beatMetrics, "cgroup", report.InstanceCroupsReporter(logger, monitoringCgroupsHierarchyOverride), monitoring.Report) + } + + if isWindows() { + report.SetupWindowsHandlesMetrics(logger, systemMetrics) + } else { + monitoring.NewFunc(systemMetrics, "load", report.ReportSystemLoadAverage, monitoring.Report) + } + + report.SetupLinuxBSDFDMetrics(logger, systemMetrics, processStats) +} + +// EphemeralID returns generated EphemeralID +func EphemeralID() uuid.UUID { + return ephemeralID +} diff --git a/internal/pkg/agent/cmd/platformcheck_test.go b/internal/pkg/agent/cmd/platformcheck_test.go index c6450351d69..7054d2b507d 100644 --- a/internal/pkg/agent/cmd/platformcheck_test.go +++ b/internal/pkg/agent/cmd/platformcheck_test.go @@ -15,8 +15,8 @@ import ( ) func TestCheckPlatformCompat(t *testing.T) { - if !(runtime.GOARCH == "amd64" && (runtime.GOOS == "linux" || - runtime.GOOS == "windows")) { + if !(runtime.GOARCH == "amd64" && (isLinux() || + isWindows())) { t.Skip("Test not support on current platform") } diff --git a/internal/pkg/agent/cmd/run.go b/internal/pkg/agent/cmd/run.go index c6052cdfd1c..88ba6ab8cf0 100644 --- a/internal/pkg/agent/cmd/run.go +++ b/internal/pkg/agent/cmd/run.go @@ -19,10 +19,9 @@ import ( apmtransport "go.elastic.co/apm/transport" "gopkg.in/yaml.v2" - "github.com/elastic/beats/v7/libbeat/api" - "github.com/elastic/beats/v7/libbeat/cmd/instance/metrics" - "github.com/elastic/beats/v7/libbeat/monitoring" - "github.com/elastic/beats/v7/libbeat/service" + "github.com/elastic/elastic-agent-libs/api" + "github.com/elastic/elastic-agent-libs/monitoring" + "github.com/elastic/elastic-agent-libs/service" "github.com/elastic/elastic-agent/internal/pkg/agent/application" "github.com/elastic/elastic-agent/internal/pkg/agent/application/filelock" @@ -42,6 +41,7 @@ import ( "github.com/elastic/elastic-agent/internal/pkg/core/status" "github.com/elastic/elastic-agent/internal/pkg/release" "github.com/elastic/elastic-agent/pkg/core/logger" + "github.com/elastic/elastic-agent/version" ) const ( @@ -55,7 +55,7 @@ func newRunCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command { Use: "run", Short: "Start the elastic-agent.", Run: func(_ *cobra.Command, _ []string) { - if err := run(streams, nil); err != nil { + if err := run(nil); err != nil { fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) os.Exit(1) } @@ -63,7 +63,7 @@ func newRunCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command { } } -func run(streams *cli.IOStreams, override cfgOverrider) error { +func run(override cfgOverrider) error { // Windows: Mark service as stopped. // After this is run, the service is considered by the OS to be stopped. // This must be the first deferred cleanup task (last to execute). @@ -76,7 +76,9 @@ func run(streams *cli.IOStreams, override cfgOverrider) error { if err := locker.TryLock(); err != nil { return err } - defer locker.Unlock() + defer func() { + _ = locker.Unlock() + }() service.BeforeRun() defer service.Cleanup() @@ -172,7 +174,9 @@ func run(streams *cli.IOStreams, override cfgOverrider) error { if err != nil { return err } - defer serverStopFn() + defer func() { + _ = serverStopFn() + }() if err := app.Start(); err != nil { return err @@ -180,7 +184,7 @@ func run(streams *cli.IOStreams, override cfgOverrider) error { // listen for signals signals := make(chan os.Signal, 1) - signal.Notify(signals, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) + signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) reexecing := false for { breakout := false @@ -322,8 +326,7 @@ func setupMetrics( app application.Application, tracer *apm.Tracer, ) (func() error, error) { - // use libbeat to setup metrics - if err := metrics.SetupMetrics(agentName); err != nil { + if err := initMetrics(logger, agentName, version.GetDefaultVersion()); err != nil { return nil, err } @@ -356,7 +359,7 @@ func tryDelayEnroll(ctx context.Context, logger *logger.Logger, cfg *configurati enrollPath := paths.AgentEnrollFile() if _, err := os.Stat(enrollPath); err != nil { // no enrollment file exists or failed to stat it; nothing to do - return cfg, nil + return cfg, nil //nolint:nilerr // there is nothing to do } contents, err := ioutil.ReadFile(enrollPath) if err != nil { diff --git a/internal/pkg/agent/cmd/uninstall.go b/internal/pkg/agent/cmd/uninstall.go index 8f60257cedc..f66c381add6 100644 --- a/internal/pkg/agent/cmd/uninstall.go +++ b/internal/pkg/agent/cmd/uninstall.go @@ -10,7 +10,6 @@ import ( "github.com/spf13/cobra" - c "github.com/elastic/beats/v7/libbeat/common/cli" "github.com/elastic/elastic-agent/internal/pkg/agent/application/info" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" "github.com/elastic/elastic-agent/internal/pkg/agent/install" @@ -25,8 +24,8 @@ func newUninstallCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Comm Unless -f is used this command will ask confirmation before performing removal. `, - Run: func(c *cobra.Command, args []string) { - if err := uninstallCmd(streams, c, args); err != nil { + Run: func(c *cobra.Command, _ []string) { + if err := uninstallCmd(streams, c); err != nil { fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) os.Exit(1) } @@ -38,7 +37,7 @@ Unless -f is used this command will ask confirmation before performing removal. return cmd } -func uninstallCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error { +func uninstallCmd(streams *cli.IOStreams, cmd *cobra.Command) error { isAdmin, err := install.HasRoot() if err != nil { return fmt.Errorf("unable to perform command while checking for administrator rights, %w", err) @@ -58,7 +57,7 @@ func uninstallCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) err if status == install.Broken { if !force { fmt.Fprintf(streams.Out, "Elastic Agent is installed but currently broken: %s\n", reason) - confirm, err := c.Confirm(fmt.Sprintf("Continuing will uninstall the broken Elastic Agent at %s. Do you want to continue?", paths.InstallPath), true) + confirm, err := cli.Confirm(fmt.Sprintf("Continuing will uninstall the broken Elastic Agent at %s. Do you want to continue?", paths.InstallPath), true) if err != nil { return fmt.Errorf("problem reading prompt response") } @@ -68,7 +67,7 @@ func uninstallCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) err } } else { if !force { - confirm, err := c.Confirm(fmt.Sprintf("Elastic Agent will be uninstalled from your system at %s. Do you want to continue?", paths.InstallPath), true) + confirm, err := cli.Confirm(fmt.Sprintf("Elastic Agent will be uninstalled from your system at %s. Do you want to continue?", paths.InstallPath), true) if err != nil { return fmt.Errorf("problem reading prompt response") } @@ -84,6 +83,6 @@ func uninstallCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) err } fmt.Fprintf(streams.Out, "Elastic Agent has been uninstalled.\n") - install.RemovePath(paths.InstallPath) + _ = install.RemovePath(paths.InstallPath) return nil } diff --git a/internal/pkg/agent/cmd/watch.go b/internal/pkg/agent/cmd/watch.go index 258e9650a27..b1a4988906d 100644 --- a/internal/pkg/agent/cmd/watch.go +++ b/internal/pkg/agent/cmd/watch.go @@ -9,7 +9,6 @@ import ( "fmt" "os" "os/signal" - "runtime" "syscall" "time" @@ -39,8 +38,8 @@ func newWatchCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command Use: "watch", Short: "Watch watches Elastic Agent for failures and initiates rollback.", Long: `Watch watches Elastic Agent for failures and initiates rollback.`, - Run: func(c *cobra.Command, args []string) { - if err := watchCmd(streams, c, args); err != nil { + Run: func(_ *cobra.Command, _ []string) { + if err := watchCmd(); err != nil { fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) os.Exit(1) } @@ -50,7 +49,7 @@ func newWatchCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command return cmd } -func watchCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error { +func watchCmd() error { log, err := configuredLogger() if err != nil { return err @@ -77,7 +76,9 @@ func watchCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error { log.Error("failed to acquire lock", err) return err } - defer locker.Unlock() + defer func() { + _ = locker.Unlock() + }() isWithinGrace, tilGrace := gracePeriod(marker) if !isWithinGrace { @@ -106,7 +107,7 @@ func watchCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error { // cleanup older versions, // in windows it might leave self untouched, this will get cleaned up // later at the start, because for windows we leave marker untouched. - removeMarker := runtime.GOOS != "windows" + removeMarker := !isWindows() err = upgrade.Cleanup(marker.Hash, removeMarker) if err != nil { log.Error("rollback failed", err) @@ -141,7 +142,7 @@ func watch(ctx context.Context, tilGrace time.Duration, log *logger.Logger) erro go crashChecker.Run(ctx) signals := make(chan os.Signal, 1) - signal.Notify(signals, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) + signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) t := time.NewTimer(tilGrace) defer t.Stop() diff --git a/internal/pkg/agent/configuration/fleet_server.go b/internal/pkg/agent/configuration/fleet_server.go index 8f52ff92f66..a0e8348f47b 100644 --- a/internal/pkg/agent/configuration/fleet_server.go +++ b/internal/pkg/agent/configuration/fleet_server.go @@ -7,7 +7,7 @@ package configuration import ( "net/url" - "github.com/elastic/beats/v7/libbeat/common/transport/tlscommon" + "github.com/elastic/elastic-agent-libs/transport/tlscommon" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" ) diff --git a/internal/pkg/agent/control/client/dial_windows.go b/internal/pkg/agent/control/client/dial_windows.go index 76abf87575f..503c785fd8e 100644 --- a/internal/pkg/agent/control/client/dial_windows.go +++ b/internal/pkg/agent/control/client/dial_windows.go @@ -13,8 +13,7 @@ import ( "google.golang.org/grpc" - "github.com/elastic/beats/v7/libbeat/api/npipe" - + "github.com/elastic/elastic-agent-libs/api/npipe" "github.com/elastic/elastic-agent/internal/pkg/agent/control" ) diff --git a/internal/pkg/agent/control/control_test.go b/internal/pkg/agent/control/control_test.go index 74a7e571de3..09f77960185 100644 --- a/internal/pkg/agent/control/control_test.go +++ b/internal/pkg/agent/control/control_test.go @@ -13,8 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/logp" - + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/control/client" "github.com/elastic/elastic-agent/internal/pkg/agent/control/server" "github.com/elastic/elastic-agent/internal/pkg/core/status" diff --git a/internal/pkg/agent/control/server/listener_windows.go b/internal/pkg/agent/control/server/listener_windows.go index b705218f041..69d211502ea 100644 --- a/internal/pkg/agent/control/server/listener_windows.go +++ b/internal/pkg/agent/control/server/listener_windows.go @@ -13,8 +13,7 @@ import ( "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/api/npipe" - + "github.com/elastic/elastic-agent-libs/api/npipe" "github.com/elastic/elastic-agent/internal/pkg/agent/control" "github.com/elastic/elastic-agent/pkg/core/logger" ) diff --git a/internal/pkg/agent/install/uninstall.go b/internal/pkg/agent/install/uninstall.go index dd00d5e1db2..87ff47ae169 100644 --- a/internal/pkg/agent/install/uninstall.go +++ b/internal/pkg/agent/install/uninstall.go @@ -16,7 +16,7 @@ import ( "github.com/kardianos/service" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/application/info" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" @@ -55,7 +55,6 @@ func Uninstall(cfgFile string) error { fmt.Sprintf("failed to stop service (%s)", paths.ServiceName), errors.M("service", paths.ServiceName)) } - status = service.StatusStopped } _ = svc.Uninstall() @@ -77,7 +76,7 @@ func Uninstall(cfgFile string) error { // remove existing directory err = os.RemoveAll(paths.InstallPath) if err != nil { - if runtime.GOOS == "windows" { + if runtime.GOOS == "windows" { //nolint:goconst // it is more readable this way // possible to fail on Windows, because elastic-agent.exe is running from // this directory. return nil @@ -116,6 +115,7 @@ func delayedRemoval(path string) { // The installation path will still exists because we are executing from that // directory. So cmd.exe is spawned that sleeps for 2 seconds (using ping, recommend way from // from Windows) then rmdir is performed. + //nolint:gosec // it's not tainted rmdir := exec.Command( filepath.Join(os.Getenv("windir"), "system32", "cmd.exe"), "/C", "ping", "-n", "2", "127.0.0.1", "&&", "rmdir", "/s", "/q", path) @@ -163,7 +163,7 @@ func uninstallPrograms(ctx context.Context, cfgFile string) error { for _, p := range pp { descriptor := app.NewDescriptor(p.Spec, currentVersion, artifactConfig, nil) if err := uninstaller.Uninstall(ctx, p.Spec, currentVersion, descriptor.Directory()); err != nil { - fmt.Printf("failed to uninstall '%s': %v\n", p.Spec.Name, err) + os.Stderr.WriteString(fmt.Sprintf("failed to uninstall '%s': %v\n", p.Spec.Name, err)) } } @@ -244,7 +244,7 @@ func applyDynamics(ctx context.Context, log *logger.Logger, cfg *config.Config) if err != nil { return nil, err } - ctrl.Run(ctx, varsCallback) + _ = ctrl.Run(ctx, varsCallback) wg.Wait() renderedInputs, err := transpiler.RenderInputs(inputs, varsArray) @@ -273,7 +273,7 @@ func applyDynamics(ctx context.Context, log *logger.Logger, cfg *config.Config) ast = newAst } - finalConfig, err := newAst.Map() + finalConfig, err := ast.Map() if err != nil { return nil, err } diff --git a/internal/pkg/agent/operation/common_test.go b/internal/pkg/agent/operation/common_test.go index ba3ad5ab660..60193c4c4e2 100644 --- a/internal/pkg/agent/operation/common_test.go +++ b/internal/pkg/agent/operation/common_test.go @@ -14,7 +14,7 @@ import ( "go.elastic.co/apm/apmtest" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/application/info" "github.com/elastic/elastic-agent/internal/pkg/agent/configuration" "github.com/elastic/elastic-agent/internal/pkg/agent/program" diff --git a/internal/pkg/agent/transpiler/vars.go b/internal/pkg/agent/transpiler/vars.go index 4b52aeb9c2b..8daacf606fe 100644 --- a/internal/pkg/agent/transpiler/vars.go +++ b/internal/pkg/agent/transpiler/vars.go @@ -10,9 +10,8 @@ import ( "strings" "unicode" + "github.com/elastic/elastic-agent-libs/mapstr" "github.com/elastic/elastic-agent/internal/pkg/core/composable" - - "github.com/elastic/beats/v7/libbeat/common" ) var varsRegex = regexp.MustCompile(`\${([\p{L}\d\s\\\-_|.'"]*)}`) @@ -25,16 +24,16 @@ type Vars struct { tree *AST processorsKey string processors Processors - fetchContextProviders common.MapStr + fetchContextProviders mapstr.M } // NewVars returns a new instance of vars. -func NewVars(mapping map[string]interface{}, fetchContextProviders common.MapStr) (*Vars, error) { +func NewVars(mapping map[string]interface{}, fetchContextProviders mapstr.M) (*Vars, error) { return NewVarsWithProcessors(mapping, "", nil, fetchContextProviders) } // NewVarsWithProcessors returns a new instance of vars with attachment of processors. -func NewVarsWithProcessors(mapping map[string]interface{}, processorKey string, processors Processors, fetchContextProviders common.MapStr) (*Vars, error) { +func NewVarsWithProcessors(mapping map[string]interface{}, processorKey string, processors Processors, fetchContextProviders mapstr.M) (*Vars, error) { tree, err := NewAST(mapping) if err != nil { return nil, err @@ -105,7 +104,10 @@ func (v *Vars) lookupNode(name string) (Node, bool) { // check if the value can be retrieved from a FetchContextProvider for providerName, provider := range v.fetchContextProviders { if varPrefixMatched(name, providerName) { - fetchProvider := provider.(composable.FetchContextProvider) + fetchProvider, ok := provider.(composable.FetchContextProvider) + if !ok { + return &StrVal{value: ""}, false + } fval, found := fetchProvider.Fetch(name) if found { return &StrVal{value: fval}, true diff --git a/internal/pkg/agent/transpiler/vars_test.go b/internal/pkg/agent/transpiler/vars_test.go index 650dbaf5cb3..5dd6d41ec72 100644 --- a/internal/pkg/agent/transpiler/vars_test.go +++ b/internal/pkg/agent/transpiler/vars_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/common" + "github.com/elastic/elastic-agent-libs/mapstr" corecomp "github.com/elastic/elastic-agent/internal/pkg/core/composable" ) @@ -263,7 +263,7 @@ func TestVars_ReplaceWithFetchContextProvider(t *testing.T) { mockFetchProvider, err := MockContextProviderBuilder() require.NoError(t, err) - fetchContextProviders := common.MapStr{ + fetchContextProviders := mapstr.M{ "kubernetes_secrets": mockFetchProvider, } vars, err := NewVarsWithProcessors( diff --git a/internal/pkg/artifact/config.go b/internal/pkg/artifact/config.go index fe2bb48d918..c190c02d239 100644 --- a/internal/pkg/artifact/config.go +++ b/internal/pkg/artifact/config.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" ) diff --git a/internal/pkg/artifact/download/fs/verifier_test.go b/internal/pkg/artifact/download/fs/verifier_test.go index 7499fc058c6..a758f90f300 100644 --- a/internal/pkg/artifact/download/fs/verifier_test.go +++ b/internal/pkg/artifact/download/fs/verifier_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent/internal/pkg/agent/program" "github.com/elastic/elastic-agent/internal/pkg/artifact" "github.com/elastic/elastic-agent/internal/pkg/artifact/download" @@ -167,7 +167,7 @@ func prepareFetchVerifyTests(dropPath, targetDir, targetFilePath, hashTargetFile } corruptedHash := append([]byte{1, 2, 3, 4, 5, 6}, hashContent[6:]...) - return ioutil.WriteFile(hashTargetFilePath, corruptedHash, 0666) + return ioutil.WriteFile(hashTargetFilePath, corruptedHash, 0666) //nolint:gosec // no sweat, it's a test } func TestVerify(t *testing.T) { @@ -230,11 +230,11 @@ func prepareTestCase(beatSpec program.Spec, version string, cfg *artifact.Config hash := sha512.Sum512(content) hashContent := fmt.Sprintf("%x %s", hash, filename) - if err := ioutil.WriteFile(filepath.Join(cfg.DropPath, filename), []byte(content), 0644); err != nil { + if err := ioutil.WriteFile(filepath.Join(cfg.DropPath, filename), content, 0644); err != nil { //nolint:gosec // no sweat, it's a test return err } - return ioutil.WriteFile(filepath.Join(cfg.DropPath, filename+".sha512"), []byte(hashContent), 0644) + return ioutil.WriteFile(filepath.Join(cfg.DropPath, filename+".sha512"), []byte(hashContent), 0644) //nolint:gosec // no sweat, it's a test } func assertFileExists(t testing.TB, path string) { diff --git a/internal/pkg/artifact/download/http/downloader.go b/internal/pkg/artifact/download/http/downloader.go index a046e6ca19b..2da6e3d1015 100644 --- a/internal/pkg/artifact/download/http/downloader.go +++ b/internal/pkg/artifact/download/http/downloader.go @@ -18,8 +18,8 @@ import ( "github.com/docker/go-units" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" "github.com/elastic/elastic-agent-libs/atomic" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/agent/program" diff --git a/internal/pkg/artifact/download/http/downloader_test.go b/internal/pkg/artifact/download/http/downloader_test.go index 2df02fcdc8d..6fa2777c02f 100644 --- a/internal/pkg/artifact/download/http/downloader_test.go +++ b/internal/pkg/artifact/download/http/downloader_test.go @@ -20,8 +20,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" - + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent/internal/pkg/artifact" ) diff --git a/internal/pkg/artifact/download/http/elastic_test.go b/internal/pkg/artifact/download/http/elastic_test.go index 4e07abf6f82..c29b8115089 100644 --- a/internal/pkg/artifact/download/http/elastic_test.go +++ b/internal/pkg/artifact/download/http/elastic_test.go @@ -18,13 +18,12 @@ import ( "testing" "time" - "github.com/elastic/elastic-agent/pkg/core/logger" - "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent/internal/pkg/agent/program" "github.com/elastic/elastic-agent/internal/pkg/artifact" + "github.com/elastic/elastic-agent/pkg/core/logger" ) const ( diff --git a/internal/pkg/artifact/download/http/verifier.go b/internal/pkg/artifact/download/http/verifier.go index b88c273558a..1fe855fa2af 100644 --- a/internal/pkg/artifact/download/http/verifier.go +++ b/internal/pkg/artifact/download/http/verifier.go @@ -13,7 +13,7 @@ import ( "path" "strings" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/agent/program" "github.com/elastic/elastic-agent/internal/pkg/artifact" @@ -138,7 +138,7 @@ func (v *Verifier) composeURI(filename, artifactName string) (string, error) { } func (v *Verifier) getPublicAsc(sourceURI string) ([]byte, error) { - resp, err := v.client.Get(sourceURI) + resp, err := v.client.Get(sourceURI) //nolint:noctx // keep previous behaviour if err != nil { return nil, errors.New(err, "failed loading public key", errors.TypeNetwork, errors.M(errors.MetaKeyURI, sourceURI)) } diff --git a/internal/pkg/artifact/download/snapshot/downloader.go b/internal/pkg/artifact/download/snapshot/downloader.go index d7266f4aec5..2fbe027ae4b 100644 --- a/internal/pkg/artifact/download/snapshot/downloader.go +++ b/internal/pkg/artifact/download/snapshot/downloader.go @@ -9,7 +9,7 @@ import ( "fmt" "strings" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent/internal/pkg/artifact" "github.com/elastic/elastic-agent/internal/pkg/artifact/download" "github.com/elastic/elastic-agent/internal/pkg/artifact/download/http" diff --git a/internal/pkg/basecmd/version/cmd_test.go b/internal/pkg/basecmd/version/cmd_test.go index 857efb1f81c..f7e4ae2e74f 100644 --- a/internal/pkg/basecmd/version/cmd_test.go +++ b/internal/pkg/basecmd/version/cmd_test.go @@ -14,8 +14,7 @@ import ( "go.elastic.co/apm/apmtest" "gopkg.in/yaml.v2" - "github.com/elastic/beats/v7/libbeat/logp" - + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/control/server" "github.com/elastic/elastic-agent/internal/pkg/cli" "github.com/elastic/elastic-agent/internal/pkg/release" @@ -25,8 +24,9 @@ import ( func TestCmdBinaryOnly(t *testing.T) { streams, _, out, _ := cli.NewTestingIOStreams() cmd := NewCommandWithArgs(streams) - cmd.Flags().Set("binary-only", "true") - err := cmd.Execute() + err := cmd.Flags().Set("binary-only", "true") + require.NoError(t, err) + err = cmd.Execute() require.NoError(t, err) version, err := ioutil.ReadAll(out) @@ -38,9 +38,11 @@ func TestCmdBinaryOnly(t *testing.T) { func TestCmdBinaryOnlyYAML(t *testing.T) { streams, _, out, _ := cli.NewTestingIOStreams() cmd := NewCommandWithArgs(streams) - cmd.Flags().Set("binary-only", "true") - cmd.Flags().Set("yaml", "true") - err := cmd.Execute() + err := cmd.Flags().Set("binary-only", "true") + require.NoError(t, err) + err = cmd.Flags().Set("yaml", "true") + require.NoError(t, err) + err = cmd.Execute() require.NoError(t, err) version, err := ioutil.ReadAll(out) @@ -77,8 +79,9 @@ func TestCmdDaemonYAML(t *testing.T) { streams, _, out, _ := cli.NewTestingIOStreams() cmd := NewCommandWithArgs(streams) - cmd.Flags().Set("yaml", "true") - err := cmd.Execute() + err := cmd.Flags().Set("yaml", "true") + require.NoError(t, err) + err = cmd.Execute() require.NoError(t, err) version, err := ioutil.ReadAll(out) @@ -109,8 +112,9 @@ func TestCmdDaemonErrYAML(t *testing.T) { // srv not started streams, _, out, _ := cli.NewTestingIOStreams() cmd := NewCommandWithArgs(streams) - cmd.Flags().Set("yaml", "true") - err := cmd.Execute() + err := cmd.Flags().Set("yaml", "true") + require.NoError(t, err) + err = cmd.Execute() require.Error(t, err) version, err := ioutil.ReadAll(out) diff --git a/internal/pkg/capabilities/capabilities_test.go b/internal/pkg/capabilities/capabilities_test.go index ed8bd62f74e..9f349836856 100644 --- a/internal/pkg/capabilities/capabilities_test.go +++ b/internal/pkg/capabilities/capabilities_test.go @@ -2,6 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. +//nolint:dupl // tests are not the same, just equivalent package capabilities import ( @@ -15,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/config" "github.com/elastic/elastic-agent/internal/pkg/core/status" "github.com/elastic/elastic-agent/pkg/core/logger" diff --git a/internal/pkg/composable/controller.go b/internal/pkg/composable/controller.go index be8612a78fc..a14e111194f 100644 --- a/internal/pkg/composable/controller.go +++ b/internal/pkg/composable/controller.go @@ -14,8 +14,7 @@ import ( "sync" "time" - "github.com/elastic/beats/v7/libbeat/common" - + "github.com/elastic/elastic-agent-libs/mapstr" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/agent/transpiler" "github.com/elastic/elastic-agent/internal/pkg/config" @@ -99,7 +98,7 @@ func (c *controller) Run(ctx context.Context, cb VarsCallback) error { notify := make(chan bool, 5000) localCtx, cancel := context.WithCancel(ctx) - fetchContextProviders := common.MapStr{} + fetchContextProviders := mapstr.M{} // run all the enabled context providers for name, state := range c.contextProviders { @@ -111,7 +110,7 @@ func (c *controller) Run(ctx context.Context, cb VarsCallback) error { return errors.New(err, fmt.Sprintf("failed to run provider '%s'", name), errors.TypeConfig, errors.M("provider", name)) } if p, ok := state.provider.(corecomp.FetchContextProvider); ok { - fetchContextProviders.Put(name, p) + _, _ = fetchContextProviders.Put(name, p) } } diff --git a/internal/pkg/composable/providers/docker/config.go b/internal/pkg/composable/providers/docker/config.go index adb5e01f037..99594412626 100644 --- a/internal/pkg/composable/providers/docker/config.go +++ b/internal/pkg/composable/providers/docker/config.go @@ -7,7 +7,7 @@ package docker import ( "time" - "github.com/elastic/beats/v7/libbeat/common/docker" + "github.com/elastic/elastic-agent-autodiscover/docker" ) // Config for docker provider diff --git a/internal/pkg/composable/providers/docker/docker.go b/internal/pkg/composable/providers/docker/docker.go index 3d58d9b4c68..4bdc6d11cfe 100644 --- a/internal/pkg/composable/providers/docker/docker.go +++ b/internal/pkg/composable/providers/docker/docker.go @@ -8,10 +8,11 @@ import ( "fmt" "time" - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/common/bus" - "github.com/elastic/beats/v7/libbeat/common/docker" - "github.com/elastic/beats/v7/libbeat/common/safemapstr" + "github.com/elastic/elastic-agent-autodiscover/bus" + "github.com/elastic/elastic-agent-autodiscover/docker" + "github.com/elastic/elastic-agent-autodiscover/utils" + "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-libs/safemapstr" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/composable" "github.com/elastic/elastic-agent/internal/pkg/config" @@ -22,7 +23,7 @@ import ( const ContainerPriority = 0 func init() { - composable.Providers.AddDynamicProvider("docker", DynamicProviderBuilder) + _ = composable.Providers.AddDynamicProvider("docker", DynamicProviderBuilder) } type dockerContainerData struct { @@ -79,7 +80,10 @@ func (c *dynamicProvider) Run(comm composable.DynamicProviderComm) error { delete(stoppers, data.container.ID) return } - comm.AddOrUpdate(data.container.ID, ContainerPriority, data.mapping, data.processors) + err = comm.AddOrUpdate(data.container.ID, ContainerPriority, data.mapping, data.processors) + if err != nil { + c.logger.Errorf("%s", err) + } case event := <-stopListener.Events(): data, err := generateData(event) if err != nil { @@ -119,11 +123,11 @@ func generateData(event bus.Event) (*dockerContainerData, error) { return nil, fmt.Errorf("unable to get container from watcher event") } - labelMap := common.MapStr{} - processorLabelMap := common.MapStr{} + labelMap := mapstr.M{} + processorLabelMap := mapstr.M{} for k, v := range container.Labels { - safemapstr.Put(labelMap, k, v) - processorLabelMap.Put(common.DeDot(k), v) + _ = safemapstr.Put(labelMap, k, v) + _, _ = processorLabelMap.Put(utils.DeDot(k), v) } data := &dockerContainerData{ diff --git a/internal/pkg/composable/providers/docker/docker_test.go b/internal/pkg/composable/providers/docker/docker_test.go index 55cf2f3a238..d0b5c69ba4d 100644 --- a/internal/pkg/composable/providers/docker/docker_test.go +++ b/internal/pkg/composable/providers/docker/docker_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/common/bus" - "github.com/elastic/beats/v7/libbeat/common/docker" + "github.com/elastic/elastic-agent-autodiscover/bus" + "github.com/elastic/elastic-agent-autodiscover/docker" + "github.com/elastic/elastic-agent-libs/mapstr" ) func TestGenerateData(t *testing.T) { @@ -35,9 +35,9 @@ func TestGenerateData(t *testing.T) { "id": container.ID, "name": container.Name, "image": container.Image, - "labels": common.MapStr{ - "do": common.MapStr{"not": common.MapStr{"include": "true"}}, - "co": common.MapStr{"elastic": common.MapStr{"logs/disable": "true"}}, + "labels": mapstr.M{ + "do": mapstr.M{"not": mapstr.M{"include": "true"}}, + "co": mapstr.M{"elastic": mapstr.M{"logs/disable": "true"}}, }, }, } @@ -48,7 +48,7 @@ func TestGenerateData(t *testing.T) { "id": container.ID, "name": container.Name, "image": container.Image, - "labels": common.MapStr{ + "labels": mapstr.M{ "do_not_include": "true", "co_elastic_logs/disable": "true", }, diff --git a/internal/pkg/composable/providers/kubernetes/config.go b/internal/pkg/composable/providers/kubernetes/config.go index 29014021b06..9bec67b66b8 100644 --- a/internal/pkg/composable/providers/kubernetes/config.go +++ b/internal/pkg/composable/providers/kubernetes/config.go @@ -7,10 +7,9 @@ package kubernetes import ( "time" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" - - "github.com/elastic/beats/v7/libbeat/common/kubernetes/metadata" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes/metadata" + "github.com/elastic/elastic-agent-libs/logp" ) // Config for kubernetes provider @@ -53,7 +52,7 @@ type Enabled struct { func (c *Config) InitDefaults() { c.CleanupTimeout = 60 * time.Second c.SyncPeriod = 10 * time.Minute - c.Scope = "node" + c.Scope = nodeScope c.LabelsDedot = true c.AnnotationsDedot = true c.AddResourceMetadata = metadata.GetDefaultResourceMetadataConfig() @@ -63,7 +62,7 @@ func (c *Config) InitDefaults() { func (c *Config) Validate() error { // Check if resource is service. If yes then default the scope to "cluster". if c.Resources.Service.Enabled { - if c.Scope == "node" { + if c.Scope == nodeScope { logp.L().Warnf("can not set scope to `node` when using resource `Service`. resetting scope to `cluster`") } c.Scope = "cluster" diff --git a/internal/pkg/composable/providers/kubernetes/kubernetes.go b/internal/pkg/composable/providers/kubernetes/kubernetes.go index d918c854205..91367c5252f 100644 --- a/internal/pkg/composable/providers/kubernetes/kubernetes.go +++ b/internal/pkg/composable/providers/kubernetes/kubernetes.go @@ -9,7 +9,7 @@ import ( k8s "k8s.io/client-go/kubernetes" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/composable" "github.com/elastic/elastic-agent/internal/pkg/config" @@ -27,8 +27,10 @@ const ( ServicePriority = 3 ) +const nodeScope = "node" + func init() { - composable.Providers.AddDynamicProvider("kubernetes", DynamicProviderBuilder) + _ = composable.Providers.AddDynamicProvider("kubernetes", DynamicProviderBuilder) } type dynamicProvider struct { @@ -59,7 +61,7 @@ func (p *dynamicProvider) Run(comm composable.DynamicProviderComm) error { } } if p.config.Resources.Node.Enabled { - err := p.watchResource(comm, "node") + err := p.watchResource(comm, nodeScope) if err != nil { return err } @@ -88,7 +90,7 @@ func (p *dynamicProvider) watchResource( // Ensure that node is set correctly whenever the scope is set to "node". Make sure that node is empty // when cluster scope is enforced. p.logger.Infof("Kubernetes provider started for resource %s with %s scope", resourceType, p.config.Scope) - if p.config.Scope == "node" { + if p.config.Scope == nodeScope { p.logger.Debugf( "Initializing Kubernetes watcher for resource %s using node: %v", @@ -142,7 +144,7 @@ func (p *dynamicProvider) newEventer( return nil, err } return eventer, nil - case "node": + case nodeScope: eventer, err := NewNodeEventer(comm, p.config, p.logger, client, p.config.Scope) if err != nil { return nil, err diff --git a/internal/pkg/composable/providers/kubernetes/node.go b/internal/pkg/composable/providers/kubernetes/node.go index 7cdbdbf559d..a1539afb9c1 100644 --- a/internal/pkg/composable/providers/kubernetes/node.go +++ b/internal/pkg/composable/providers/kubernetes/node.go @@ -11,11 +11,12 @@ import ( "k8s.io/apimachinery/pkg/api/equality" k8s "k8s.io/client-go/kubernetes" - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" - "github.com/elastic/beats/v7/libbeat/common/kubernetes/metadata" - "github.com/elastic/beats/v7/libbeat/common/safemapstr" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes/metadata" + c "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-libs/safemapstr" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/composable" ) @@ -53,7 +54,7 @@ func NewNodeEventer( return nil, errors.New(err, "couldn't create kubernetes watcher") } - rawConfig, err := common.NewConfigFrom(cfg) + rawConfig, err := c.NewConfigFrom(cfg) if err != nil { return nil, errors.New(err, "failed to unpack configuration") } @@ -72,14 +73,14 @@ func NewNodeEventer( } func (n *node) emitRunning(node *kubernetes.Node) { - data := generateNodeData(node, n.config, n.metagen) + data := generateNodeData(node, n.metagen) if data == nil { return } data.mapping["scope"] = n.scope // Emit the node - n.comm.AddOrUpdate(string(node.GetUID()), NodePriority, data.mapping, data.processors) + _ = n.comm.AddOrUpdate(string(node.GetUID()), NodePriority, data.mapping, data.processors) } func (n *node) emitStopped(node *kubernetes.Node) { @@ -104,7 +105,7 @@ func (n *node) OnAdd(obj interface{}) { // OnUpdate ensures processing of node objects that are updated func (n *node) OnUpdate(obj interface{}) { - node := obj.(*kubernetes.Node) + node, _ := obj.(*kubernetes.Node) if node.GetObjectMeta().GetDeletionTimestamp() != nil { n.logger.Debugf("Watcher Node update (terminating): %+v", obj) // Node is terminating, don't reload its configuration and ignore the event as long as node is Ready. @@ -121,7 +122,7 @@ func (n *node) OnUpdate(obj interface{}) { // OnDelete ensures processing of node objects that are deleted func (n *node) OnDelete(obj interface{}) { n.logger.Debugf("Watcher Node delete: %+v", obj) - node := obj.(*kubernetes.Node) + node, _ := obj.(*kubernetes.Node) time.AfterFunc(n.cleanupTimeout, func() { n.emitStopped(node) }) } @@ -192,7 +193,7 @@ func isNodeReady(node *kubernetes.Node) bool { return false } -func generateNodeData(node *kubernetes.Node, cfg *Config, kubeMetaGen metadata.MetaGen) *nodeData { +func generateNodeData(node *kubernetes.Node, kubeMetaGen metadata.MetaGen) *nodeData { host := getAddress(node) // If a node doesn't have an IP then dont monitor it @@ -212,14 +213,14 @@ func generateNodeData(node *kubernetes.Node, cfg *Config, kubeMetaGen metadata.M } // Pass annotations to all events so that it can be used in templating and by annotation builders. - annotations := common.MapStr{} + annotations := mapstr.M{} for k, v := range node.GetObjectMeta().GetAnnotations() { - safemapstr.Put(annotations, k, v) + _ = safemapstr.Put(annotations, k, v) } // k8sMapping includes only the metadata that fall under kubernetes.* // and these are available as dynamic vars through the provider - k8sMapping := map[string]interface{}(kubemetaMap.(common.MapStr).Clone()) + k8sMapping := map[string]interface{}(kubemetaMap.(mapstr.M).Clone()) // add annotations to be discoverable by templates k8sMapping["annotations"] = annotations diff --git a/internal/pkg/composable/providers/kubernetes/node_test.go b/internal/pkg/composable/providers/kubernetes/node_test.go index f42af49f988..7d8abfcea4e 100644 --- a/internal/pkg/composable/providers/kubernetes/node_test.go +++ b/internal/pkg/composable/providers/kubernetes/node_test.go @@ -7,21 +7,20 @@ package kubernetes import ( "testing" - "github.com/elastic/beats/v7/libbeat/common/kubernetes/metadata" - - "github.com/elastic/beats/v7/libbeat/common" - "github.com/stretchr/testify/assert" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes/metadata" + "github.com/elastic/elastic-agent-libs/mapstr" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - - "github.com/elastic/beats/v7/libbeat/common/kubernetes" ) +const uid = "005f3b90-4b9d-12f8-acf0-31020a840133" + func TestGenerateNodeData(t *testing.T) { - uid := "005f3b90-4b9d-12f8-acf0-31020a840133" node := &kubernetes.Node{ ObjectMeta: kubernetes.ObjectMeta{ Name: "testnode", @@ -43,41 +42,41 @@ func TestGenerateNodeData(t *testing.T) { }, } - data := generateNodeData(node, &Config{}, &nodeMeta{}) + data := generateNodeData(node, &nodeMeta{}) mapping := map[string]interface{}{ - "node": common.MapStr{ + "node": mapstr.M{ "uid": string(node.GetUID()), "name": node.GetName(), "ip": "node1", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "baz": "ban", }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, } processors := map[string]interface{}{ - "orchestrator": common.MapStr{ - "cluster": common.MapStr{ + "orchestrator": mapstr.M{ + "cluster": mapstr.M{ "name": "devcluster", "url": "8.8.8.8:9090"}, - }, "kubernetes": common.MapStr{ - "labels": common.MapStr{"foo": "bar"}, - "annotations": common.MapStr{"baz": "ban"}, - "node": common.MapStr{ + }, "kubernetes": mapstr.M{ + "labels": mapstr.M{"foo": "bar"}, + "annotations": mapstr.M{"baz": "ban"}, + "node": mapstr.M{ "ip": "node1", "name": "testnode", - "uid": "005f3b90-4b9d-12f8-acf0-31020a840133"}, + "uid": uid}, }, } assert.Equal(t, node, data.node) assert.Equal(t, mapping, data.mapping) for _, v := range data.processors { - k := v["add_fields"].(map[string]interface{}) - target := k["target"].(string) + k, _ := v["add_fields"].(map[string]interface{}) + target, _ := k["target"].(string) fields := k["fields"] assert.Equal(t, processors[target], fields) } @@ -93,9 +92,9 @@ type nodeMeta struct{} // } // All Kubernetes fields that need to be stored under kubernetes. prefix are populated by // GenerateK8s method while fields that are part of ECS are generated by GenerateECS method -func (n *nodeMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOptions) common.MapStr { +func (n *nodeMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOptions) mapstr.M { ecsFields := n.GenerateECS(obj) - meta := common.MapStr{ + meta := mapstr.M{ "kubernetes": n.GenerateK8s(obj, opts...), } meta.DeepUpdate(ecsFields) @@ -103,10 +102,10 @@ func (n *nodeMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOptio } // GenerateECS generates node ECS metadata from a resource object -func (n *nodeMeta) GenerateECS(obj kubernetes.Resource) common.MapStr { - return common.MapStr{ - "orchestrator": common.MapStr{ - "cluster": common.MapStr{ +func (n *nodeMeta) GenerateECS(obj kubernetes.Resource) mapstr.M { + return mapstr.M{ + "orchestrator": mapstr.M{ + "cluster": mapstr.M{ "name": "devcluster", "url": "8.8.8.8:9090", }, @@ -115,24 +114,24 @@ func (n *nodeMeta) GenerateECS(obj kubernetes.Resource) common.MapStr { } // GenerateK8s generates node metadata from a resource object -func (n *nodeMeta) GenerateK8s(obj kubernetes.Resource, opts ...metadata.FieldOptions) common.MapStr { - k8sNode := obj.(*kubernetes.Node) - return common.MapStr{ - "node": common.MapStr{ +func (n *nodeMeta) GenerateK8s(obj kubernetes.Resource, opts ...metadata.FieldOptions) mapstr.M { + k8sNode, _ := obj.(*kubernetes.Node) + return mapstr.M{ + "node": mapstr.M{ "uid": string(k8sNode.GetUID()), "name": k8sNode.GetName(), "ip": "node1", }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "baz": "ban", }, } } // GenerateFromName generates node metadata from a node name -func (n *nodeMeta) GenerateFromName(name string, opts ...metadata.FieldOptions) common.MapStr { +func (n *nodeMeta) GenerateFromName(name string, opts ...metadata.FieldOptions) mapstr.M { return nil } diff --git a/internal/pkg/composable/providers/kubernetes/pod.go b/internal/pkg/composable/providers/kubernetes/pod.go index a14369ad0f8..a8b11b06585 100644 --- a/internal/pkg/composable/providers/kubernetes/pod.go +++ b/internal/pkg/composable/providers/kubernetes/pod.go @@ -9,14 +9,15 @@ import ( "sync" "time" - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/common/safemapstr" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes/metadata" + c "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-libs/safemapstr" k8s "k8s.io/client-go/kubernetes" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" - "github.com/elastic/beats/v7/libbeat/common/kubernetes/metadata" - "github.com/elastic/beats/v7/libbeat/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/composable" ) @@ -78,7 +79,7 @@ func NewPodEventer( logger.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Namespace{}, err) } - rawConfig, err := common.NewConfigFrom(cfg) + rawConfig, err := c.NewConfigFrom(cfg) if err != nil { return nil, errors.New(err, "failed to unpack configuration") } @@ -146,20 +147,20 @@ func (p *pod) emitRunning(pod *kubernetes.Pod) { namespaceAnnotations := kubernetes.PodNamespaceAnnotations(pod, p.namespaceWatcher) - data := generatePodData(pod, p.config, p.metagen, namespaceAnnotations) + data := generatePodData(pod, p.metagen, namespaceAnnotations) data.mapping["scope"] = p.scope // Emit the pod // We emit Pod + containers to ensure that configs matching Pod only // get Pod metadata (not specific to any container) - p.comm.AddOrUpdate(data.uid, PodPriority, data.mapping, data.processors) + _ = p.comm.AddOrUpdate(data.uid, PodPriority, data.mapping, data.processors) // Emit all containers in the pod - // TODO: deal with init containers stopping after initialization + // We should deal with init containers stopping after initialization p.emitContainers(pod, namespaceAnnotations) } -func (p *pod) emitContainers(pod *kubernetes.Pod, namespaceAnnotations common.MapStr) { - generateContainerData(p.comm, pod, p.config, p.metagen, namespaceAnnotations) +func (p *pod) emitContainers(pod *kubernetes.Pod, namespaceAnnotations mapstr.M) { + generateContainerData(p.comm, pod, p.metagen, namespaceAnnotations) } func (p *pod) emitStopped(pod *kubernetes.Pod) { @@ -199,7 +200,7 @@ func (p *pod) OnUpdate(obj interface{}) { func (p *pod) unlockedUpdate(obj interface{}) { p.logger.Debugf("Watcher Pod update: %+v", obj) - pod := obj.(*kubernetes.Pod) + pod, _ := obj.(*kubernetes.Pod) p.emitRunning(pod) } @@ -209,7 +210,7 @@ func (p *pod) OnDelete(obj interface{}) { defer p.crossUpdate.RUnlock() p.logger.Debugf("pod delete: %+v", obj) - pod := obj.(*kubernetes.Pod) + pod, _ := obj.(*kubernetes.Pod) time.AfterFunc(p.cleanupTimeout, func() { p.emitStopped(pod) }) @@ -217,9 +218,8 @@ func (p *pod) OnDelete(obj interface{}) { func generatePodData( pod *kubernetes.Pod, - cfg *Config, kubeMetaGen metadata.MetaGen, - namespaceAnnotations common.MapStr) providerData { + namespaceAnnotations mapstr.M) providerData { meta := kubeMetaGen.Generate(pod) kubemetaMap, err := meta.GetValue("kubernetes") @@ -229,15 +229,15 @@ func generatePodData( // k8sMapping includes only the metadata that fall under kubernetes.* // and these are available as dynamic vars through the provider - k8sMapping := map[string]interface{}(kubemetaMap.(common.MapStr).Clone()) + k8sMapping := map[string]interface{}(kubemetaMap.(mapstr.M).Clone()) if len(namespaceAnnotations) != 0 { k8sMapping["namespace_annotations"] = namespaceAnnotations } // Pass annotations to all events so that it can be used in templating and by annotation builders. - annotations := common.MapStr{} + annotations := mapstr.M{} for k, v := range pod.GetObjectMeta().GetAnnotations() { - safemapstr.Put(annotations, k, v) + _ = safemapstr.Put(annotations, k, v) } k8sMapping["annotations"] = annotations @@ -264,16 +264,15 @@ func generatePodData( func generateContainerData( comm composable.DynamicProviderComm, pod *kubernetes.Pod, - cfg *Config, kubeMetaGen metadata.MetaGen, - namespaceAnnotations common.MapStr) { + namespaceAnnotations mapstr.M) { containers := kubernetes.GetContainersInPod(pod) // Pass annotations to all events so that it can be used in templating and by annotation builders. - annotations := common.MapStr{} + annotations := mapstr.M{} for k, v := range pod.GetObjectMeta().GetAnnotations() { - safemapstr.Put(annotations, k, v) + _ = safemapstr.Put(annotations, k, v) } for _, c := range containers { @@ -295,7 +294,7 @@ func generateContainerData( // k8sMapping includes only the metadata that fall under kubernetes.* // and these are available as dynamic vars through the provider - k8sMapping := map[string]interface{}(kubemetaMap.(common.MapStr).Clone()) + k8sMapping := map[string]interface{}(kubemetaMap.(mapstr.M).Clone()) if len(namespaceAnnotations) != 0 { k8sMapping["namespace_annotations"] = namespaceAnnotations @@ -304,10 +303,10 @@ func generateContainerData( k8sMapping["annotations"] = annotations //container ECS fields - cmeta := common.MapStr{ + cmeta := mapstr.M{ "id": c.ID, "runtime": c.Runtime, - "image": common.MapStr{ + "image": mapstr.M{ "name": c.Spec.Image, }, } @@ -334,7 +333,7 @@ func generateContainerData( // add container metadata under kubernetes.container.* to // make them available to dynamic var resolution - containerMeta := common.MapStr{ + containerMeta := mapstr.M{ "id": c.ID, "name": c.Spec.Name, "image": c.Spec.Image, @@ -342,14 +341,14 @@ func generateContainerData( } if len(c.Spec.Ports) > 0 { for _, port := range c.Spec.Ports { - containerMeta.Put("port", fmt.Sprintf("%v", port.ContainerPort)) - containerMeta.Put("port_name", port.Name) + _, _ = containerMeta.Put("port", fmt.Sprintf("%v", port.ContainerPort)) + _, _ = containerMeta.Put("port_name", port.Name) k8sMapping["container"] = containerMeta - comm.AddOrUpdate(eventID, ContainerPriority, k8sMapping, processors) + _ = comm.AddOrUpdate(eventID, ContainerPriority, k8sMapping, processors) } } else { k8sMapping["container"] = containerMeta - comm.AddOrUpdate(eventID, ContainerPriority, k8sMapping, processors) + _ = comm.AddOrUpdate(eventID, ContainerPriority, k8sMapping, processors) } } } diff --git a/internal/pkg/composable/providers/kubernetes/pod_test.go b/internal/pkg/composable/providers/kubernetes/pod_test.go index 62d4a199892..45fd78ac76c 100644 --- a/internal/pkg/composable/providers/kubernetes/pod_test.go +++ b/internal/pkg/composable/providers/kubernetes/pod_test.go @@ -11,17 +11,16 @@ import ( "github.com/stretchr/testify/assert" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes/metadata" + "github.com/elastic/elastic-agent-libs/mapstr" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" - "github.com/elastic/beats/v7/libbeat/common/kubernetes/metadata" ) func TestGeneratePodData(t *testing.T) { - uid := "005f3b90-4b9d-12f8-acf0-31020a840133" pod := &kubernetes.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "testpod", @@ -44,57 +43,56 @@ func TestGeneratePodData(t *testing.T) { Status: kubernetes.PodStatus{PodIP: "127.0.0.5"}, } - namespaceAnnotations := common.MapStr{ + namespaceAnnotations := mapstr.M{ "nsa": "nsb", } - data := generatePodData(pod, &Config{}, &podMeta{}, namespaceAnnotations) + data := generatePodData(pod, &podMeta{}, namespaceAnnotations) mapping := map[string]interface{}{ "namespace": pod.GetNamespace(), - "pod": common.MapStr{ + "pod": mapstr.M{ "uid": string(pod.GetUID()), "name": pod.GetName(), "ip": pod.Status.PodIP, }, - "namespace_annotations": common.MapStr{ + "namespace_annotations": mapstr.M{ "nsa": "nsb", }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "app": "production", }, } processors := map[string]interface{}{ - "orchestrator": common.MapStr{ - "cluster": common.MapStr{ + "orchestrator": mapstr.M{ + "cluster": mapstr.M{ "name": "devcluster", "url": "8.8.8.8:9090"}, - }, "kubernetes": common.MapStr{ + }, "kubernetes": mapstr.M{ "namespace": "testns", - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, - "annotations": common.MapStr{"app": "production"}, - "pod": common.MapStr{ + "annotations": mapstr.M{"app": "production"}, + "pod": mapstr.M{ "ip": "127.0.0.5", "name": "testpod", - "uid": "005f3b90-4b9d-12f8-acf0-31020a840133"}}, + "uid": uid}}, } assert.Equal(t, string(pod.GetUID()), data.uid) assert.Equal(t, mapping, data.mapping) for _, v := range data.processors { - k := v["add_fields"].(map[string]interface{}) - target := k["target"].(string) + k, _ := v["add_fields"].(map[string]interface{}) + target, _ := k["target"].(string) fields := k["fields"] assert.Equal(t, processors[target], fields) } } func TestGenerateContainerPodData(t *testing.T) { - uid := "005f3b90-4b9d-12f8-acf0-31020a840133" containers := []kubernetes.Container{ { Name: "nginx", @@ -150,20 +148,19 @@ func TestGenerateContainerPodData(t *testing.T) { generateContainerData( &comm, pod, - &Config{}, &podMeta{}, - common.MapStr{ + mapstr.M{ "nsa": "nsb", }) mapping := map[string]interface{}{ "namespace": pod.GetNamespace(), - "pod": common.MapStr{ + "pod": mapstr.M{ "uid": string(pod.GetUID()), "name": pod.GetName(), "ip": pod.Status.PodIP, }, - "container": common.MapStr{ + "container": mapstr.M{ "id": "asdfghdeadbeef", "name": "nginx", "image": "nginx:1.120", @@ -171,42 +168,42 @@ func TestGenerateContainerPodData(t *testing.T) { "port": "80", "port_name": "http", }, - "namespace_annotations": common.MapStr{ + "namespace_annotations": mapstr.M{ "nsa": "nsb", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "app": "production", }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, } processors := map[string]interface{}{ - "container": common.MapStr{ + "container": mapstr.M{ "id": "asdfghdeadbeef", - "image": common.MapStr{"name": "nginx:1.120"}, + "image": mapstr.M{"name": "nginx:1.120"}, "runtime": "crio", - }, "orchestrator": common.MapStr{ - "cluster": common.MapStr{ + }, "orchestrator": mapstr.M{ + "cluster": mapstr.M{ "name": "devcluster", "url": "8.8.8.8:9090"}, - }, "kubernetes": common.MapStr{ + }, "kubernetes": mapstr.M{ "namespace": "testns", - "annotations": common.MapStr{"app": "production"}, - "labels": common.MapStr{"foo": "bar"}, - "pod": common.MapStr{ + "annotations": mapstr.M{"app": "production"}, + "labels": mapstr.M{"foo": "bar"}, + "pod": mapstr.M{ "ip": "127.0.0.5", "name": "testpod", - "uid": "005f3b90-4b9d-12f8-acf0-31020a840133"}}, + "uid": uid}}, } cuid := fmt.Sprintf("%s.%s", pod.GetObjectMeta().GetUID(), "nginx") data := <-providerDataChan assert.Equal(t, cuid, data.uid) assert.Equal(t, mapping, data.mapping) for _, v := range data.processors { - k := v["add_fields"].(map[string]interface{}) - target := k["target"].(string) + k, _ := v["add_fields"].(map[string]interface{}) + target, _ := k["target"].(string) fields := k["fields"] assert.Equal(t, processors[target], fields) } @@ -214,7 +211,6 @@ func TestGenerateContainerPodData(t *testing.T) { } func TestEphemeralContainers(t *testing.T) { - uid := "005f3b90-4b9d-12f8-acf0-31020a840133" containers := []v1.EphemeralContainer{ { EphemeralContainerCommon: v1.EphemeralContainerCommon{ @@ -265,61 +261,60 @@ func TestEphemeralContainers(t *testing.T) { generateContainerData( &comm, pod, - &Config{}, &podMeta{}, - common.MapStr{ + mapstr.M{ "nsa": "nsb", }) mapping := map[string]interface{}{ "namespace": pod.GetNamespace(), - "pod": common.MapStr{ + "pod": mapstr.M{ "uid": string(pod.GetUID()), "name": pod.GetName(), "ip": pod.Status.PodIP, }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, - "container": common.MapStr{ + "container": mapstr.M{ "id": "asdfghdeadbeef", "name": "nginx", "image": "nginx:1.120", "runtime": "crio", }, - "namespace_annotations": common.MapStr{ + "namespace_annotations": mapstr.M{ "nsa": "nsb", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "app": "production", }, } processors := map[string]interface{}{ - "container": common.MapStr{ + "container": mapstr.M{ "id": "asdfghdeadbeef", - "image": common.MapStr{"name": "nginx:1.120"}, + "image": mapstr.M{"name": "nginx:1.120"}, "runtime": "crio", - }, "orchestrator": common.MapStr{ - "cluster": common.MapStr{ + }, "orchestrator": mapstr.M{ + "cluster": mapstr.M{ "name": "devcluster", "url": "8.8.8.8:9090"}, - }, "kubernetes": common.MapStr{ + }, "kubernetes": mapstr.M{ "namespace": "testns", - "labels": common.MapStr{"foo": "bar"}, - "annotations": common.MapStr{"app": "production"}, - "pod": common.MapStr{ + "labels": mapstr.M{"foo": "bar"}, + "annotations": mapstr.M{"app": "production"}, + "pod": mapstr.M{ "ip": "127.0.0.5", "name": "testpod", - "uid": "005f3b90-4b9d-12f8-acf0-31020a840133"}}, + "uid": uid}}, } cuid := fmt.Sprintf("%s.%s", pod.GetObjectMeta().GetUID(), "nginx") data := <-providerDataChan assert.Equal(t, cuid, data.uid) assert.Equal(t, mapping, data.mapping) for _, v := range data.processors { - k := v["add_fields"].(map[string]interface{}) - target := k["target"].(string) + k, _ := v["add_fields"].(map[string]interface{}) + target, _ := k["target"].(string) fields := k["fields"] assert.Equal(t, processors[target], fields) } @@ -356,9 +351,9 @@ type podMeta struct{} // } // All Kubernetes fields that need to be stored under kubernetes. prefix are populated by // GenerateK8s method while fields that are part of ECS are generated by GenerateECS method -func (p *podMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOptions) common.MapStr { +func (p *podMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOptions) mapstr.M { ecsFields := p.GenerateECS(obj) - meta := common.MapStr{ + meta := mapstr.M{ "kubernetes": p.GenerateK8s(obj, opts...), } meta.DeepUpdate(ecsFields) @@ -366,10 +361,10 @@ func (p *podMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOption } // GenerateECS generates pod ECS metadata from a resource object -func (p *podMeta) GenerateECS(obj kubernetes.Resource) common.MapStr { - return common.MapStr{ - "orchestrator": common.MapStr{ - "cluster": common.MapStr{ +func (p *podMeta) GenerateECS(obj kubernetes.Resource) mapstr.M { + return mapstr.M{ + "orchestrator": mapstr.M{ + "cluster": mapstr.M{ "name": "devcluster", "url": "8.8.8.8:9090", }, @@ -378,25 +373,25 @@ func (p *podMeta) GenerateECS(obj kubernetes.Resource) common.MapStr { } // GenerateK8s generates pod metadata from a resource object -func (p *podMeta) GenerateK8s(obj kubernetes.Resource, opts ...metadata.FieldOptions) common.MapStr { - k8sPod := obj.(*kubernetes.Pod) - return common.MapStr{ +func (p *podMeta) GenerateK8s(obj kubernetes.Resource, opts ...metadata.FieldOptions) mapstr.M { + k8sPod, _ := obj.(*kubernetes.Pod) + return mapstr.M{ "namespace": k8sPod.GetNamespace(), - "pod": common.MapStr{ + "pod": mapstr.M{ "uid": string(k8sPod.GetUID()), "name": k8sPod.GetName(), "ip": k8sPod.Status.PodIP, }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "app": "production", }, } } // GenerateFromName generates pod metadata from a node name -func (p *podMeta) GenerateFromName(name string, opts ...metadata.FieldOptions) common.MapStr { +func (p *podMeta) GenerateFromName(name string, opts ...metadata.FieldOptions) mapstr.M { return nil } diff --git a/internal/pkg/composable/providers/kubernetes/service.go b/internal/pkg/composable/providers/kubernetes/service.go index 52e9a06382a..49c20627734 100644 --- a/internal/pkg/composable/providers/kubernetes/service.go +++ b/internal/pkg/composable/providers/kubernetes/service.go @@ -8,14 +8,14 @@ import ( "fmt" "time" - "github.com/elastic/beats/v7/libbeat/common/kubernetes/metadata" - "github.com/elastic/beats/v7/libbeat/common/safemapstr" - k8s "k8s.io/client-go/kubernetes" - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes/metadata" + "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/elastic-agent-libs/safemapstr" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/composable" ) @@ -63,7 +63,7 @@ func NewServiceEventer( } namespaceMeta := metadata.NewNamespaceMetadataGenerator(metaConf.Namespace, namespaceWatcher.Store(), client) - rawConfig, err := common.NewConfigFrom(cfg) + rawConfig, err := config.NewConfigFrom(cfg) if err != nil { return nil, errors.New(err, "failed to unpack configuration") } @@ -105,18 +105,18 @@ func (s *service) Stop() { func (s *service) emitRunning(service *kubernetes.Service) { namespaceAnnotations := svcNamespaceAnnotations(service, s.namespaceWatcher) - data := generateServiceData(service, s.config, s.metagen, namespaceAnnotations) + data := generateServiceData(service, s.metagen, namespaceAnnotations) if data == nil { return } data.mapping["scope"] = s.scope // Emit the service - s.comm.AddOrUpdate(string(service.GetUID()), ServicePriority, data.mapping, data.processors) + _ = s.comm.AddOrUpdate(string(service.GetUID()), ServicePriority, data.mapping, data.processors) } // svcNamespaceAnnotations returns the annotations of the namespace of the service -func svcNamespaceAnnotations(svc *kubernetes.Service, watcher kubernetes.Watcher) common.MapStr { +func svcNamespaceAnnotations(svc *kubernetes.Service, watcher kubernetes.Watcher) mapstr.M { if watcher == nil { return nil } @@ -131,9 +131,9 @@ func svcNamespaceAnnotations(svc *kubernetes.Service, watcher kubernetes.Watcher return nil } - annotations := common.MapStr{} + annotations := mapstr.M{} for k, v := range namespace.GetAnnotations() { - safemapstr.Put(annotations, k, v) + _ = safemapstr.Put(annotations, k, v) } return annotations } @@ -150,7 +150,7 @@ func (s *service) OnAdd(obj interface{}) { // OnUpdate ensures processing of service objects that are updated func (s *service) OnUpdate(obj interface{}) { - service := obj.(*kubernetes.Service) + service, _ := obj.(*kubernetes.Service) // Once service is in terminated state, mark it for deletion if service.GetObjectMeta().GetDeletionTimestamp() != nil { s.logger.Debugf("Watcher Service update (terminating): %+v", obj) @@ -164,15 +164,14 @@ func (s *service) OnUpdate(obj interface{}) { // OnDelete ensures processing of service objects that are deleted func (s *service) OnDelete(obj interface{}) { s.logger.Debugf("Watcher Service delete: %+v", obj) - service := obj.(*kubernetes.Service) + service, _ := obj.(*kubernetes.Service) time.AfterFunc(s.cleanupTimeout, func() { s.emitStopped(service) }) } func generateServiceData( service *kubernetes.Service, - cfg *Config, kubeMetaGen metadata.MetaGen, - namespaceAnnotations common.MapStr) *serviceData { + namespaceAnnotations mapstr.M) *serviceData { host := service.Spec.ClusterIP // If a service doesn't have an IP then dont monitor it @@ -188,15 +187,15 @@ func generateServiceData( // k8sMapping includes only the metadata that fall under kubernetes.* // and these are available as dynamic vars through the provider - k8sMapping := map[string]interface{}(kubemetaMap.(common.MapStr).Clone()) + k8sMapping := map[string]interface{}(kubemetaMap.(mapstr.M).Clone()) if len(namespaceAnnotations) != 0 { k8sMapping["namespace_annotations"] = namespaceAnnotations } // Pass annotations to all events so that it can be used in templating and by annotation builders. - annotations := common.MapStr{} + annotations := mapstr.M{} for k, v := range service.GetObjectMeta().GetAnnotations() { - safemapstr.Put(annotations, k, v) + _ = safemapstr.Put(annotations, k, v) } // add annotations to be discoverable by templates diff --git a/internal/pkg/composable/providers/kubernetes/service_test.go b/internal/pkg/composable/providers/kubernetes/service_test.go index c183541e6a7..47d420fb233 100644 --- a/internal/pkg/composable/providers/kubernetes/service_test.go +++ b/internal/pkg/composable/providers/kubernetes/service_test.go @@ -7,21 +7,18 @@ package kubernetes import ( "testing" - "github.com/elastic/beats/v7/libbeat/common/kubernetes/metadata" - - "github.com/elastic/beats/v7/libbeat/common" - "github.com/stretchr/testify/assert" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes/metadata" + "github.com/elastic/elastic-agent-libs/mapstr" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - - "github.com/elastic/beats/v7/libbeat/common/kubernetes" ) func TestGenerateServiceData(t *testing.T) { - uid := "005f3b90-4b9d-12f8-acf0-31020a840133" service := &kubernetes.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "testsvc", @@ -49,44 +46,43 @@ func TestGenerateServiceData(t *testing.T) { data := generateServiceData( service, - &Config{}, &svcMeta{}, - common.MapStr{ + mapstr.M{ "nsa": "nsb", }) mapping := map[string]interface{}{ - "service": common.MapStr{ + "service": mapstr.M{ "uid": string(service.GetUID()), "name": service.GetName(), "ip": service.Spec.ClusterIP, }, - "namespace_annotations": common.MapStr{ + "namespace_annotations": mapstr.M{ "nsa": "nsb", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "baz": "ban", }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, } processors := map[string]interface{}{ - "orchestrator": common.MapStr{ - "cluster": common.MapStr{ + "orchestrator": mapstr.M{ + "cluster": mapstr.M{ "name": "devcluster", "url": "8.8.8.8:9090"}, - }, "kubernetes": common.MapStr{ - "service": common.MapStr{ + }, "kubernetes": mapstr.M{ + "service": mapstr.M{ "uid": string(service.GetUID()), "name": service.GetName(), "ip": "1.2.3.4", }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "baz": "ban", }, }, @@ -95,8 +91,8 @@ func TestGenerateServiceData(t *testing.T) { assert.Equal(t, service, data.service) assert.Equal(t, mapping, data.mapping) for _, v := range data.processors { - k := v["add_fields"].(map[string]interface{}) - target := k["target"].(string) + k, _ := v["add_fields"].(map[string]interface{}) + target, _ := k["target"].(string) fields := k["fields"] assert.Equal(t, processors[target], fields) } @@ -112,9 +108,9 @@ type svcMeta struct{} // } // All Kubernetes fields that need to be stored under kubernetes. prefix are populated by // GenerateK8s method while fields that are part of ECS are generated by GenerateECS method -func (s *svcMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOptions) common.MapStr { +func (s *svcMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOptions) mapstr.M { ecsFields := s.GenerateECS(obj) - meta := common.MapStr{ + meta := mapstr.M{ "kubernetes": s.GenerateK8s(obj, opts...), } meta.DeepUpdate(ecsFields) @@ -122,10 +118,10 @@ func (s *svcMeta) Generate(obj kubernetes.Resource, opts ...metadata.FieldOption } // GenerateECS generates svc ECS metadata from a resource object -func (s *svcMeta) GenerateECS(obj kubernetes.Resource) common.MapStr { - return common.MapStr{ - "orchestrator": common.MapStr{ - "cluster": common.MapStr{ +func (s *svcMeta) GenerateECS(obj kubernetes.Resource) mapstr.M { + return mapstr.M{ + "orchestrator": mapstr.M{ + "cluster": mapstr.M{ "name": "devcluster", "url": "8.8.8.8:9090", }, @@ -134,24 +130,24 @@ func (s *svcMeta) GenerateECS(obj kubernetes.Resource) common.MapStr { } // GenerateK8s generates svc metadata from a resource object -func (s *svcMeta) GenerateK8s(obj kubernetes.Resource, opts ...metadata.FieldOptions) common.MapStr { - k8sNode := obj.(*kubernetes.Service) - return common.MapStr{ - "service": common.MapStr{ +func (s *svcMeta) GenerateK8s(obj kubernetes.Resource, opts ...metadata.FieldOptions) mapstr.M { + k8sNode, _ := obj.(*kubernetes.Service) + return mapstr.M{ + "service": mapstr.M{ "uid": string(k8sNode.GetUID()), "name": k8sNode.GetName(), "ip": "1.2.3.4", }, - "labels": common.MapStr{ + "labels": mapstr.M{ "foo": "bar", }, - "annotations": common.MapStr{ + "annotations": mapstr.M{ "baz": "ban", }, } } // GenerateFromName generates svc metadata from a node name -func (s *svcMeta) GenerateFromName(name string, opts ...metadata.FieldOptions) common.MapStr { +func (s *svcMeta) GenerateFromName(name string, opts ...metadata.FieldOptions) mapstr.M { return nil } diff --git a/internal/pkg/composable/providers/kubernetesleaderelection/config.go b/internal/pkg/composable/providers/kubernetesleaderelection/config.go index b6e9ad2ee64..d92d35566a2 100644 --- a/internal/pkg/composable/providers/kubernetesleaderelection/config.go +++ b/internal/pkg/composable/providers/kubernetesleaderelection/config.go @@ -4,7 +4,7 @@ package kubernetesleaderelection -import "github.com/elastic/beats/v7/libbeat/common/kubernetes" +import "github.com/elastic/elastic-agent-autodiscover/kubernetes" // Config for kubernetes_leaderelection provider type Config struct { diff --git a/internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go b/internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go index 769dad7fd42..410e13ec77d 100644 --- a/internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go +++ b/internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go @@ -13,7 +13,7 @@ import ( "k8s.io/client-go/tools/leaderelection" "k8s.io/client-go/tools/leaderelection/resourcelock" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" "github.com/elastic/elastic-agent/internal/pkg/agent/application/info" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/composable" @@ -23,7 +23,7 @@ import ( ) func init() { - composable.Providers.AddContextProvider("kubernetes_leaderelection", ContextProviderBuilder) + _ = composable.Providers.AddContextProvider("kubernetes_leaderelection", ContextProviderBuilder) } type contextProvider struct { @@ -76,7 +76,6 @@ func (p *contextProvider) Run(comm corecomp.ContextProviderComm) error { Name: p.config.LeaderLease, Namespace: ns, } - metaUID := lease.GetObjectMeta().GetUID() p.leaderElection = &leaderelection.LeaderElectionConfig{ Lock: &resourcelock.LeaseLock{ LeaseMeta: lease, @@ -92,11 +91,11 @@ func (p *contextProvider) Run(comm corecomp.ContextProviderComm) error { Callbacks: leaderelection.LeaderCallbacks{ OnStartedLeading: func(ctx context.Context) { p.logger.Debugf("leader election lock GAINED, id %v", id) - p.startLeading(string(metaUID)) + p.startLeading() }, OnStoppedLeading: func() { p.logger.Debugf("leader election lock LOST, id %v", id) - p.stopLeading(string(metaUID)) + p.stopLeading() }, }, } @@ -118,7 +117,7 @@ func (p *contextProvider) startLeaderElector(ctx context.Context) { go le.Run(ctx) } -func (p *contextProvider) startLeading(metaUID string) { +func (p *contextProvider) startLeading() { mapping := map[string]interface{}{ "leader": true, } @@ -129,7 +128,7 @@ func (p *contextProvider) startLeading(metaUID string) { } } -func (p *contextProvider) stopLeading(metaUID string) { +func (p *contextProvider) stopLeading() { mapping := map[string]interface{}{ "leader": false, } diff --git a/internal/pkg/composable/providers/kubernetessecrets/config.go b/internal/pkg/composable/providers/kubernetessecrets/config.go index ac14af2ea45..95ff308c3aa 100644 --- a/internal/pkg/composable/providers/kubernetessecrets/config.go +++ b/internal/pkg/composable/providers/kubernetessecrets/config.go @@ -4,7 +4,7 @@ package kubernetessecrets -import "github.com/elastic/beats/v7/libbeat/common/kubernetes" +import "github.com/elastic/elastic-agent-autodiscover/kubernetes" // Config for kubernetes provider type Config struct { diff --git a/internal/pkg/composable/providers/kubernetessecrets/kubernetes_secrets.go b/internal/pkg/composable/providers/kubernetessecrets/kubernetes_secrets.go index e6e5de8e6d1..0bc560295ed 100644 --- a/internal/pkg/composable/providers/kubernetessecrets/kubernetes_secrets.go +++ b/internal/pkg/composable/providers/kubernetessecrets/kubernetes_secrets.go @@ -11,7 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8sclient "k8s.io/client-go/kubernetes" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" "github.com/elastic/elastic-agent/internal/pkg/composable" "github.com/elastic/elastic-agent/internal/pkg/config" @@ -23,7 +23,7 @@ var _ corecomp.FetchContextProvider = (*contextProviderK8sSecrets)(nil) var getK8sClientFunc = getK8sClient func init() { - composable.Providers.AddContextProvider("kubernetes_secrets", ContextProviderBuilder) + _ = composable.Providers.AddContextProvider("kubernetes_secrets", ContextProviderBuilder) } type contextProviderK8sSecrets struct { diff --git a/internal/pkg/composable/providers/kubernetessecrets/kubernetes_secrets_test.go b/internal/pkg/composable/providers/kubernetessecrets/kubernetes_secrets_test.go index bff1677f814..4c80800a59b 100644 --- a/internal/pkg/composable/providers/kubernetessecrets/kubernetes_secrets_test.go +++ b/internal/pkg/composable/providers/kubernetessecrets/kubernetes_secrets_test.go @@ -8,8 +8,6 @@ import ( "context" "testing" - "github.com/elastic/beats/v7/libbeat/common/kubernetes" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -18,15 +16,19 @@ import ( k8sclient "k8s.io/client-go/kubernetes" k8sfake "k8s.io/client-go/kubernetes/fake" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-autodiscover/kubernetes" + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/config" corecomp "github.com/elastic/elastic-agent/internal/pkg/core/composable" ) +const ( + ns = "test_namespace" + pass = "testing_passpass" +) + func Test_K8sSecretsProvider_Fetch(t *testing.T) { client := k8sfake.NewSimpleClientset() - ns := "test_namespace" - pass := "testing_passpass" secret := &v1.Secret{ TypeMeta: metav1.TypeMeta{ Kind: "Secret", @@ -50,13 +52,13 @@ func Test_K8sSecretsProvider_Fetch(t *testing.T) { p, err := ContextProviderBuilder(logger, cfg) require.NoError(t, err) - fp := p.(corecomp.FetchContextProvider) + fp, _ := p.(corecomp.FetchContextProvider) getK8sClientFunc = func(kubeconfig string, opt kubernetes.KubeClientOptions) (k8sclient.Interface, error) { return client, nil } require.NoError(t, err) - fp.Run(nil) + _ = fp.Run(nil) val, found := fp.Fetch("kubernetes_secrets.test_namespace.testing_secret.secret_value") assert.True(t, found) assert.Equal(t, val, pass) @@ -64,8 +66,6 @@ func Test_K8sSecretsProvider_Fetch(t *testing.T) { func Test_K8sSecretsProvider_FetchWrongSecret(t *testing.T) { client := k8sfake.NewSimpleClientset() - ns := "test_namespace" - pass := "testing_passpass" secret := &v1.Secret{ TypeMeta: metav1.TypeMeta{ Kind: "Secret", @@ -89,13 +89,13 @@ func Test_K8sSecretsProvider_FetchWrongSecret(t *testing.T) { p, err := ContextProviderBuilder(logger, cfg) require.NoError(t, err) - fp := p.(corecomp.FetchContextProvider) + fp, _ := p.(corecomp.FetchContextProvider) getK8sClientFunc = func(kubeconfig string, opt kubernetes.KubeClientOptions) (k8sclient.Interface, error) { return client, nil } require.NoError(t, err) - fp.Run(nil) + _ = fp.Run(nil) val, found := fp.Fetch("kubernetes_secrets.test_namespace.testing_secretHACK.secret_value") assert.False(t, found) assert.EqualValues(t, val, "") diff --git a/internal/pkg/composable/registry.go b/internal/pkg/composable/registry.go index fa1acf59b4c..cc4b3f82b61 100644 --- a/internal/pkg/composable/registry.go +++ b/internal/pkg/composable/registry.go @@ -7,7 +7,7 @@ package composable import ( "sync" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-libs/logp" ) // providerRegistry is a registry of providers diff --git a/internal/pkg/config/operations/inspector.go b/internal/pkg/config/operations/inspector.go index 2ee9592ae92..e7a7f9e63ce 100644 --- a/internal/pkg/config/operations/inspector.go +++ b/internal/pkg/config/operations/inspector.go @@ -7,7 +7,7 @@ package operations import ( "fmt" - "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/application/info" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" "github.com/elastic/elastic-agent/internal/pkg/agent/configuration" @@ -41,7 +41,7 @@ func LoadFullAgentConfig(cfgPath string, failOnFleetMissing bool) (*config.Confi return rawConfig, nil } - fleetConfig, err := loadFleetConfig(rawConfig) + fleetConfig, err := loadFleetConfig() if err != nil { return nil, err } else if fleetConfig == nil { @@ -81,7 +81,7 @@ func loadConfig(configPath string) (*config.Config, error) { } // merge local configuration and configuration persisted from fleet. - rawConfig.Merge(config) + _ = rawConfig.Merge(config) if err := info.InjectAgentConfig(rawConfig); err != nil { return nil, err @@ -90,7 +90,7 @@ func loadConfig(configPath string) (*config.Config, error) { return rawConfig, nil } -func loadFleetConfig(cfg *config.Config) (map[string]interface{}, error) { +func loadFleetConfig() (map[string]interface{}, error) { log, err := newErrorLogger() if err != nil { return nil, err diff --git a/internal/pkg/core/monitoring/server/server.go b/internal/pkg/core/monitoring/server/server.go index 71382ac556a..e5929909158 100644 --- a/internal/pkg/core/monitoring/server/server.go +++ b/internal/pkg/core/monitoring/server/server.go @@ -16,11 +16,10 @@ import ( "go.elastic.co/apm" "go.elastic.co/apm/module/apmgorilla" - "github.com/elastic/beats/v7/libbeat/api" - "github.com/elastic/beats/v7/libbeat/beat" - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/monitoring" - "github.com/elastic/beats/v7/libbeat/monitoring/report/buffer" + "github.com/elastic/elastic-agent-libs/api" + "github.com/elastic/elastic-agent-libs/config" + "github.com/elastic/elastic-agent-libs/monitoring" + "github.com/elastic/elastic-agent-libs/monitoring/report/buffer" "github.com/elastic/elastic-agent/internal/pkg/sorted" "github.com/elastic/elastic-agent/pkg/core/logger" ) @@ -40,7 +39,7 @@ func New( log.Errorf("failed to create monitoring drop: %v", err) } - cfg, err := common.NewConfigFrom(endpointConfig) + cfg, err := config.NewConfigFrom(endpointConfig) if err != nil { return nil, err } @@ -50,7 +49,7 @@ func New( func exposeMetricsEndpoint( log *logger.Logger, - config *common.Config, + config *config.C, ns func(string) *monitoring.Namespace, routesFetchFn func() *sorted.Set, enableProcessStats bool, @@ -72,7 +71,7 @@ func exposeMetricsEndpoint( } if enableBuffer { - bufferReporter, err := buffer.MakeReporter(beat.Info{}, config) // beat.Info is not used by buffer reporter + bufferReporter, err := buffer.MakeReporter(config) // beat.Info is not used by buffer reporter if err != nil { return nil, fmt.Errorf("unable to create buffer reporter for elastic-agent: %w", err) } diff --git a/internal/pkg/core/monitoring/server/stats.go b/internal/pkg/core/monitoring/server/stats.go index 5bb84246e9f..366da268aad 100644 --- a/internal/pkg/core/monitoring/server/stats.go +++ b/internal/pkg/core/monitoring/server/stats.go @@ -9,7 +9,7 @@ import ( "fmt" "net/http" - "github.com/elastic/beats/v7/libbeat/monitoring" + "github.com/elastic/elastic-agent-libs/monitoring" ) func statsHandler(ns *monitoring.Namespace) func(http.ResponseWriter, *http.Request) error { diff --git a/internal/pkg/remote/client.go b/internal/pkg/remote/client.go index 29e6a5611a8..085ab2bfe0e 100644 --- a/internal/pkg/remote/client.go +++ b/internal/pkg/remote/client.go @@ -9,28 +9,23 @@ import ( "io" "net/http" "net/url" - "regexp" "strings" "sync" "time" "github.com/pkg/errors" - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" + urlutil "github.com/elastic/elastic-agent-libs/kibana" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent/internal/pkg/config" "github.com/elastic/elastic-agent/internal/pkg/id" "github.com/elastic/elastic-agent/pkg/core/logger" ) const ( - defaultPort = 8220 - retryOnBadConnTimeout = 5 * time.Minute ) -var hasScheme = regexp.MustCompile(`^([a-z][a-z0-9+\-.]*)://`) - type requestFunc func(string, string, url.Values, io.Reader) (*http.Request, error) type wrapperFunc func(rt http.RoundTripper) (http.RoundTripper, error) @@ -104,7 +99,7 @@ func NewWithConfig(log *logger.Logger, cfg Config, wrapper wrapperFunc) (*Client hosts := cfg.GetHosts() clients := make([]*requestClient, len(hosts)) for i, host := range cfg.GetHosts() { - connStr, err := common.MakeURL(string(cfg.Protocol), p, host, 0) + connStr, err := urlutil.MakeURL(string(cfg.Protocol), p, host, 0) if err != nil { return nil, errors.Wrap(err, "invalid fleet-server endpoint") } @@ -173,7 +168,7 @@ func (c *Client) Send( // Content-Type / Accepted type can be override from the called. req.Header.Set("Content-Type", "application/json") req.Header.Add("Accept", "application/json") - // TODO: Make this header specific to fleet-server or remove it + // This header should be specific to fleet-server or remove it req.Header.Set("kbn-xsrf", "1") // Without this Kibana will refuse to answer the request. // If available, add the request id as an HTTP header @@ -268,6 +263,6 @@ func prefixRequestFactory(URL string) requestFunc { return func(method, path string, params url.Values, body io.Reader) (*http.Request, error) { path = strings.TrimPrefix(path, "/") newPath := strings.Join([]string{URL, path, "?", params.Encode()}, "") - return http.NewRequest(method, newPath, body) + return http.NewRequest(method, newPath, body) //nolint:noctx // keep old behaviour } } diff --git a/internal/pkg/remote/config.go b/internal/pkg/remote/config.go index 495f850f5bc..c0846899611 100644 --- a/internal/pkg/remote/config.go +++ b/internal/pkg/remote/config.go @@ -8,7 +8,7 @@ import ( "fmt" "time" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" ) // Config is the configuration for the client. diff --git a/internal/pkg/remote/config_test.go b/internal/pkg/remote/config_test.go index 5a71cb9b6cd..cbe9a39df5b 100644 --- a/internal/pkg/remote/config_test.go +++ b/internal/pkg/remote/config_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" ) func TestPackUnpack(t *testing.T) { diff --git a/pkg/core/logger/logger.go b/pkg/core/logger/logger.go index 6ef25cd9d48..4f941266cca 100644 --- a/pkg/core/logger/logger.go +++ b/pkg/core/logger/logger.go @@ -14,10 +14,10 @@ import ( "go.uber.org/zap/zapcore" "gopkg.in/yaml.v2" - "github.com/elastic/beats/v7/libbeat/common" - "github.com/elastic/beats/v7/libbeat/logp" - "github.com/elastic/beats/v7/libbeat/logp/configure" + "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/file" + "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/logp/configure" "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" "github.com/elastic/elastic-agent/internal/pkg/agent/errors" ) @@ -50,7 +50,7 @@ func NewWithLogpLevel(name string, level logp.Level, logInternal bool) (*Logger, } // NewFromConfig takes the user configuration and generate the right logger. -// TODO: Finish implementation, need support on the library that we use. +// We should finish implementation, need support on the library that we use. func NewFromConfig(name string, cfg *Config, logInternal bool) (*Logger, error) { return new(name, cfg, logInternal) } @@ -77,7 +77,7 @@ func new(name string, cfg *Config, logInternal bool) (*Logger, error) { return logp.NewLogger(name), nil } -func toCommonConfig(cfg *Config) (*common.Config, error) { +func toCommonConfig(cfg *Config) (*config.C, error) { // work around custom types and common config // when custom type is transformed to common.Config // value is determined based on reflect value which is incorrect @@ -87,7 +87,7 @@ func toCommonConfig(cfg *Config) (*common.Config, error) { return nil, err } - commonLogp, err := common.NewConfigFrom(string(yamlCfg)) + commonLogp, err := config.NewConfigFrom(string(yamlCfg)) if err != nil { return nil, errors.New(err, errors.TypeConfig) } diff --git a/pkg/core/server/server_test.go b/pkg/core/server/server_test.go index ee4e8fda9ca..a2a1bdf4f80 100644 --- a/pkg/core/server/server_test.go +++ b/pkg/core/server/server_test.go @@ -2,6 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. +//nolint:dupl // tests are equivalent package server import ( @@ -17,19 +18,22 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/elastic/beats/v7/libbeat/logp" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/elastic/elastic-agent-client/v7/pkg/client" "github.com/elastic/elastic-agent-client/v7/pkg/proto" + "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/pkg/core/logger" ) +const ( + initConfig = "initial_config" + newConfig = "new_config" +) + func TestServer_Register(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -40,7 +44,6 @@ func TestServer_Register(t *testing.T) { } func TestServer_Get(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -54,7 +57,6 @@ func TestServer_Get(t *testing.T) { } func TestServer_InitialCheckIn(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -74,7 +76,8 @@ func TestServer_InitialCheckIn(t *testing.T) { })) // set status as healthy and running - c.Status(proto.StateObserved_HEALTHY, "Running", nil) + err = c.Status(proto.StateObserved_HEALTHY, "Running", nil) + require.NoError(t, err) // application state should be updated assert.NoError(t, waitFor(func() error { @@ -120,8 +123,10 @@ func TestServer_MultiClients(t *testing.T) { })) // set status differently - c1.Status(proto.StateObserved_HEALTHY, "Running", nil) - c2.Status(proto.StateObserved_DEGRADED, "No upstream connection", nil) + err = c1.Status(proto.StateObserved_HEALTHY, "Running", nil) + require.NoError(t, err) + err = c2.Status(proto.StateObserved_DEGRADED, "No upstream connection", nil) + require.NoError(t, err) // application states should be updated assert.NoError(t, waitFor(func() error { @@ -139,7 +144,6 @@ func TestServer_MultiClients(t *testing.T) { } func TestServer_PreventCheckinStream(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -167,7 +171,6 @@ func TestServer_PreventCheckinStream(t *testing.T) { } func TestServer_PreventActionsStream(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -195,7 +198,6 @@ func TestServer_PreventActionsStream(t *testing.T) { } func TestServer_DestroyPreventConnectAtTLS(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -226,7 +228,6 @@ func TestServer_DestroyPreventConnectAtTLS(t *testing.T) { } func TestServer_UpdateConfig(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -244,7 +245,8 @@ func TestServer_UpdateConfig(t *testing.T) { } return nil })) - c.Status(proto.StateObserved_HEALTHY, "Running", nil) + err = c.Status(proto.StateObserved_HEALTHY, "Running", nil) + require.NoError(t, err) assert.NoError(t, waitFor(func() error { if app.Status() != proto.StateObserved_HEALTHY { return fmt.Errorf("server never updated currect application state") @@ -258,7 +260,6 @@ func TestServer_UpdateConfig(t *testing.T) { assert.Equal(t, preIdx, as.expectedConfigIdx) // push new config; should update the client - newConfig := "new_config" require.NoError(t, as.UpdateConfig(newConfig)) assert.Equal(t, preIdx+1, as.expectedConfigIdx) assert.NoError(t, waitFor(func() error { @@ -270,7 +271,6 @@ func TestServer_UpdateConfig(t *testing.T) { } func TestServer_UpdateConfigDisconnected(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -288,7 +288,8 @@ func TestServer_UpdateConfigDisconnected(t *testing.T) { } return nil })) - c.Status(proto.StateObserved_HEALTHY, "Running", nil) + err = c.Status(proto.StateObserved_HEALTHY, "Running", nil) + require.NoError(t, err) assert.NoError(t, waitFor(func() error { if app.Status() != proto.StateObserved_HEALTHY { return fmt.Errorf("server never updated currect application state") @@ -298,7 +299,6 @@ func TestServer_UpdateConfigDisconnected(t *testing.T) { // stop the client, then update the config c.Stop() - newConfig := "new_config" require.NoError(t, as.UpdateConfig(newConfig)) // reconnect, client should get latest config @@ -312,7 +312,6 @@ func TestServer_UpdateConfigDisconnected(t *testing.T) { } func TestServer_UpdateConfigStopping(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -330,7 +329,8 @@ func TestServer_UpdateConfigStopping(t *testing.T) { } return nil })) - c.Status(proto.StateObserved_HEALTHY, "Running", nil) + err = c.Status(proto.StateObserved_HEALTHY, "Running", nil) + require.NoError(t, err) assert.NoError(t, waitFor(func() error { if app.Status() != proto.StateObserved_HEALTHY { return fmt.Errorf("server never updated currect application state") @@ -344,13 +344,12 @@ func TestServer_UpdateConfigStopping(t *testing.T) { _ = as.Stop(500 * time.Millisecond) close(done) }() - err = as.UpdateConfig("new_config") + err = as.UpdateConfig(newConfig) assert.Error(t, ErrApplicationStopping, err) <-done } func TestServer_Stop(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -368,7 +367,8 @@ func TestServer_Stop(t *testing.T) { } return nil })) - c.Status(proto.StateObserved_HEALTHY, "Running", nil) + err = c.Status(proto.StateObserved_HEALTHY, "Running", nil) + require.NoError(t, err) assert.NoError(t, waitFor(func() error { if app.Status() != proto.StateObserved_HEALTHY { return fmt.Errorf("server never updated currect application state") @@ -396,14 +396,16 @@ func TestServer_Stop(t *testing.T) { } return nil })) - c.Status(proto.StateObserved_CONFIGURING, "Configuring", nil) + err = c.Status(proto.StateObserved_CONFIGURING, "Configuring", nil) + require.NoError(t, err) require.NoError(t, waitFor(func() error { if cImpl.Stop() < 1 { return fmt.Errorf("client never got expected stop again") } return nil })) - c.Status(proto.StateObserved_STOPPING, "Stopping", nil) + err = c.Status(proto.StateObserved_STOPPING, "Stopping", nil) + require.NoError(t, err) require.NoError(t, waitFor(func() error { if app.Status() != proto.StateObserved_STOPPING { return fmt.Errorf("server never updated to stopping") @@ -418,7 +420,6 @@ func TestServer_Stop(t *testing.T) { } func TestServer_StopJustDisconnect(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -436,7 +437,8 @@ func TestServer_StopJustDisconnect(t *testing.T) { } return nil })) - c.Status(proto.StateObserved_HEALTHY, "Running", nil) + err = c.Status(proto.StateObserved_HEALTHY, "Running", nil) + require.NoError(t, err) assert.NoError(t, waitFor(func() error { if app.Status() != proto.StateObserved_HEALTHY { return fmt.Errorf("server never updated currect application state") @@ -469,7 +471,6 @@ func TestServer_StopJustDisconnect(t *testing.T) { } func TestServer_StopTimeout(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}) defer srv.Stop() @@ -487,7 +488,8 @@ func TestServer_StopTimeout(t *testing.T) { } return nil })) - c.Status(proto.StateObserved_HEALTHY, "Running", nil) + err = c.Status(proto.StateObserved_HEALTHY, "Running", nil) + require.NoError(t, err) assert.NoError(t, waitFor(func() error { if app.Status() != proto.StateObserved_HEALTHY { return fmt.Errorf("server never updated currect application state") @@ -511,7 +513,6 @@ func TestServer_StopTimeout(t *testing.T) { } func TestServer_WatchdogFailApp(t *testing.T) { - initConfig := "initial_config" checkMinTimeout := 300 * time.Millisecond app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}, func(s *Server) { @@ -538,7 +539,6 @@ func TestServer_WatchdogFailApp(t *testing.T) { } func TestServer_PerformAction(t *testing.T) { - initConfig := "initial_config" app := &StubApp{} srv := createAndStartServer(t, &StubHandler{}, func(s *Server) { s.watchdogCheckInterval = 50 * time.Millisecond @@ -685,7 +685,7 @@ func (a *StubApp) Message() string { type StubHandler struct{} func (h *StubHandler) OnStatusChange(as *ApplicationState, status proto.StateObserved_Status, message string, payload map[string]interface{}) { - stub := as.app.(*StubApp) + stub, _ := as.app.(*StubApp) stub.lock.Lock() defer stub.lock.Unlock() stub.status = status