Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLOUDGA-19629] Add support for telemetry provider #222

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions cmd/db_audit_logs_exporter/db_audit_logs_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ var assignDbAuditLogsExporterCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {

clusterId, _ := cmd.Flags().GetString("cluster-id")
telemetryProviderId, _ := cmd.Flags().GetString("telemetry-provider-id")
integrationId, _ := cmd.Flags().GetString("integration-id")
ysqlConfig, _ := cmd.Flags().GetStringToString("ysql-config")
statement_classes, _ := cmd.Flags().GetString("statement_classes")

dbAuditLogsExporterSpec, err := setDbAuditLogsExporterSpec(ysqlConfig, statement_classes, telemetryProviderId)
dbAuditLogsExporterSpec, err := setDbAuditLogsExporterSpec(ysqlConfig, statement_classes, integrationId)

if err != nil {
logrus.Fatalf(err.Error())
Expand All @@ -70,9 +70,9 @@ var assignDbAuditLogsExporterCmd = &cobra.Command{
logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err))
}

dbAuditTelemetryProviderId := resp.GetData().Info.Id
dbAuditIntegrationId := resp.GetData().Info.Id

msg := fmt.Sprintf("The db audit exporter config %s is being created", formatter.Colorize(dbAuditTelemetryProviderId, formatter.GREEN_COLOR))
msg := fmt.Sprintf("The db audit exporter config %s is being created", formatter.Colorize(dbAuditIntegrationId, formatter.GREEN_COLOR))

fmt.Println(msg)

Expand All @@ -93,11 +93,11 @@ var updateDbAuditLogsExporterCmd = &cobra.Command{

clusterId, _ := cmd.Flags().GetString("cluster-id")
exportConfigId, _ := cmd.Flags().GetString("export-config-id")
telemetryProviderId, _ := cmd.Flags().GetString("telemetry-provider-id")
integrationId, _ := cmd.Flags().GetString("integration-id")
ysqlConfig, _ := cmd.Flags().GetStringToString("ysql-config")
statement_classes, _ := cmd.Flags().GetString("statement_classes")

dbAuditLogsExporterSpec, err := setDbAuditLogsExporterSpec(ysqlConfig, statement_classes, telemetryProviderId)
dbAuditLogsExporterSpec, err := setDbAuditLogsExporterSpec(ysqlConfig, statement_classes, integrationId)

if err != nil {
logrus.Fatalf(err.Error())
Expand All @@ -109,16 +109,16 @@ var updateDbAuditLogsExporterCmd = &cobra.Command{
}
authApi.GetInfo("", "")

resp, r, err := authApi.UpdateDbAuditLogsExporterConfig(clusterId, exportConfigId).DbAuditExporterConfigSpec(*dbAuditLogsExporterSpec).Execute()
resp, r, err := authApi.UpdateDbAuditExporterConfig(clusterId, exportConfigId).DbAuditExporterConfigSpec(*dbAuditLogsExporterSpec).Execute()

if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err))
}

dbAuditTelemetryProviderId := resp.GetData().Info.Id
dbAuditIntegrationId := resp.GetData().Info.Id

msg := fmt.Sprintf("The db audit exporter config %s is being updated", formatter.Colorize(dbAuditTelemetryProviderId, formatter.GREEN_COLOR))
msg := fmt.Sprintf("The db audit exporter config %s is being updated", formatter.Colorize(dbAuditIntegrationId, formatter.GREEN_COLOR))

fmt.Println(msg)

