Merge pull request #642 from openziti/release-next

Release 0.25.2
This commit is contained in:
Paul Lorenz
2022-03-11 11:07:13 -05:00
committed by GitHub
40 changed files with 531 additions and 412 deletions
+16
View File
@@ -1,3 +1,19 @@
# Release 0.25.2
## Deprecations
The Ziti Edge management REST `/database` and `/terminators` endpoints are being deprecated. They belong in the
fabric management API, but there was no fabric REST api at the time when they were added. Now that they are
available under fabric, they will be removed from the edge APIs in a future release, v0.26 or later.
## What's New
* Enhancement: Only translate router ids -> names in `ziti edge traceroute` when requested to with flag
* Enhancement: Add the /database rest API from edge to fabric, where they below
* `ziti fabric db` now as the same commands as `ziti edge db`
* Enhancement: Add `ziti agent` command for sending IPC commands. Contains copy of what was under `ziti ps`.
* Enhancement: Add `ziti agent controller snapshot-db <name or pid>` IPC command
# Release 0.25.1
* Bug fix: Fix panic caused by race condition at router start up
+3 -3
View File
@@ -158,7 +158,7 @@ require (
golang.org/x/image v0.0.0-20191206065243-da761ea9ff43 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220307203707-22a9840ba4d7 // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.7 // indirect
@@ -173,7 +173,7 @@ require (
require (
github.com/jedib0t/go-pretty/v6 v6.2.4
github.com/openziti/edge v0.21.124
github.com/openziti/fabric v0.17.61
github.com/openziti/edge v0.21.127
github.com/openziti/fabric v0.17.62
github.com/rivo/uniseg v0.2.0 // indirect
)
+6 -6
View File
@@ -824,10 +824,10 @@ github.com/openziti/channel v0.18.14 h1:MS6Wfo0BklKI/IQ/HQl+wKJBw9rPimTSSqFIeBcs
github.com/openziti/channel v0.18.14/go.mod h1:F370DYbKEKpIEhRaZVbEK6xN+pirSZx4qnwbObQAV2I=
github.com/openziti/dilithium v0.3.3 h1:PLgQ6PMNLSTzCFbX/h98cmudgz/cU6TmjdSv5NAPD8k=
github.com/openziti/dilithium v0.3.3/go.mod h1:vsCjI2AU/hon9e+dLhUFbCNGesJDj2ASgkySOcpmvjo=
github.com/openziti/edge v0.21.124 h1:+GmkJ/4HFXNeOVv4zn2gmZEURGDBuDi3N8lMzwsw6sI=
github.com/openziti/edge v0.21.124/go.mod h1:qZ4Jn3Y0POBdIQR03maD+GAzNI7C5W57aiBiFE5c7is=
github.com/openziti/fabric v0.17.61 h1:3sWTJdZPfHOsyxGWA0e5D7fQhjaZWRoB8dj9JHfqaPQ=
github.com/openziti/fabric v0.17.61/go.mod h1:8oBcmWriG/nTGF/+8pkv1oAKQY97XXG4ptns8dUTMr4=
github.com/openziti/edge v0.21.127 h1:4Z2AlmSjMgw/a0PQt4aYuVIURW0nQVwnR0mSvgyVZcc=
github.com/openziti/edge v0.21.127/go.mod h1:NIOrmA5yEhdTbmARyPm4DOrdpWiaB33OVpJVj4PkEDY=
github.com/openziti/fabric v0.17.62 h1:V1Eavso4AvMSCMXJYtEATu5NQ9Dtpu3s3OYZt+SuVwY=
github.com/openziti/fabric v0.17.62/go.mod h1:8oBcmWriG/nTGF/+8pkv1oAKQY97XXG4ptns8dUTMr4=
github.com/openziti/foundation v0.17.8 h1:vlX6yQHrs5Tcp39xHylJhzohTDOZ6d/VrVlQahw7GBo=
github.com/openziti/foundation v0.17.8/go.mod h1:dTaJgdO5OqnKpV+0OPHpnTnqfPpqNGbhJv8O6pMot6o=
github.com/openziti/sdk-golang v0.16.20 h1:AtSaD0Do5HgkDWFR0dLUVpiOpky2WAh6cf78hcG30jk=
@@ -1382,8 +1382,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/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-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220307203707-22a9840ba4d7 h1:8IVLkfbr2cLhv0a/vKq4UFUcJym8RmDoDboxCFWEjYE=
golang.org/x/sys v0.0.0-20220307203707-22a9840ba4d7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/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-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
+3 -3
View File
@@ -19,7 +19,7 @@ Lastly, you can choose to run [docker](https://docs.docker.com/get-started/) dir
more verbose but should you prefer to not use docker-compose it can also illustrate how to establish
a Ziti Network piece by piece.
## Prerequisties
## Prerequisites
### Bash
@@ -91,7 +91,7 @@ Before running the commands below please do the following:
#make a docker network for isolation while allowing the parts to be able to interact
docker network create "$zitinw"
### Staring the Containers
### Starting the Containers
To start the containers you can simply run these two commands in two different shells. (or choose to daemonize them
once you're ready to do so). Take special note of the initial variables used in these commands. The ${zitinw} variable
@@ -103,7 +103,7 @@ Ziti Controller:
Ziti Edge Router:
routerName=edge-router; docker run -d --name "${zitinw}-${routerName}" --rm -e ZITI_EDGE_ROUTER_RAWNAME="${routerName}" --volume "${zitinw_shared}":/openziti/shared -it --network="${zitinw}" --hostname "${routerName}" --network-alias="${routerName}" --rm openziti/quickstart /openziti/scripts/run-edge-router.sh edge
routerName=edge-router; docker run -d --name "${zitinw}-${routerName}" --rm -e ZITI_EDGE_ROUTER_RAWNAME="${routerName}" --volume "${zitinw_shared}":/openziti/shared -it --network="${zitinw}" --hostname "${routerName}" --network-alias="${routerName}" --rm openziti/quickstart /openziti/scripts/run-router.sh edge
+8 -1
View File
@@ -1,7 +1,14 @@
Building and Deploying the Latest Quickstart Docker Image
==========================
Build Docker Image
Build Docker Image for Local Dev (probably for docker-compose testing)
------------------
1. change to this directory: `cd quickstart/docker`
2. run the questionably named `./pushDevBuild.sh` which will create a `openziti/quickstart:dev` tag
3. update `docker-compose.yml` and replace `:latest` with `:dev`
4. run `docker-compose` as normal
Build Docker Image For Publication
------------------
1. change to this directory: `cd quickstart/docker`
1. set an environment variable: `export ZITI_HOME=$(pwd)`
@@ -0,0 +1 @@
docker run --network docker_zitiblue --rm -it openziti/quickstart /bin/bash
+5 -5
View File
@@ -32,7 +32,7 @@ services:
volumes:
- ziti-fs:/openziti
entrypoint: /bin/bash
command: "/openziti/scripts/run-edge-router.sh edge"
command: "/openziti/scripts/run-router.sh edge"
ziti-edge-router-wss:
image: openziti/quickstart:latest
@@ -49,7 +49,7 @@ services:
volumes:
- ziti-fs:/openziti
entrypoint: /bin/bash
command: "/openziti/scripts/run-edge-router.sh wss"
command: "/openziti/scripts/run-router.sh wss"
ziti-fabric-router-br:
image: openziti/quickstart:latest
@@ -65,7 +65,7 @@ services:
volumes:
- ziti-fs:/openziti
entrypoint: /bin/bash
command: "/openziti/scripts/run-edge-router.sh fabric"
command: "/openziti/scripts/run-router.sh fabric"
ziti-private-red:
image: openziti/quickstart:latest
@@ -80,7 +80,7 @@ services:
volumes:
- ziti-fs:/openziti
entrypoint: /bin/bash
command: "/openziti/scripts/run-edge-router.sh private"
command: "/openziti/scripts/run-router.sh private"
ziti-private-blue:
image: openziti/quickstart:latest
@@ -95,7 +95,7 @@ services:
volumes:
- ziti-fs:/openziti
entrypoint: /bin/bash
command: "/openziti/scripts/run-edge-router.sh private"
command: "/openziti/scripts/run-router.sh private"
web-test-blue:
image: crccheck/hello-world
+3 -1
View File
@@ -22,7 +22,9 @@ RUN mkdir -p "${ZITI_SCRIPTS}"
# copy the ziti binaries to a directory already on the path
COPY --chown=ziti ziti.ignore "${ZITI_BIN_DIR}"
COPY --chown=ziti *.sh "${ZITI_SCRIPTS}/"
COPY --chown=ziti ziti-cli-functions.sh "${ZITI_SCRIPTS}/"
COPY --chown=ziti run-controller.sh "${ZITI_SCRIPTS}/"
COPY --chown=ziti run-router.sh "${ZITI_SCRIPTS}/"
RUN /bin/bash -c "source ${ZITI_SCRIPTS}/ziti-cli-functions.sh; ziti_createEnvFile; echo source ${ZITI_HOME}/ziti.env >> ~/.bashrc"
@@ -1,5 +1,8 @@
#!/bin/bash
# give the controller time to ramp up before running if running in docker-compose
sleep 5
. "${ZITI_SCRIPTS}/ziti-cli-functions.sh"
if [[ "${ZITI_CONTROLLER_RAWNAME-}" == "" ]]; then export export ZITI_CONTROLLER_RAWNAME="ziti-controller"; fi
@@ -8,7 +11,6 @@ if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" == "" ]]; then export export ZITI_EDGE_ROUT
if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; fi
if [[ "${ZITI_EDGE_ROUTER_HOSTNAME}" == "" ]]; then export ZITI_EDGE_ROUTER_HOSTNAME="${ZITI_EDGE_ROUTER_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi
generateEnvFile
. ${ZITI_HOME}/ziti.env
# shellcheck disable=SC2091
@@ -17,8 +19,6 @@ until $(curl -s -o /dev/null --fail -k "https://${ZITI_EDGE_CTRL_ADVERTISED_HOST
sleep 2
done
sleep 2
createRouterPki "${ZITI_EDGE_ROUTER_RAWNAME}"
zitiLogin
+24 -28
View File
@@ -423,15 +423,15 @@ function ziti_expressConfiguration {
"${ZITI_BIN_DIR-}/ziti" edge delete service-edge-router-policy allSvcPublicRouters > /dev/null
"${ZITI_BIN_DIR-}/ziti" edge create service-edge-router-policy allSvcPublicRouters --edge-router-roles '#public' --service-roles '#all' > /dev/null
createRouterPki
if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" != "" ]]; then
echo "ZITI_EDGE_ROUTER_RAWNAME OVERRIDDEN: $ZITI_EDGE_ROUTER_RAWNAME"
else
ZITI_EDGE_ROUTER_RAWNAME="${ZITI_NETWORK}-edge-router"
fi
echo "USING ZITI_EDGE_ROUTER_RAWNAME: $ZITI_EDGE_ROUTER_RAWNAME"
createRouterPki "${ZITI_EDGE_ROUTER_RAWNAME}"
createEdgeRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}"
#createRouterSystemdFile "${ZITI_EDGE_ROUTER_RAWNAME}"
@@ -635,8 +635,18 @@ function showIssuerAndSubjectForPEM() {
}
function createRouterPki {
#TODO: this needs to be parameterized to take other router_name
pki_client_server "${ZITI_EDGE_ROUTER_RAWNAME}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}"
# Allow router name to be passed in as arg
router_name="${1-}"
if [[ "${router_name}" == "" ]]; then
echo -e " * ERROR: $(RED "routerName needs to be supplied") "
return 1
fi
mkdir -p "${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}"
export ZITI_ROUTER_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/client.cert"
export ZITI_ROUTER_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.cert"
export ZITI_ROUTER_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.key"
export ZITI_ROUTER_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/cas.cert"
pki_client_server "${router_name}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}"
}
function createPrivateRouterConfig {
@@ -673,10 +683,9 @@ function createPrivateRouterConfig {
return 1
fi
output_file="${ZITI_HOME-}/${router_name}.yaml"
"${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --private > "${output_file}"
echo -e "Controller configuration file written to: $(BLUE "${output_file}")"
output_file="${ZITI_HOME-}/${router_name}.yaml"
"${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --private > "${output_file}"
echo -e "Router configuration file written to: $(BLUE "${output_file}")"
}
function createPki {
@@ -739,10 +748,9 @@ function createFabricRouterConfig {
return 1
fi
output_file="${ZITI_HOME}/${router_name}.yaml"
"${ZITI_BIN_DIR}/ziti" create config router fabric --routerName "${router_name}" > "${output_file}"
echo -e "Fabric router configuration file written to: $(BLUE "${output_file}")"
output_file="${ZITI_HOME}/${router_name}.yaml"
"${ZITI_BIN_DIR}/ziti" create config router fabric --routerName "${router_name}" > "${output_file}"
echo -e "Fabric router configuration file written to: $(BLUE "${output_file}")"
}
function createEdgeRouterWssConfig {
@@ -775,10 +783,9 @@ function createEdgeRouterWssConfig {
return 1
fi
output_file="${ZITI_HOME-}/${router_name}.yaml"
"${ZITI_BIN_DIR}/ziti" create config router edge --wss --routerName "${router_name}" > "${output_file}"
echo -e "Edge router wss configuration file written to: $(BLUE "${output_file}")"
output_file="${ZITI_HOME-}/${router_name}.yaml"
"${ZITI_BIN_DIR}/ziti" create config router edge --wss --routerName "${router_name}" > "${output_file}"
echo -e "WSS Edge router wss configuration file written to: $(BLUE "${output_file}")"
}
# shellcheck disable=SC2120
@@ -814,17 +821,8 @@ function createEdgeRouterConfig {
output_file="${ZITI_HOME}/${router_name}.yaml"
mkdir -p "${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}"
export ZITI_ROUTER_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/client.cert"
export ZITI_ROUTER_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.cert"
export ZITI_ROUTER_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.key"
export ZITI_ROUTER_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/cas.cert"
"${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" > "${output_file}"
echo -e "edge router configuration file written to: $(BLUE "${output_file}")"
unset ZITI_ROUTER_IDENTITY_CERT
unset ZITI_ROUTER_IDENTITY_SERVER_CERT
unset ZITI_ROUTER_IDENTITY_KEY
unset ZITI_ROUTER_IDENTITY_CA
}
function createFabricIdentity {
@@ -956,8 +954,6 @@ function ziti_createEnvFile {
export ZITI_BIN_ROOT="${ZITI_HOME}/ziti-bin"
if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" == "" ]]; then export ZITI_EDGE_ROUTER_RAWNAME="${ZITI_NETWORK}-edge-router"; fi
if [[ "${ZITI_CTRL_MGMT_HOST_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_HOST_PORT="${ZITI_CONTROLLER_HOSTNAME}:10000"; fi
if [[ "${ZITI_CTRL_IDENTITY_CERT-}" == "" ]]; then export ZITI_CTRL_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-client.cert"; fi
if [[ "${ZITI_CTRL_IDENTITY_SERVER_CERT-}" == "" ]]; then export ZITI_CTRL_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-server.chain.pem"; fi
@@ -30,7 +30,7 @@ services:
volumes:
- ziti-fs:/openziti
entrypoint: /bin/bash
command: "/openziti/scripts/run-edge-router.sh edge"
command: "/openziti/scripts/run-router.sh edge"
ziti-console:
image: openziti/zac
+13 -6
View File
@@ -25,6 +25,7 @@ import (
"github.com/openziti/ziti/common/version"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"io"
"os"
"os/signal"
"syscall"
@@ -59,12 +60,6 @@ func run(cmd *cobra.Command, args []string) {
startLogger = startLogger.WithField("nodeId", config.Id.Token)
startLogger.Info("starting ziti-controller")
if cliAgentEnabled {
if err := agent.Listen(agent.Options{Addr: cliAgentAddr}); err != nil {
pfxlog.Logger().WithError(err).Error("unable to start CLI agent")
}
}
var fabricController *controller.Controller
if fabricController, err = controller.NewController(config, version.GetCmdBuildInfo()); err != nil {
fmt.Printf("unable to create fabric controller %+v\n", err)
@@ -78,6 +73,18 @@ func run(cmd *cobra.Command, args []string) {
}
edgeController.Initialize()
if cliAgentEnabled {
options := agent.Options{Addr: cliAgentAddr}
fabricController.RegisterDefaultAgentOps()
options.CustomOps = map[byte]func(conn io.ReadWriter) error{
agent.CustomOp: fabricController.HandleCustomAgentOp,
}
if err := agent.Listen(options); err != nil {
pfxlog.Logger().WithError(err).Error("unable to start CLI agent")
}
}
go waitForShutdown(fabricController, edgeController)
edgeController.Run()
if err := fabricController.Run(); err != nil {
+88
View File
@@ -0,0 +1,88 @@
/*
Copyright NetFoundry, Inc.
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
https://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
import (
"github.com/openziti/edge/router/debugops"
"github.com/openziti/fabric/controller"
"github.com/openziti/fabric/router"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
)
type AgentAppId byte
const (
AgentAppController = AgentAppId(controller.AgentAppId)
AgentAppRouter = AgentAppId(router.AgentAppId)
)
func NewAgentCmd(out io.Writer, errOut io.Writer) *cobra.Command {
agentCmd := &cobra.Command{
Use: "agent",
Short: "Interact with ziti processes using the the IPC agent",
Run: func(cmd *cobra.Command, args []string) {
cmdhelper.CheckErr(cmd.Help())
},
}
ctrlCmd := &cobra.Command{
Use: "controller",
Aliases: []string{"c"},
Short: "Interact with a ziti-controller process using the IPC agent",
Run: func(cmd *cobra.Command, args []string) {
cmdhelper.CheckErr(cmd.Help())
},
}
agentCmd.AddCommand(ctrlCmd)
ctrlCmd.AddCommand(NewSimpleAgentCustomCmd("snapshot-db", AgentAppController, controller.AgentOpSnapshotDbSnaps, out, errOut))
routerCmd := &cobra.Command{
Use: "router",
Aliases: []string{"r"},
Short: "Interact with a ziti-router process using the IPC agent",
Run: func(cmd *cobra.Command, args []string) {
cmdhelper.CheckErr(cmd.Help())
},
}
agentCmd.AddCommand(routerCmd)
routerCmd.AddCommand(NewCmdPsRoute(out, errOut))
routerCmd.AddCommand(NewSimpleAgentCustomCmd("dump-routes", AgentAppRouter, router.DumpForwarderTables, out, errOut))
routerCmd.AddCommand(NewSimpleAgentCustomCmd("disconnect", AgentAppRouter, router.CloseControlChannel, out, errOut))
routerCmd.AddCommand(NewSimpleAgentCustomCmd("reconnect", AgentAppRouter, router.OpenControlChannel, out, errOut))
routerCmd.AddCommand(NewSimpleAgentCustomCmd("dump-api-sessions", AgentAppRouter, debugops.DumpApiSessions, out, errOut))
routerCmd.AddCommand(NewSimpleAgentCustomCmd("dump-links", AgentAppRouter, router.DumpLinks, out, errOut))
agentCmd.AddCommand(NewCmdPsGoversion(out, errOut))
agentCmd.AddCommand(NewCmdPsGc(out, errOut))
agentCmd.AddCommand(NewCmdPsSetgc(out, errOut))
agentCmd.AddCommand(NewCmdPsStack(out, errOut))
agentCmd.AddCommand(NewCmdPsMemstats(out, errOut))
agentCmd.AddCommand(NewCmdPsStats(out, errOut))
agentCmd.AddCommand(NewCmdPsPprofHeap(out, errOut))
agentCmd.AddCommand(NewCmdPsPprofCpu(out, errOut))
agentCmd.AddCommand(NewCmdPsTrace(out, errOut))
agentCmd.AddCommand(NewCmdPsSetLogLevel(out, errOut))
agentCmd.AddCommand(NewCmdPsSetChannelLogLevel(out, errOut))
agentCmd.AddCommand(NewCmdPsClearChannelLogLevel(out, errOut))
return agentCmd
}
@@ -22,7 +22,6 @@ import (
"github.com/openziti/fabric/pb/ctrl_pb"
"github.com/openziti/fabric/router"
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -36,13 +35,12 @@ type PsRouteOptions struct {
}
// NewCmdPsRoute creates a command object for the "create" command
func NewCmdPsRoute(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsRoute(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsRouteOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
@@ -92,14 +90,15 @@ func (o *PsRouteOptions) Run() error {
return err
}
fullBuf := make([]byte, len(buf)+5)
fullBuf[0] = router.UpdateRoute
fullBuf := make([]byte, len(buf)+6)
fullBuf[0] = byte(AgentAppRouter)
fullBuf[1] = router.UpdateRoute
sizeBuf := make([]byte, 4)
binary.LittleEndian.PutUint32(sizeBuf, uint32(len(buf)))
copy(fullBuf[1:], sizeBuf)
copy(fullBuf[5:], buf)
copy(fullBuf[2:], sizeBuf)
copy(fullBuf[6:], buf)
return agent.MakeRequest(addr, agent.CustomOp, fullBuf, os.Stdout)
}
@@ -18,24 +18,22 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
"os"
)
type PsBasicRouterCmdOptions struct {
type SimpleAgentCmdOptions struct {
PsOptions
}
func NewCmdPsBasicRouterCmd(name string, op byte, f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsBasicRouterCmdOptions{
func NewSimpleAgentCustomCmd(name string, appId AgentAppId, op byte, out io.Writer, errOut io.Writer) *cobra.Command {
options := &SimpleAgentCmdOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
@@ -46,7 +44,7 @@ func NewCmdPsBasicRouterCmd(name string, op byte, f cmdutil.Factory, out io.Writ
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run(op)
err := options.Run(appId, op)
cmdhelper.CheckErr(err)
},
}
@@ -57,13 +55,13 @@ func NewCmdPsBasicRouterCmd(name string, op byte, f cmdutil.Factory, out io.Writ
}
// Run implements the command
func (o *PsBasicRouterCmdOptions) Run(op byte) error {
func (o *SimpleAgentCmdOptions) Run(appId AgentAppId, op byte) error {
addr, err := agent.ParseGopsAddress(o.Args)
if err != nil {
return err
}
buf := []byte{op}
buf := []byte{byte(appId), op}
return agent.MakeRequest(addr, agent.CustomOp, buf, os.Stdout)
}
+3 -1
View File
@@ -131,7 +131,8 @@ func NewCmdRoot(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Comm
createCommands := NewCmdCreate(f, out, err)
updateCommands := NewCmdUpdate(f, out, err)
executeCommands := NewCmdExecute(f, out, err)
psCommands := NewCmdPs(f, out, err)
agentCommands := NewAgentCmd(out, err)
psCommands := NewCmdPs(out, err)
pkiCommands := NewCmdPKI(f, out, err)
fabricCommand := fabric.NewFabricCmd(p)
edgeCommand := edge.NewCmdEdge(f, out, err)
@@ -161,6 +162,7 @@ func NewCmdRoot(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Comm
Message: "Executing Ziti components:",
Commands: []*cobra.Command{
executeCommands,
agentCommands,
psCommands,
pkiCommands,
unwrapIdentityFileCommand,
-5
View File
@@ -19,7 +19,6 @@ package cmd
import (
"fmt"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/table"
"github.com/openziti/ziti/ziti/cmd/ziti/internal/log"
"github.com/spf13/cobra"
"io"
@@ -57,10 +56,6 @@ func (c *CommonOptions) Stdout() io.Writer {
return os.Stdout
}
func (c *CommonOptions) CreateTable() table.Table {
return c.Factory.CreateTable(c.Stdout())
}
// Debugf outputs the given text to the console if verbose mode is enabled
func (c *CommonOptions) Debugf(format string, a ...interface{}) {
if c.Verbose {
@@ -32,6 +32,8 @@ func SetZitiRouterIdentity(r *RouterTemplateValues, routerName string) {
val := os.Getenv(constants.ZitiEdgeRouterRawNameVarName)
if val != "" {
r.Edge.Hostname = val
} else {
r.Edge.Hostname, _ = os.Hostname()
}
}
func SetZitiRouterIdentityCert(r *RouterTemplateValues, routerName string) {
+8 -4
View File
@@ -20,6 +20,7 @@ type traceRouteOptions struct {
hops uint8
configFile string
timeout time.Duration
lookupRouterName bool
}
func newTraceRouteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
@@ -50,6 +51,7 @@ func newTraceRouteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
cmd.Flags().Uint8Var(&options.hops, "hops", 0, "Maximum number of hops")
cmd.Flags().DurationVarP(&options.timeout, "timeout", "t", 5*time.Second, "Trace route response timeout")
cmd.Flags().BoolVarP(&options.Verbose, "verbose", "", false, "Enable verbose logging")
cmd.Flags().BoolVarP(&options.lookupRouterName, "get-router-names", "n", false, "Lookup and output router names instead of ids. Requires admin privileges")
return cmd
}
@@ -99,10 +101,12 @@ func (o *traceRouteOptions) Run() error {
hopLabel := result.HopId
if result.HopType == "forwarder" {
hopLabel, err = mapIdToName("transit-routers", result.HopId, o.Options)
if err != nil {
hopLabel = result.HopId
routerNameLookupsFailed = true
if o.lookupRouterName {
hopLabel, err = mapIdToName("transit-routers", result.HopId, o.Options)
if err != nil {
hopLabel = result.HopId
routerNameLookupsFailed = true
}
}
}
+24
View File
@@ -0,0 +1,24 @@
package fabric
import (
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/common"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
)
func newDbCmd(p common.OptionsProvider) *cobra.Command {
cmd := &cobra.Command{
Use: "db",
Short: "Database management operations for the Ziti Edge Controller",
Run: func(cmd *cobra.Command, args []string) {
err := cmd.Help()
cmdhelper.CheckErr(err)
},
}
cmd.AddCommand(newDbSnapshotCmd(p))
cmd.AddCommand(newDbCheckIntegrityCmd(p))
cmd.AddCommand(newDbCheckIntegrityStatusCmd(p))
return cmd
}
@@ -0,0 +1,140 @@
package fabric
import (
"fmt"
"github.com/Jeffail/gabs"
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/api"
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/common"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/openziti/ziti/ziti/cmd/ziti/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"net/http"
)
type dbCheckIntegrityOptions struct {
api.Options
fix bool
}
func newDbCheckIntegrityCmd(p common.OptionsProvider) *cobra.Command {
options := &dbCheckIntegrityOptions{
Options: api.Options{CommonOptions: p()},
}
cmd := &cobra.Command{
Use: "start-check-integrity",
Short: "starts background operation checking integrity of database references and constraints",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := runCheckIntegrityDb(options)
cmdhelper.CheckErr(err)
},
SuggestFor: []string{},
}
// allow interspersing positional args and flags
cmd.Flags().SetInterspersed(true)
cmd.Flags().BoolVarP(&options.fix, "fix-errors", "f", false, "Attempt to fix any detected errors")
options.AddCommonFlags(cmd)
return cmd
}
func runCheckIntegrityDb(o *dbCheckIntegrityOptions) error {
var target string
if o.fix {
target = "database/fix-data-integrity"
} else {
target = "database/check-data-integrity"
}
if _, err := util.ControllerUpdate("edge", target, "", o.Out, http.MethodPost, o.OutputJSONRequest, o.OutputJSONResponse, o.Options.Timeout, o.Options.Verbose); err != nil {
return err
}
_, err := fmt.Fprint(o.Out, "check integrity operation started\n")
return err
}
func newDbCheckIntegrityStatusCmd(p common.OptionsProvider) *cobra.Command {
options := &dbCheckIntegrityOptions{
Options: api.Options{CommonOptions: p()},
}
cmd := &cobra.Command{
Use: "check-integrity-status",
Short: "shows current results from background operation checking integrity of database references and constraints",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := runCheckIntegrityStatus(options)
cmdhelper.CheckErr(err)
},
SuggestFor: []string{},
}
// allow interspersing positional args and flags
cmd.Flags().SetInterspersed(true)
options.AddCommonFlags(cmd)
return cmd
}
func runCheckIntegrityStatus(o *dbCheckIntegrityOptions) error {
body, err := util.EdgeControllerList("database/data-integrity-results", nil, o.OutputJSONResponse, o.Out, o.Options.Timeout, o.Options.Verbose)
if err != nil {
return err
}
data := body.S("data")
inProgress := data.S("inProgress").Data()
if _, err = fmt.Fprintf(o.Out, "In Progress: %v\n", inProgress); err != nil {
return err
}
fixingErrors := data.S("fixingErrors").Data()
if _, err = fmt.Fprintf(o.Out, "Fixing Errors: %v\n", fixingErrors); err != nil {
return err
}
tooManyErrors := data.S("tooManyErrors").Data()
if _, err = fmt.Fprintf(o.Out, "Too Many Errors: %v (if true, additional errors can be found in controller log)\n", tooManyErrors); err != nil {
return err
}
startTime := data.S("startTime").Data()
if _, err = fmt.Fprintf(o.Out, "Started At: %v\n", startTime); err != nil {
return err
}
endTime := data.S("endTime").Data()
if _, err = fmt.Fprintf(o.Out, "Finished At: %v\n", endTime); err != nil {
return err
}
opError := data.S("error").Data()
if _, err = fmt.Fprintf(o.Out, "Operation Error: %v\n", opError); err != nil {
return err
}
results := data.S("results")
children, err := results.Children()
if len(children) == 0 || errors.Is(gabs.ErrNotObjOrArray, err) {
_, err = fmt.Fprintln(o.Out, "no data integrity errors found")
}
for _, child := range children {
desc := child.S("description").Data().(string)
fixed := child.S("fixed").Data().(bool)
if _, err = fmt.Fprintf(o.Out, "Issue: %v. Fixed: %v\n", desc, fixed); err != nil {
return err
}
}
return err
}
+60
View File
@@ -0,0 +1,60 @@
/*
Copyright NetFoundry, Inc.
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
https://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 fabric
import (
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/api"
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/common"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/openziti/ziti/ziti/cmd/ziti/util"
"github.com/spf13/cobra"
"net/http"
)
type dbSnapshotOptions struct {
api.Options
}
func newDbSnapshotCmd(p common.OptionsProvider) *cobra.Command {
options := &dbSnapshotOptions{
Options: api.Options{CommonOptions: p()},
}
cmd := &cobra.Command{
Use: "snapshot",
Short: "creates a database snapshot",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := runSnapshotDb(options)
cmdhelper.CheckErr(err)
},
SuggestFor: []string{},
}
// allow interspersing positional args and flags
cmd.Flags().SetInterspersed(true)
options.AddCommonFlags(cmd)
return cmd
}
func runSnapshotDb(o *dbSnapshotOptions) error {
_, err := util.ControllerUpdate("edge", "database/snapshot", "", o.Out, http.MethodPost, false, false, o.Options.Timeout, o.Options.Verbose)
return err
}
+1
View File
@@ -33,6 +33,7 @@ func NewFabricCmd(p common.OptionsProvider) *cobra.Command {
fabricCmd.AddCommand(newAddIdentityCmd(p), newRemoveIdentityCmd(p))
fabricCmd.AddCommand(newCreateCommand(p), newListCmd(p), newUpdateCommand(p), newDeleteCmd(p))
fabricCmd.AddCommand(newInspectCmd(p))
fabricCmd.AddCommand(newDbCmd(p))
return fabricCmd
}
+16 -42
View File
@@ -19,8 +19,6 @@ package cmd
import (
"bytes"
"fmt"
"github.com/openziti/edge/router/debugops"
"github.com/openziti/fabric/router"
"github.com/spf13/cobra"
"io"
"os"
@@ -28,7 +26,6 @@ import (
"strconv"
"strings"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/templates"
"github.com/openziti/ziti/ziti/goprocess"
@@ -52,12 +49,11 @@ var (
)
// NewCmdPs Pss a command object for the "Ps" command
func NewCmdPs(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPs(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
}
@@ -73,45 +69,23 @@ func NewCmdPs(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command
},
}
routerCmd := &cobra.Command{
Use: "router",
Short: "Show Ziti router process info",
Long: psLong,
Run: func(cmd *cobra.Command, args []string) {
cmdhelper.CheckErr(cmd.Help())
},
}
cmd.AddCommand(NewCmdPsGet(out, errOut))
cmd.AddCommand(NewCmdPsGoversion(out, errOut))
cmd.AddCommand(NewCmdPsGc(out, errOut))
cmd.AddCommand(NewCmdPsSetgc(out, errOut))
cmd.AddCommand(NewCmdPsStack(out, errOut))
cmd.AddCommand(NewCmdPsMemstats(out, errOut))
cmd.AddCommand(NewCmdPsStats(out, errOut))
cmd.AddCommand(NewCmdPsPprofHeap(out, errOut))
cmd.AddCommand(NewCmdPsPprofCpu(out, errOut))
cmd.AddCommand(NewCmdPsTrace(out, errOut))
cmd.AddCommand(NewCmdPsSetLogLevel(out, errOut))
cmd.AddCommand(NewCmdPsSetChannelLogLevel(out, errOut))
cmd.AddCommand(NewCmdPsClearChannelLogLevel(out, errOut))
cmd.AddCommand(routerCmd)
cmd.AddCommand(NewCmdPsGet(f, out, errOut))
cmd.AddCommand(NewCmdPsGoversion(f, out, errOut))
cmd.AddCommand(NewCmdPsGc(f, out, errOut))
cmd.AddCommand(NewCmdPsSetgc(f, out, errOut))
cmd.AddCommand(NewCmdPsStack(f, out, errOut))
cmd.AddCommand(NewCmdPsMemstats(f, out, errOut))
cmd.AddCommand(NewCmdPsStats(f, out, errOut))
cmd.AddCommand(NewCmdPsPprofHeap(f, out, errOut))
cmd.AddCommand(NewCmdPsPprofCpu(f, out, errOut))
cmd.AddCommand(NewCmdPsTrace(f, out, errOut))
cmd.AddCommand(NewCmdPsSetLogLevel(f, out, errOut))
cmd.AddCommand(NewCmdPsSetChannelLogLevel(f, out, errOut))
cmd.AddCommand(NewCmdPsClearChannelLogLevel(f, out, errOut))
routerCmd.AddCommand(NewCmdPsRoute(f, out, errOut))
routerCmd.AddCommand(NewCmdPsBasicRouterCmd("dump-routes", router.DumpForwarderTables, f, out, errOut))
routerCmd.AddCommand(NewCmdPsBasicRouterCmd("disconnect", router.CloseControlChannel, f, out, errOut))
routerCmd.AddCommand(NewCmdPsBasicRouterCmd("reconnect", router.OpenControlChannel, f, out, errOut))
routerCmd.AddCommand(NewCmdPsBasicRouterCmd("dump-api-sessions", debugops.DumpApiSessions, f, out, errOut))
routerCmd.AddCommand(NewCmdPsBasicRouterCmd("dump-links", router.DumpLinks, f, out, errOut))
options.addPsFlags(cmd)
return cmd
}
func (options *PsOptions) addPsFlags(cmd *cobra.Command) {
// cmd.Flags().StringVarP(&options.Flags.Identity, "identity", "", "", "Which identity to use.")
}
// Run implements this command
func (o *PsOptions) Run() error {
fmt.Println("ps is running")
@@ -20,7 +20,6 @@ import (
"bytes"
"encoding/binary"
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -33,20 +32,20 @@ type PsClearChannelLogLevelOptions struct {
}
// NewCmdPsClearChannelLogLevel creates a command object for the "create" command
func NewCmdPsClearChannelLogLevel(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsClearChannelLogLevel(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsClearChannelLogLevelOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "clear-channel-log-level target channel",
Args: cobra.MinimumNArgs(1),
Use: "clear-channel-log-level target channel",
Short: "Clears a channel-specific log level in the target application",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+6 -7
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -32,20 +31,20 @@ type PsGcOptions struct {
}
// NewCmdPsGc creates a command object for the "create" command
func NewCmdPsGc(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsGc(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsGcOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "gc <optional-target>",
Args: cobra.MaximumNArgs(1),
Use: "gc <optional-target>",
Short: "Run garbage collection in the target application",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+5 -6
View File
@@ -23,7 +23,6 @@ import (
"io"
"strconv"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/openziti/ziti/ziti/cmd/ziti/internal/log"
)
@@ -36,19 +35,19 @@ type PsGetOptions struct {
}
// NewCmdPsGet creates a command object for the "create" command
func NewCmdPsGet(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsGet(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsGetOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "get",
Use: "get",
Short: "Returns information about the target process",
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+6 -7
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -32,20 +31,20 @@ type PsGoversionOptions struct {
}
// NewCmdPsGoversion creates a command object for the "create" command
func NewCmdPsGoversion(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsGoversion(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsGoversionOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "goversion <optional-target>",
Args: cobra.MaximumNArgs(1),
Use: "goversion <optional-target>",
Short: "Returns the golang version of the target application",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+6 -7
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -32,20 +31,20 @@ type PsMemstatsOptions struct {
}
// NewCmdPsMemstats creates a command object for the "create" command
func NewCmdPsMemstats(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsMemstats(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsMemstatsOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "memstats <optional-target>",
Args: cobra.MaximumNArgs(1),
Use: "memstats <optional-target>",
Short: "Returns memory use summary of the target application",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+6 -7
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -32,20 +31,20 @@ type PsPprofCpuOptions struct {
}
// NewCmdPsPprofCpu creates a command object for the "create" command
func NewCmdPsPprofCpu(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsPprofCpu(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsPprofCpuOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "pprof-cpu",
Args: cobra.MaximumNArgs(2),
Use: "pprof-cpu",
Short: "Runs and emits a 30 second pprof from the target application",
Args: cobra.MaximumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+5 -6
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -31,19 +30,19 @@ type PsPprofHeapOptions struct {
}
// NewCmdPsPprofHeap creates a command object for the "create" command
func NewCmdPsPprofHeap(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsPprofHeap(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsPprofHeapOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "pprof-heap",
Use: "pprof-heap",
Short: "Returns a memory heap pprof of the target application",
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
-73
View File
@@ -1,73 +0,0 @@
/*
Copyright NetFoundry, Inc.
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
https://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
import (
"github.com/openziti/fabric/router"
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
"os"
)
// PsRouteOptions the options for the create spring command
type PsRouterReconnectOptions struct {
PsOptions
CtrlListener string
}
// NewCmdPsRouterReconnect creates a command object for the "router-disconnect" command
func NewCmdPsRouterReconnect(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsRouterReconnectOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Args: cobra.MaximumNArgs(1),
Use: "router-reconnect <optional-target> ",
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
cmdhelper.CheckErr(err)
},
}
options.addCommonFlags(cmd)
return cmd
}
// Run implements the command
func (o *PsRouterReconnectOptions) Run() error {
addr, err := agent.ParseGopsAddress(o.Args)
if err != nil {
return err
}
buf := []byte{router.OpenControlChannel}
return agent.MakeRequest(addr, agent.CustomOp, buf, os.Stdout)
}
@@ -20,7 +20,6 @@ import (
"bytes"
"encoding/binary"
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -36,20 +35,20 @@ type PsSetChannelLogLevelOptions struct {
}
// NewCmdPsSetChannelLogLevel creates a command object for the "create" command
func NewCmdPsSetChannelLogLevel(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsSetChannelLogLevel(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsSetChannelLogLevelOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "set-channel-log-level target channel log-level (panic, fatal, error, warn, info, debug, trace)",
Args: cobra.MinimumNArgs(2),
Use: "set-channel-log-level target channel log-level (panic, fatal, error, warn, info, debug, trace)",
Short: "Sets a channel-specific log level in the target application",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+6 -7
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -35,20 +34,20 @@ type PsSetLogLevelOptions struct {
}
// NewCmdPsLogLevel creates a command object for the "create" command
func NewCmdPsSetLogLevel(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsSetLogLevel(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsSetLogLevelOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "set-log-level target log-level (panic, fatal, error, warn, info, debug, trace)",
Args: cobra.MinimumNArgs(1),
Use: "set-log-level target log-level (panic, fatal, error, warn, info, debug, trace)",
Short: "Sets the global logrus logging level in the target application",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+6 -7
View File
@@ -19,7 +19,6 @@ package cmd
import (
"encoding/binary"
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -34,20 +33,20 @@ type PsSetgcOptions struct {
}
// NewCmdPsSetgc creates a command object for the "create" command
func NewCmdPsSetgc(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsSetgc(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsSetgcOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "setgc target gc-percentage",
Args: cobra.MinimumNArgs(1),
Use: "setgc target gc-percentage",
Short: "Sets the GC percentage in the target application",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+6 -7
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -34,20 +33,20 @@ type PsStackOptions struct {
}
// NewCmdPsStack creates a command object for the "create" command
func NewCmdPsStack(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsStack(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsStackOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Args: cobra.MaximumNArgs(1),
Use: "stack [<optional-target>]",
Args: cobra.MaximumNArgs(1),
Use: "stack [<optional-target>]",
Short: "Emits a go-routine stack dump from the target application",
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+6 -7
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -32,20 +31,20 @@ type PsStatsOptions struct {
}
// NewCmdPsStats creates a command object for the "create" command
func NewCmdPsStats(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsStats(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsStatsOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "stats <optional-target>",
Args: cobra.MaximumNArgs(1),
Use: "stats <optional-target>",
Short: "Emits some runtime information (# go-routines, threads, cpus, etc) from the target application",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
+5 -6
View File
@@ -18,7 +18,6 @@ package cmd
import (
"github.com/openziti/foundation/agent"
cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory"
cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
"github.com/spf13/cobra"
"io"
@@ -31,19 +30,19 @@ type PsTraceOptions struct {
}
// NewCmdPsTrace creates a command object for the "create" command
func NewCmdPsTrace(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
func NewCmdPsTrace(out io.Writer, errOut io.Writer) *cobra.Command {
options := &PsTraceOptions{
PsOptions: PsOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "trace",
Use: "trace",
Short: "Turn tracing on for 5 seconds in the target application",
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
-113
View File
@@ -1,113 +0,0 @@
/*
Copyright NetFoundry, Inc.
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
https://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
import (
"errors"
"fmt"
"github.com/openziti/foundation/agent"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
"strconv"
"strings"
"github.com/openziti/ziti/ziti/util"
)
func trace(addr net.TCPAddr, _ []string) error {
fmt.Println("Tracing now, will take 5 secs...")
out, err := cmd(addr, agent.Trace)
if err != nil {
return err
}
if len(out) == 0 {
return errors.New("nothing has traced")
}
tmpfile, err := ioutil.TempFile("", "trace")
if err != nil {
return err
}
if err := ioutil.WriteFile(tmpfile.Name(), out, 0); err != nil {
return err
}
fmt.Printf("Trace dump saved to: %s\n", tmpfile.Name())
// If go tool chain not found, stopping here and keep trace file.
if _, err := exec.LookPath("go"); err != nil {
return nil
}
defer os.Remove(tmpfile.Name())
cmd := exec.Command("go", "tool", "trace", tmpfile.Name())
cmd.Env = os.Environ()
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// targetToAddr tries to parse the target string, be it remote host:port
// or local process's PID.
func targetToAddr(target string) (*net.TCPAddr, error) {
if strings.Contains(target, ":") {
// addr host:port passed
var err error
addr, err := net.ResolveTCPAddr("tcp", target)
if err != nil {
return nil, fmt.Errorf("couldn't parse dst address: %v", err)
}
return addr, nil
}
// try to find port by pid then, connect to local
pid, err := strconv.Atoi(target)
if err != nil {
return nil, fmt.Errorf("couldn't parse PID: %v", err)
}
port, err := util.GetPort(pid)
if err != nil {
return nil, fmt.Errorf("couldn't get port for PID %v: %v", pid, err)
}
addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:"+port)
return addr, nil
}
func cmd(addr net.TCPAddr, c byte, params ...byte) ([]byte, error) {
conn, err := cmdLazy(addr, c, params...)
if err != nil {
return nil, fmt.Errorf("couldn't get port by PID: %v", err)
}
all, err := ioutil.ReadAll(conn)
if err != nil {
return nil, err
}
return all, nil
}
func cmdLazy(addr net.TCPAddr, c byte, params ...byte) (io.Reader, error) {
conn, err := net.DialTCP("tcp", nil, &addr)
if err != nil {
return nil, err
}
buf := []byte{c}
buf = append(buf, params...)
if _, err := conn.Write(buf); err != nil {
return nil, err
}
return conn, nil
}
+12 -10
View File
@@ -22,6 +22,8 @@ import (
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/table"
"github.com/openziti/ziti/ziti/cmd/ziti/internal/log"
"io"
"os"
// "strings"
"github.com/openziti/ziti/common/version"
@@ -77,19 +79,19 @@ func (o *VersionOptions) Run() error {
info := util.ColorInfo
table := o.CreateTable()
table.AddRow("NAME", "VERSION")
t := table.CreateTable(os.Stdout)
t.AddRow("NAME", "VERSION")
table.AddRow(c.ZITI, info(version.GetBuildMetadata(o.Verbose)))
t.AddRow(c.ZITI, info(version.GetBuildMetadata(o.Verbose)))
o.versionPrintZitiApp(c.ZITI_CONTROLLER, &table)
o.versionPrintZitiApp(c.ZITI_FABRIC, &table)
o.versionPrintZitiApp(c.ZITI_PROX_C, &table)
o.versionPrintZitiApp(c.ZITI_ROUTER, &table)
o.versionPrintZitiApp(c.ZITI_TUNNEL, &table)
o.versionPrintZitiApp(c.ZITI_EDGE_TUNNEL, &table)
o.versionPrintZitiApp(c.ZITI_CONTROLLER, &t)
o.versionPrintZitiApp(c.ZITI_FABRIC, &t)
o.versionPrintZitiApp(c.ZITI_PROX_C, &t)
o.versionPrintZitiApp(c.ZITI_ROUTER, &t)
o.versionPrintZitiApp(c.ZITI_TUNNEL, &t)
o.versionPrintZitiApp(c.ZITI_EDGE_TUNNEL, &t)
table.Render()
t.Render()
if !o.NoVersionCheck && !o.Verbose {
return o.versionCheck()