mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-04 20:08:38 +00:00
💡 Better log messages
This commit is contained in:
parent
fa0fb62e07
commit
cae3b4fe17
@ -53,7 +53,7 @@ func startProxyReportErrorIfAny(kubernetesProvider *kubernetes.Provider, ctx con
|
||||
connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(srcPort), connect.DefaultRetries, connect.DefaultTimeout)
|
||||
if err := connector.TestConnection(healthCheck); err != nil {
|
||||
log.Error().
|
||||
Str("service-name", serviceName).
|
||||
Str("service", serviceName).
|
||||
Err(errormessage.FormatError(err)).
|
||||
Msg("Couldn't connect to service.")
|
||||
cancel()
|
||||
|
@ -33,7 +33,7 @@ Supported protocols are HTTP and gRPC.`,
|
||||
|
||||
log.Info().
|
||||
Str("limit", config.Config.Tap.HumanMaxEntriesDBSize).
|
||||
Msg("Kubeshark will store traffic up to a limit. The old traffic will be cleared once the limit is reached.")
|
||||
Msg("Kubeshark will store the traffic up to a limit. Oldest entries will be removed once the limit is reached.")
|
||||
|
||||
return nil
|
||||
},
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/kubeshark/kubeshark/internal/connect"
|
||||
@ -69,14 +68,7 @@ func RunKubesharkTap() {
|
||||
}
|
||||
}
|
||||
|
||||
var namespacesStr string
|
||||
if !utils.Contains(state.targetNamespaces, kubernetes.K8sAllNamespaces) {
|
||||
namespacesStr = fmt.Sprintf("namespaces \"%s\"", strings.Join(state.targetNamespaces, "\", \""))
|
||||
} else {
|
||||
namespacesStr = "all namespaces"
|
||||
}
|
||||
|
||||
log.Info().Str("namespace", namespacesStr).Msg("Tapping pods in:")
|
||||
log.Info().Strs("namespaces", state.targetNamespaces).Msg("Targetting pods in:")
|
||||
|
||||
if err := printTappedPodsPreview(ctx, kubernetesProvider, state.targetNamespaces); err != nil {
|
||||
log.Error().Err(errormessage.FormatError(err)).Msg("Error listing pods!")
|
||||
@ -141,7 +133,7 @@ func printTappedPodsPreview(ctx context.Context, kubernetesProvider *kubernetes.
|
||||
printNoPodsFoundSuggestion(namespaces)
|
||||
}
|
||||
for _, tappedPod := range matchingPods {
|
||||
log.Info().Msg(fmt.Sprintf(utils.Green, fmt.Sprintf("+%s", tappedPod.Name)))
|
||||
log.Info().Msg(fmt.Sprintf("New pod: %s", fmt.Sprintf(utils.Green, tappedPod.Name)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -464,14 +456,14 @@ func postHubStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider
|
||||
}
|
||||
|
||||
url := kubernetes.GetLocalhostOnPort(config.Config.Hub.PortForward.SrcPort)
|
||||
log.Info().Msg(fmt.Sprintf("Hub is available at %s", url))
|
||||
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, "Hub is available at:"))
|
||||
}
|
||||
|
||||
func postFrontStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider, cancel context.CancelFunc) {
|
||||
startProxyReportErrorIfAny(kubernetesProvider, ctx, cancel, kubernetes.FrontServiceName, config.Config.Front.PortForward.SrcPort, config.Config.Front.PortForward.DstPort, "")
|
||||
|
||||
url := kubernetes.GetLocalhostOnPort(config.Config.Front.PortForward.SrcPort)
|
||||
log.Info().Msg(fmt.Sprintf("Kubeshark is available at %s", url))
|
||||
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, "Kubeshark is available at:"))
|
||||
if !config.Config.HeadlessMode {
|
||||
utils.OpenBrowser(url)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func runKubesharkView() {
|
||||
|
||||
connector := connect.NewConnector(url, connect.DefaultRetries, connect.DefaultTimeout)
|
||||
if err := connector.TestConnection(""); err != nil {
|
||||
log.Error().Msg(fmt.Sprintf(utils.Error, "Couldn't connect to Hub."))
|
||||
log.Error().Msg(fmt.Sprintf(utils.Red, "Couldn't connect to Hub."))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -316,10 +316,10 @@ func (tapperSyncer *KubesharkTapperSyncer) updateCurrentlyTappedPods() (err erro
|
||||
podsToTap := excludeKubesharkPods(matchingPods)
|
||||
addedPods, removedPods := getPodArrayDiff(tapperSyncer.CurrentlyTappedPods, podsToTap)
|
||||
for _, addedPod := range addedPods {
|
||||
log.Info().Str("pod", addedPod.Name).Msg("Tapping new pod.")
|
||||
log.Info().Str("pod", addedPod.Name).Msg("Currently targetting:")
|
||||
}
|
||||
for _, removedPod := range removedPods {
|
||||
log.Info().Str("pod", removedPod.Name).Msg("Pod is no longer running. Tapping is stopped.")
|
||||
log.Info().Str("pod", removedPod.Name).Msg("Pod is no longer running. Targetting is stopped.")
|
||||
}
|
||||
if len(addedPods) > 0 || len(removedPods) > 0 {
|
||||
tapperSyncer.CurrentlyTappedPods = podsToTap
|
||||
|
@ -816,7 +816,7 @@ func (provider *Provider) ApplyKubesharkTapperDaemonSet(ctx context.Context, nam
|
||||
Str("namespace", namespace).
|
||||
Str("daemonset-name", daemonSetName).
|
||||
Str("image", podImage).
|
||||
Str("pod-name", tapperPodName).
|
||||
Str("pod", tapperPodName).
|
||||
Msg("Applying tapper DaemonSets.")
|
||||
|
||||
if len(nodeNames) == 0 {
|
||||
|
@ -24,7 +24,7 @@ const kubesharkServicePort = 80
|
||||
func StartProxy(kubernetesProvider *Provider, proxyHost string, srcPort uint16, dstPort uint16, kubesharkNamespace string, kubesharkServiceName string, cancel context.CancelFunc) (*http.Server, error) {
|
||||
log.Info().
|
||||
Str("namespace", kubesharkNamespace).
|
||||
Str("service-name", kubesharkServiceName).
|
||||
Str("service", kubesharkServiceName).
|
||||
Int("src-port", int(srcPort)).
|
||||
Int("dst-port", int(dstPort)).
|
||||
Msg("Starting proxy...")
|
||||
@ -112,7 +112,7 @@ func NewPortForward(kubernetesProvider *Provider, namespace string, podRegex *re
|
||||
|
||||
log.Info().
|
||||
Str("namespace", namespace).
|
||||
Str("pod-name", podName).
|
||||
Str("pod", podName).
|
||||
Int("src-port", int(srcPort)).
|
||||
Int("dst-port", int(dstPort)).
|
||||
Msg("Starting proxy using port-forward method...")
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func CheckNewerVersion() {
|
||||
log.Info().Msg("Checking for newer version...")
|
||||
log.Info().Msg("Checking for a newer version...")
|
||||
start := time.Now()
|
||||
client := github.NewClient(nil)
|
||||
latestRelease, _, err := client.Repositories.GetLatestRelease(context.Background(), "kubeshark", "kubeshark")
|
||||
@ -77,6 +77,6 @@ func CheckNewerVersion() {
|
||||
downloadCommand = "sh <(curl -Ls https://kubeshark.co/install)"
|
||||
}
|
||||
msg := fmt.Sprintf("Update available! %v -> %v run:", kubeshark.Ver, gitHubVersion)
|
||||
log.Info().Str("command", downloadCommand).Msg(fmt.Sprintf(utils.Yellow, msg))
|
||||
log.Warn().Str("command", downloadCommand).Msg(fmt.Sprintf(utils.Yellow, msg))
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func CleanUpKubesharkResources(ctx context.Context, cancel context.CancelFunc, kubernetesProvider *kubernetes.Provider, isNsRestrictedMode bool, kubesharkResourcesNamespace string) {
|
||||
log.Info().Msg("Removing Kubeshark resources...")
|
||||
log.Warn().Msg("Removing Kubeshark resources...")
|
||||
|
||||
var leftoverResources []string
|
||||
|
||||
@ -27,7 +27,7 @@ func CleanUpKubesharkResources(ctx context.Context, cancel context.CancelFunc, k
|
||||
for _, resource := range leftoverResources {
|
||||
errMsg += "\n- " + resource
|
||||
}
|
||||
log.Error().Msg(fmt.Sprintf(utils.Error, errMsg))
|
||||
log.Error().Msg(fmt.Sprintf(utils.Red, errMsg))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,14 +79,14 @@ func CreateTapKubesharkResources(ctx context.Context, kubernetesProvider *kubern
|
||||
return kubesharkServiceAccountExists, err
|
||||
}
|
||||
|
||||
log.Info().Str("service-name", kubernetes.HubServiceName).Msg("Successfully created service:")
|
||||
log.Info().Str("service", kubernetes.HubServiceName).Msg("Successfully created a service.")
|
||||
|
||||
_, err = kubernetesProvider.CreateService(ctx, kubesharkResourcesNamespace, kubernetes.FrontServiceName, kubernetes.FrontServiceName, 80, int32(config.Config.Front.PortForward.DstPort), int32(config.Config.Front.PortForward.SrcPort))
|
||||
if err != nil {
|
||||
return kubesharkServiceAccountExists, err
|
||||
}
|
||||
|
||||
log.Info().Str("service-name", kubernetes.FrontServiceName).Msg("Successfully created service:")
|
||||
log.Info().Str("service", kubernetes.FrontServiceName).Msg("Successfully created a service.")
|
||||
|
||||
return kubesharkServiceAccountExists, nil
|
||||
}
|
||||
@ -123,7 +123,7 @@ func createKubesharkHubPod(ctx context.Context, kubernetesProvider *kubernetes.P
|
||||
if _, err = kubernetesProvider.CreatePod(ctx, opts.Namespace, pod); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info().Str("pod-name", pod.Name).Msg("Successfully created pod.")
|
||||
log.Info().Str("pod", pod.Name).Msg("Successfully created a pod.")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -135,6 +135,6 @@ func createFrontPod(ctx context.Context, kubernetesProvider *kubernetes.Provider
|
||||
if _, err = kubernetesProvider.CreatePod(ctx, opts.Namespace, pod); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info().Str("pod-name", pod.Name).Msg("Successfully created pod.")
|
||||
log.Info().Str("pod", pod.Name).Msg("Successfully created a pod.")
|
||||
return nil
|
||||
}
|
||||
|
@ -9,6 +9,4 @@ const (
|
||||
Magenta = "\033[1;35m%s\033[0m"
|
||||
Teal = "\033[1;36m%s\033[0m"
|
||||
White = "\033[1;37m%s\033[0m"
|
||||
Error = Red
|
||||
Warning = Yellow
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user