Expand All @@ -144,7 +144,7 @@ var listDbAuditLogsExporterCmd = &cobra.Command{

clusterId, _ := cmd.Flags().GetString("cluster-id")

resp, r, err := authApi.ListDbAuditLogsExportConfigs(clusterId).Execute()
resp, r, err := authApi.ListDbAuditExporterConfig(clusterId).Execute()

if err != nil {
logrus.Debugf("Full HTTP response: %v", r)
Expand Down Expand Up @@ -187,7 +187,7 @@ var removeDbAuditLogsExporterCmd = &cobra.Command{
clusterId, _ := cmd.Flags().GetString("cluster-id")
exportConfigId, _ := cmd.Flags().GetString("export-config-id")

resp, err := authApi.DeleteDbAuditLogsExportConfig(clusterId, exportConfigId).Execute()
resp, err := authApi.UnassignDbAuditLogsExportConfig(clusterId, exportConfigId).Execute()

if err != nil {
logrus.Debugf("Full HTTP response: %v", resp)
Expand All @@ -201,8 +201,8 @@ var removeDbAuditLogsExporterCmd = &cobra.Command{
func init() {
DbAuditLogsExporterCmd.AddCommand(assignDbAuditLogsExporterCmd)
assignDbAuditLogsExporterCmd.Flags().SortFlags = false
assignDbAuditLogsExporterCmd.Flags().String("telemetry-provider-id", "", "[REQUIRED] The ID of the telemetry provider")
assignDbAuditLogsExporterCmd.MarkFlagRequired("telemetry-provider-id")
assignDbAuditLogsExporterCmd.Flags().String("integration-id", "", "[REQUIRED] The ID of the Integration")
assignDbAuditLogsExporterCmd.MarkFlagRequired("integration-id")
assignDbAuditLogsExporterCmd.Flags().StringToString("ysql-config", nil, `[REQUIRED] The ysql config to setup DB auditting
Please provide key value pairs as follows:
log_catalog=<boolean>,log_level=<LOG_LEVEL>,log_client=<boolean>,log_parameter=<boolean>,
Expand All @@ -224,8 +224,8 @@ func init() {
updateDbAuditLogsExporterCmd.Flags().SortFlags = false
updateDbAuditLogsExporterCmd.Flags().String("export-config-id", "", "[REQUIRED] The ID of the DB audit export config")
updateDbAuditLogsExporterCmd.MarkFlagRequired("export-config-id")
updateDbAuditLogsExporterCmd.Flags().String("telemetry-provider-id", "", "[REQUIRED] The ID of the telemetry provider")
updateDbAuditLogsExporterCmd.MarkFlagRequired("telemetry-provider-id")
updateDbAuditLogsExporterCmd.Flags().String("integration-id", "", "[REQUIRED] The ID of the Integration")
updateDbAuditLogsExporterCmd.MarkFlagRequired("integration-id")
updateDbAuditLogsExporterCmd.Flags().StringToString("ysql-config", nil, `The ysql config to setup DB auditting
Please provide key value pairs as follows:
log_catalog=<boolean>,log_level=<LOG_LEVEL>,log_client=<boolean>,log_parameter=<boolean>,
Expand All @@ -245,7 +245,7 @@ func init() {
removeDbAuditLogsExporterCmd.Flags().BoolP("force", "f", false, "Bypass the prompt for non-interactive usage")
}

func setDbAuditLogsExporterSpec(ysqlConfigMap map[string]string, statementClasses string, telemetryProviderId string) (*ybmclient.DbAuditExporterConfigSpec, error) {
func setDbAuditLogsExporterSpec(ysqlConfigMap map[string]string, statementClasses string, integrationId string) (*ybmclient.DbAuditExporterConfigSpec, error) {
log_catalog := ysqlConfigMap["log_catalog"]
log_client := ysqlConfigMap["log_client"]
log_level := ysqlConfigMap["log_level"]
Expand Down Expand Up @@ -337,5 +337,5 @@ func setDbAuditLogsExporterSpec(ysqlConfigMap map[string]string, statementClasse

ysqlConfig.SetLogSettings(*log_settings)

return ybmclient.NewDbAuditExporterConfigSpec(*ysqlConfig, telemetryProviderId), nil
return ybmclient.NewDbAuditExporterConfigSpec(*ysqlConfig, integrationId), nil
}
18 changes: 9 additions & 9 deletions cmd/db_audit_logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ var _ = Describe("Db Audit", func() {
ghttp.RespondWithJSONEncodedPtr(&statusCode, responseDbAudit),
),
)
cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "assign", "--cluster-id", "7bb68af6-0875-42e0-8665-dcf634ed9fd1", "--telemetry-provider-id", "7c07c103-e3b2-48b6-ac30-764e9b5275e1", "--ysql-config", "log_catalog=true,log_client=true,log_level=INFO,log_parameter=false,log_statement_once=false,log_relation=false", "--statement_classes", "READ,WRITE")
cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "assign", "--cluster-id", "7bb68af6-0875-42e0-8665-dcf634ed9fd1", "--integration-id", "7c07c103-e3b2-48b6-ac30-764e9b5275e1", "--ysql-config", "log_catalog=true,log_client=true,log_level=INFO,log_parameter=false,log_statement_once=false,log_relation=false", "--statement_classes", "READ,WRITE")
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expect(session.Out).Should(gbytes.Say(`The db audit exporter config 9e3fabbc-849c-4a77-bdb2-9422e712e7dc is being created
ID Date Created Cluster ID Telemetry Provider ID State Ysql Config
ID Date Created Cluster ID Integration ID State Ysql Config
9e3fabbc-849c-4a77-bdb2-9422e712e7dc 2024-02-27T06:30:51.304Z 7bb68af6-0875-42e0-8665-dcf634ed9fd1 7c07c103-e3b2-48b6-ac30-764e9b5275e1 ACTIVE {\"log_settings\":{\"log_catalog\":true,\"log_client\":true,\"log_level\":\"LOG\",\"log_parameter\":false,\"log_relation\":false,\"log_statement_once\":false},\"statement_classes\":\[\"READ\",\"WRITE\"]}`))
session.Kill()
})
Expand All @@ -77,12 +77,12 @@ ID Date Created Cluster ID
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expect(session.Err).Should(gbytes.Say(`\bError: required flag\(s\) "telemetry-provider-id", "ysql-config", "statement_classes", "cluster-id" not set\b`))
Expect(session.Err).Should(gbytes.Say(`\bError: required flag\(s\) "integration-id", "ysql-config", "statement_classes", "cluster-id" not set\b`))
session.Kill()
})
It("should return required log setting when not set", func() {

cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "assign", "--cluster-id", "7bb68af6-0875-42e0-8665-dcf634ed9fd1", "--telemetry-provider-id", "7c07c103-e3b2-48b6-ac30-764e9b5275e1", "--ysql-config", "log_catalog=true,log_client=true,log_level=INFO,log_parameter=false,log_relation=false", "--statement_classes", "READ,WRITE")
cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "assign", "--cluster-id", "7bb68af6-0875-42e0-8665-dcf634ed9fd1", "--integration-id", "7c07c103-e3b2-48b6-ac30-764e9b5275e1", "--ysql-config", "log_catalog=true,log_client=true,log_level=INFO,log_parameter=false,log_relation=false", "--statement_classes", "READ,WRITE")
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expand All @@ -106,7 +106,7 @@ ID Date Created Cluster ID
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expect(session.Out).Should(gbytes.Say(`ID Date Created Cluster ID Telemetry Provider ID State Ysql Config
Expect(session.Out).Should(gbytes.Say(`ID Date Created Cluster ID Integration ID State Ysql Config
9e3fabbc-849c-4a77-bdb2-9422e712e7dc 2024-02-27T06:30:51.304Z 7bb68af6-0875-42e0-8665-dcf634ed9fd1 7c07c103-e3b2-48b6-ac30-764e9b5275e1 ACTIVE {\"log_settings\":{\"log_catalog\":true,\"log_client\":true,\"log_level\":\"LOG\",\"log_parameter\":false,\"log_relation\":false,\"log_statement_once\":false},\"statement_classes\":\[\"READ\",\"WRITE\"]}`))
session.Kill()
})
Expand All @@ -133,12 +133,12 @@ ID Date Created Cluster ID
ghttp.RespondWithJSONEncodedPtr(&statusCode, responseDbAudit),
),
)
cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "update", "--cluster-id", "7bb68af6-0875-42e0-8665-dcf634ed9fd1", "--export-config-id", "123e4567-e89b-12d3-a456-426614174000", "--telemetry-provider-id", "7c07c103-e3b2-48b6-ac30-764e9b5275e1", "--ysql-config", "log_catalog=true,log_client=true,log_level=INFO,log_parameter=false,log_statement_once=false,log_relation=false", "--statement_classes", "READ,WRITE")
cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "update", "--cluster-id", "7bb68af6-0875-42e0-8665-dcf634ed9fd1", "--export-config-id", "123e4567-e89b-12d3-a456-426614174000", "--integration-id", "7c07c103-e3b2-48b6-ac30-764e9b5275e1", "--ysql-config", "log_catalog=true,log_client=true,log_level=INFO,log_parameter=false,log_statement_once=false,log_relation=false", "--statement_classes", "READ,WRITE")
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expect(session.Out).Should(gbytes.Say(`The db audit exporter config 9e3fabbc-849c-4a77-bdb2-9422e712e7dc is being updated
ID Date Created Cluster ID Telemetry Provider ID State Ysql Config
ID Date Created Cluster ID Integration ID State Ysql Config
9e3fabbc-849c-4a77-bdb2-9422e712e7dc 2024-02-27T06:30:51.304Z 7bb68af6-0875-42e0-8665-dcf634ed9fd1 7c07c103-e3b2-48b6-ac30-764e9b5275e1 ACTIVE {\"log_settings\":{\"log_catalog\":true,\"log_client\":true,\"log_level\":\"LOG\",\"log_parameter\":false,\"log_relation\":false,\"log_statement_once\":false},\"statement_classes\":\[\"READ\",\"WRITE\"]}`))
session.Kill()
})
Expand All @@ -148,12 +148,12 @@ ID Date Created Cluster ID
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\\) \"export-config-id\", \"telemetry-provider-id\", \"cluster-id\" not set$)"))
Expect(session.Err).Should(gbytes.Say("(?m:Error: required flag\\(s\\) \"export-config-id\", \"integration-id\", \"cluster-id\" not set$)"))
session.Kill()
})
It("should return required log setting when not set", func() {

cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "update", "--cluster-id", "7bb68af6-0875-42e0-8665-dcf634ed9fd1", "--export-config-id", "123e4567-e89b-12d3-a456-426614174000", "--telemetry-provider-id", "7c07c103-e3b2-48b6-ac30-764e9b5275e1", "--ysql-config", "log_catalog=true,log_client=true,log_level=INFO,log_parameter=false,log_statement_once=false", "--statement_classes", "READ,WRITE")
cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "update", "--cluster-id", "7bb68af6-0875-42e0-8665-dcf634ed9fd1", "--export-config-id", "123e4567-e89b-12d3-a456-426614174000", "--integration-id", "7c07c103-e3b2-48b6-ac30-764e9b5275e1", "--ysql-config", "log_catalog=true,log_client=true,log_level=INFO,log_parameter=false,log_statement_once=false", "--statement_classes", "READ,WRITE")
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(2)
Expand Down
Loading