-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLOUDGA-19629] Add support for telemetry provider
- Loading branch information
aquatiko
committed
Mar 14, 2024
1 parent
33701b5
commit ec91f0c
Showing
12 changed files
with
988 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
// Licensed to Yugabyte, Inc. under one or more contributor license | ||
// agreements. See the NOTICE file distributed with this work for | ||
// additional information regarding copyright ownership. Yugabyte | ||
// licenses this file to you under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package cmd_test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gbytes" | ||
"github.com/onsi/gomega/gexec" | ||
"github.com/onsi/gomega/ghttp" | ||
openapi "github.com/yugabyte/yugabytedb-managed-go-client-internal" | ||
) | ||
|
||
var _ = Describe("Telemetry Provider", func() { | ||
|
||
var ( | ||
server *ghttp.Server | ||
statusCode int | ||
args []string | ||
responseAccount openapi.AccountListResponse | ||
responseProject openapi.AccountListResponse | ||
responseTelemetryProvider openapi.TelemetryProviderResponse | ||
responseTelemetryProviderList openapi.TelemetryProviderListResponse | ||
) | ||
|
||
BeforeEach(func() { | ||
args = os.Args | ||
os.Args = []string{} | ||
var err error | ||
server, err = newGhttpServer(responseAccount, responseProject) | ||
Expect(err).ToNot(HaveOccurred()) | ||
os.Setenv("YBM_HOST", fmt.Sprintf("http://%s", server.Addr())) | ||
os.Setenv("YBM_APIKEY", "test-token") | ||
}) | ||
|
||
Context("When type is Datadog", func() { | ||
It("should create the config", func() { | ||
statusCode = 200 | ||
err := loadJson("./test/fixtures/metrics-exporter-dd.json", &responseTelemetryProvider) | ||
Expect(err).ToNot(HaveOccurred()) | ||
server.AppendHandlers( | ||
ghttp.CombineHandlers( | ||
ghttp.VerifyRequest(http.MethodPost, "/api/public/v1/accounts/340af43a-8a7c-4659-9258-4876fd6a207b/projects/78d4459c-0f45-47a5-899a-45ddf43eba6e/telemetry-providers"), | ||
ghttp.RespondWithJSONEncodedPtr(&statusCode, responseTelemetryProvider), | ||
), | ||
) | ||
cmd := exec.Command(compiledCLIPath, "telemetry-provider", "create", "--config-name", "test", "--type", "datadog", "--datadog-spec", "site=test,api-key=c4XXXXXXXXXXXXXXXXXXXXXXXXXXXX3d") | ||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
session.Wait(2) | ||
Expect(session.Out).Should(gbytes.Say(`The telemetry provider 9e3fabbc-849c-4a77-bdb2-9422e712e7dc is being created | ||
ID Name Type Site ApiKey | ||
9e3fabbc-849c-4a77-bdb2-9422e712e7dc ff DATADOG test c4XXXXXXXXXXXXXXXXXXXXXXXXXXXX3d`)) | ||
session.Kill() | ||
}) | ||
It("should return required field name and type when not set", func() { | ||
|
||
cmd := exec.Command(compiledCLIPath, "telemetry-provider", "create") | ||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
session.Wait(2) | ||
Expect(session.Err).Should(gbytes.Say("(?m:Error: required flag\\(s\\) \"config-name\", \"type\" not set$)")) | ||
session.Kill() | ||
}) | ||
It("should return required field", func() { | ||
cmd := exec.Command(compiledCLIPath, "telemetry-provider", "create", "--config-name", "test", "--type", "datadog", "--datadog-spec", "site=test") | ||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
session.Wait(2) | ||
Expect(session.Err).Should(gbytes.Say("(?m:api-key is a required field for datadog-spec$)")) | ||
session.Kill() | ||
}) | ||
|
||
}) | ||
Context("When type is Grafana", func() { | ||
It("should create the config", func() { | ||
statusCode = 200 | ||
err := loadJson("./test/fixtures/metrics-exporter-grafana.json", &responseTelemetryProvider) | ||
Expect(err).ToNot(HaveOccurred()) | ||
server.AppendHandlers( | ||
ghttp.CombineHandlers( | ||
ghttp.VerifyRequest(http.MethodPost, "/api/public/v1/accounts/340af43a-8a7c-4659-9258-4876fd6a207b/projects/78d4459c-0f45-47a5-899a-45ddf43eba6e/telemetry-providers"), | ||
ghttp.RespondWithJSONEncodedPtr(&statusCode, responseTelemetryProvider), | ||
), | ||
) | ||
cmd := exec.Command(compiledCLIPath, "telemetry-provider", "create", "--config-name", "test", "--type", "grafana", "--grafana-spec", "org-slug=ybmclitest,instance-id=1234456,zone=test-endpoint,access-policy-token=glXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==") | ||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
session.Wait(2) | ||
Expect(session.Out).Should(gbytes.Say(`The telemetry provider 92ceaa26-bac7-4842-9b3c-831a18a4f813 is being created | ||
ID Name Type Zone Access Token Policy InstanceId OrgSlug | ||
92ceaa26-bac7-4842-9b3c-831a18a4f813 grafana GRAFANA test-zone glXXXXXXXXXX...XXXXXXXXXXXXXXX== 1234456 ybmclitest`)) | ||
session.Kill() | ||
}) | ||
It("should return required field", func() { | ||
cmd := exec.Command(compiledCLIPath, "telemetry-provider", "create", "--config-name", "test", "--type", "grafana", "--grafana-spec", "zone=test") | ||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
session.Wait(2) | ||
Expect(session.Err).Should(gbytes.Say("(?m:access-policy-token is a required field for grafana-spec$)")) | ||
session.Kill() | ||
}) | ||
|
||
}) | ||
Context("When type is sumologic", func() { | ||
It("should create the config", func() { | ||
statusCode = 200 | ||
err := loadJson("./test/fixtures/metrics-exporter-sumologic.json", &responseTelemetryProvider) | ||
Expect(err).ToNot(HaveOccurred()) | ||
server.AppendHandlers( | ||
ghttp.CombineHandlers( | ||
ghttp.VerifyRequest(http.MethodPost, "/api/public/v1/accounts/340af43a-8a7c-4659-9258-4876fd6a207b/projects/78d4459c-0f45-47a5-899a-45ddf43eba6e/telemetry-providers"), | ||
ghttp.RespondWithJSONEncodedPtr(&statusCode, responseTelemetryProvider), | ||
), | ||
) | ||
cmd := exec.Command(compiledCLIPath, "telemetry-provider", "create", "--config-name", "testsumo", "--type", "sumologic", "--sumologic-spec", "access-id=ybmclitest,access-key=1234456,installation-token=test-endpoint") | ||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
session.Wait(2) | ||
Expect(session.Out).Should(gbytes.Say(`ID Name Type Access Key Access ID InstallationToken | ||
4021aa44-b22d-4bb6-a7d3-0a1099a4f206 gwenn-sumo SUMOLOGIC FqXXXXXXXXXX...XXXXXXXXXXXXXXX9p suXXXXXXXXXXJ9 U1XXXXXXXXXX...XXXXXXXXXXXXXXX==`)) | ||
session.Kill() | ||
}) | ||
It("should return required field", func() { | ||
cmd := exec.Command(compiledCLIPath, "telemetry-provider", "create", "--config-name", "testsumo", "--type", "sumologic", "--sumologic-spec", "access-id=test") | ||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
session.Wait(2) | ||
Expect(session.Err).Should(gbytes.Say("(?m:access-key is a required field for sumologic-spec$)")) | ||
session.Kill() | ||
}) | ||
|
||
}) | ||
|
||
Context("When listing telememtry providers", func() { | ||
It("should return the list of config", func() { | ||
statusCode = 200 | ||
err := loadJson("./test/fixtures/list-metrics-exporter.json", &responseTelemetryProviderList) | ||
Expect(err).ToNot(HaveOccurred()) | ||
server.AppendHandlers( | ||
ghttp.CombineHandlers( | ||
ghttp.VerifyRequest(http.MethodGet, "/api/public/v1/accounts/340af43a-8a7c-4659-9258-4876fd6a207b/projects/78d4459c-0f45-47a5-899a-45ddf43eba6e/telemetry-providers"), | ||
ghttp.RespondWithJSONEncodedPtr(&statusCode, responseTelemetryProviderList), | ||
), | ||
) | ||
cmd := exec.Command(compiledCLIPath, "telemetry-provider", "list") | ||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
session.Wait(2) | ||
Expect(session.Out).Should(gbytes.Say(`ID Name Type | ||
129f7c97-81ae-47c7-8f9e-40ab4390093f ff DATADOG | ||
92ceaa26-bac7-4842-9b3c-831a18a4f813 grafana GRAFANA | ||
4021aa44-b22d-4bb6-a7d3-0a1099a4f206 gwenn-sumo SUMOLOGIC`)) | ||
session.Kill() | ||
}) | ||
|
||
}) | ||
|
||
AfterEach(func() { | ||
os.Args = args | ||
server.Close() | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## ybm telemetry-provider | ||
|
||
Manage Telemetry Provider | ||
|
||
### Synopsis | ||
|
||
Manage Telemetry Provider | ||
|
||
``` | ||
ybm telemetry-provider [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for telemetry-provider | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --apiKey string YBM Api Key | ||
--config string config file (default is $HOME/.ybm-cli.yaml) | ||
--debug Use debug mode, same as --logLevel debug | ||
-l, --logLevel string Select the desired log level format(info). Default to info | ||
--no-color Disable colors in output , default to false | ||
-o, --output string Select the desired output format (table, json, pretty). Default to table | ||
--timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s) | ||
--wait Wait until the task is completed, otherwise it will exit immediately, default to false | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [ybm](ybm.md) - ybm - Effortlessly manage your DB infrastructure on YugabyteDB Managed (DBaaS) from command line! | ||
* [ybm telemetry-provider create](ybm_telemetry-provider_create.md) - Create Telemetry Provider | ||
* [ybm telemetry-provider delete](ybm_telemetry-provider_delete.md) - Delete Telemetry Provider | ||
* [ybm telemetry-provider list](ybm_telemetry-provider_list.md) - List Telemetry Provider | ||
* [ybm telemetry-provider update](ybm_telemetry-provider_update.md) - Update Telemetry Provider | ||
* [ybm telemetry-provider validate](ybm_telemetry-provider_validate.md) - Validate Telemetry Provider | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
## ybm telemetry-provider create | ||
|
||
Create Telemetry Provider | ||
|
||
### Synopsis | ||
|
||
Create Telemetry Provider | ||
|
||
``` | ||
ybm telemetry-provider create [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--config-name string [REQUIRED] The name of the telemetry provider | ||
--type string [REQUIRED] The type of third party telemetry provider sink | ||
--datadog-spec stringToString Configuration for Datadog. | ||
Please provide key value pairs as follows: | ||
api-key=<your-datadog-api-key>,site=<your-datadog-site-parameters> (default []) | ||
--grafana-spec stringToString Configuration for Grafana. | ||
Please provide key value pairs as follows: | ||
access-policy-token=<your-grafana-token>,zone=<your-grafana-zone-parameter>,instance-id=<your-grafana-instance-id>,org-slug=<your-grafana-org-slug> (default []) | ||
--sumologic-spec stringToString Configuration for sumologic. | ||
Please provide key value pairs as follows: | ||
access-key=<your-sumologic-access-key>,access-id=<your-sumologic-access-id>,installation-token=<your-sumologic-installation-token> (default []) | ||
-h, --help help for create | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --apiKey string YBM Api Key | ||
--config string config file (default is $HOME/.ybm-cli.yaml) | ||
--debug Use debug mode, same as --logLevel debug | ||
-l, --logLevel string Select the desired log level format(info). Default to info | ||
--no-color Disable colors in output , default to false | ||
-o, --output string Select the desired output format (table, json, pretty). Default to table | ||
--timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s) | ||
--wait Wait until the task is completed, otherwise it will exit immediately, default to false | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [ybm telemetry-provider](ybm_telemetry-provider.md) - Manage Telemetry Provider | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## ybm telemetry-provider delete | ||
|
||
Delete Telemetry Provider | ||
|
||
### Synopsis | ||
|
||
Delete Telemetry Provider | ||
|
||
``` | ||
ybm telemetry-provider delete [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--config-name string [REQUIRED] The name of the telemetry provider | ||
-f, --force Bypass the prompt for non-interactive usage | ||
-h, --help help for delete | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --apiKey string YBM Api Key | ||
--config string config file (default is $HOME/.ybm-cli.yaml) | ||
--debug Use debug mode, same as --logLevel debug | ||
-l, --logLevel string Select the desired log level format(info). Default to info | ||
--no-color Disable colors in output , default to false | ||
-o, --output string Select the desired output format (table, json, pretty). Default to table | ||
--timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s) | ||
--wait Wait until the task is completed, otherwise it will exit immediately, default to false | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [ybm telemetry-provider](ybm_telemetry-provider.md) - Manage Telemetry Provider | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## ybm telemetry-provider list | ||
|
||
List Telemetry Provider | ||
|
||
### Synopsis | ||
|
||
List Telemetry Provider | ||
|
||
``` | ||
ybm telemetry-provider list [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for list | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --apiKey string YBM Api Key | ||
--config string config file (default is $HOME/.ybm-cli.yaml) | ||
--debug Use debug mode, same as --logLevel debug | ||
-l, --logLevel string Select the desired log level format(info). Default to info | ||
--no-color Disable colors in output , default to false | ||
-o, --output string Select the desired output format (table, json, pretty). Default to table | ||
--timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s) | ||
--wait Wait until the task is completed, otherwise it will exit immediately, default to false | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [ybm telemetry-provider](ybm_telemetry-provider.md) - Manage Telemetry Provider | ||
|
Oops, something went wrong.