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

CICD for VClusterOps Synchronization #1048

Closed
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
2 changes: 1 addition & 1 deletion local-libs/vcluster/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [2023-2024] Open Text.
Copyright [2023-2025] Open Text.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
7 changes: 3 additions & 4 deletions local-libs/vcluster/commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down Expand Up @@ -113,8 +113,6 @@ const (
)

// Flag and key for database replication
//
//nolint:dupl
const (
targetDBNameFlag = "target-db-name"
targetDBNameKey = "targetDBName"
Expand Down Expand Up @@ -217,7 +215,6 @@ var keyEnvVarMap = map[string]string{
tlsModeKey: vclusterTLSModeEnv,
}

//nolint:dupl
const (
createDBSubCmd = "create_db"
stopDBSubCmd = "stop_db"
Expand Down Expand Up @@ -254,6 +251,7 @@ const (
getDrainingStatusSubCmd = "get_draining_status"
upgradeLicenseCmd = "upgrade_license"
checkConnectionSubCmd = "check"
clusterHealth = "cluster_health"
)

// cmdGlobals holds global variables shared by multiple
Expand Down Expand Up @@ -640,6 +638,7 @@ func constructCmds() []*cobra.Command {
makeCmdCreateArchive(),
makeCmdSaveRestorePoint(),
makeCmdUpgradeLicense(),
makeCmdClusterHealth(),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_add_node.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_base.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_check_connection.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
220 changes: 220 additions & 0 deletions local-libs/vcluster/commands/cmd_cluster_health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/*
(c) Copyright [2023-2024] Open Text.
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.
*/

package commands

import (
"encoding/json"
"fmt"
"strconv"

"github.com/spf13/cobra"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/vlog"
)

/* CmdClusterHealth
*
* Implements ClusterCommand interface
*/
type CmdClusterHealth struct {
clusterHealthOptions *vclusterops.VClusterHealthOptions

CmdBase
}

func makeCmdClusterHealth() *cobra.Command {
// CmdClusterHealth
newCmd := &CmdClusterHealth{}
opt := vclusterops.VClusterHealthFactory()
newCmd.clusterHealthOptions = &opt

cmd := makeBasicCobraCmd(
newCmd,
clusterHealth,
"Checks the database cluster health. This is used for testing and debugging only.",
`Checks the database cluster health.

This is used for testing and debugging only.

Examples:
# Check the cluster health
vcluster cluster_health
`,
// TODO: modify this
[]string{dbNameFlag, configFlag, hostsFlag, ipv6Flag, passwordFlag, outputFileFlag},
)

// local flags
newCmd.setLocalFlags(cmd)

return cmd
}

// setLocalFlags will set the local flags the command has
func (c *CmdClusterHealth) setLocalFlags(cmd *cobra.Command) {
// TODO: add some code here
// local flag of CmdClusterHealth,
// --operation : the operation type, including "check", "get_slow_events", "get_transaction_starts", "get_session_starts"
// --txn-id : the transaction id (for slow event and trsanction start)
// --node-name : the node name (for all operations)
// --start-time : the start time (for all operations)
// --end-time : the end time (for all operations)
// --session-id : the session id (for session start and slow event)
// --debug : debug mode (for all operations)
// --threadhold : the threadhold of seconds for slow events (for get_slow_events)
// --thread-id : the thread id (for get_slow_events)
// --phase-duration-desc : the phase duration description (for get_slow_events)
// --event-desc : the event description (for get_slow_events)
// --user-name : the user name (for get_slow_events)

cmd.Flags().StringVar(
&c.clusterHealthOptions.Operation,
"operation",
"",
"The operation type, including 'cascade', 'get_slow_events', 'get_transaction_starts', 'get_session_starts'.",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.TxnID,
"txn-id",
"",
"The transaction id (for slow event and transaction start).",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.NodeName,
"node-name",
"",
"The node name (for all operations).",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.StartTime,
"start-time",
"",
"The start time (for all operations).",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.EndTime,
"end-time",
"",
"The end time (for all operations).",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.SessionID,
"session-id",
"",
"The session id (for session start and slow event).",
)
cmd.Flags().BoolVar(
&c.clusterHealthOptions.Debug,
"debug",
false,
"Debug mode (for all operations).",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.Threadhold,
"threadhold",
"",
"The threadhold of seconds for slow events (for get_slow_events).",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.ThreadID,
"thread-id",
"",
"The thread id (for get_slow_events).",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.PhaseDurationDesc,
"phase-duration-desc",
"",
"The phase duration description (for get_slow_events).",
)
cmd.Flags().StringVar(
&c.clusterHealthOptions.EventDesc,
"event-desc",
"",
"The event description (for get_slow_events).",
)
}

func (c *CmdClusterHealth) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
logger.LogMaskedArgParse(c.argv)

// for some options, we do not want to use their default values,
// if they are not provided in cli,
// reset the value of those options to nil
c.ResetUserInputOptions(&c.clusterHealthOptions.DatabaseOptions)
return c.validateParse(logger)
}

func (c *CmdClusterHealth) validateParse(logger vlog.Printer) error {
logger.Info("Called validateParse()")

if !c.usePassword() {
err := c.getCertFilesFromCertPaths(&c.clusterHealthOptions.DatabaseOptions)
if err != nil {
return err
}
}

// validate txn id is integer
if c.clusterHealthOptions.TxnID != "" {
_, err := c.validateInt(c.clusterHealthOptions.TxnID, "txn-id")
if err != nil {
return err
}
}
err := c.ValidateParseBaseOptions(&c.clusterHealthOptions.DatabaseOptions)
if err != nil {
return err
}
return c.setDBPassword(&c.clusterHealthOptions.DatabaseOptions)
}

// validateInt checks if the given string is a valid integer
func (c *CmdClusterHealth) validateInt(value, fieldName string) (int, error) {
intValue, err := strconv.Atoi(value)
if err != nil {
return 0, fmt.Errorf("%s must be an integer", fieldName)
}
return intValue, nil
}

func (c *CmdClusterHealth) Run(vcc vclusterops.ClusterCommands) error {
vcc.LogInfo("Called method Run()")

options := c.clusterHealthOptions

err := vcc.VClusterHealth(options)
if err != nil {
vcc.LogError(err, "failed to check cluster health.")
return err
}

bytes, err := json.MarshalIndent(options.CascadeStack, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal the traceback result, details: %w", err)
}

c.writeCmdOutputToFile(globals.file, bytes, vcc.GetLog())
vcc.LogInfo("Slow event traceback: ", "slow events", string(bytes))

return nil
}

// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdClusterHealth
func (c *CmdClusterHealth) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) {
c.clusterHealthOptions.DatabaseOptions = *opt
}
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_config_recover.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_config_show.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_connection.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_create_archive.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
4 changes: 2 additions & 2 deletions local-libs/vcluster/commands/cmd_create_connection.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down Expand Up @@ -146,7 +146,7 @@ func (c *CmdCreateConnection) Run(vcc vclusterops.ClusterCommands) error {
// write target db info to vcluster connection file
err := c.writeConn()
if err != nil {
vcc.DisplayError("failed to write the connection file: " + err.Error())
vcc.DisplayError("Failed to write the connection file: " + err.Error())
return nil
}
vcc.DisplayInfo("Successfully wrote the connection file in %s", globals.connFile)
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_create_db.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_drop_db.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_get_draining_status.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_install_packages.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_list_all_nodes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
2 changes: 1 addition & 1 deletion local-libs/vcluster/commands/cmd_manage_config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright [2023-2024] Open Text.
(c) Copyright [2023-2025] Open Text.
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
Expand Down
Loading