Skip to content

Commit

Permalink
adding network analyzer
Browse files Browse the repository at this point in the history
Signed-off-by: jackyalbo <jacky.albo@gmail.com>
  • Loading branch information
jackyalbo committed Dec 11, 2024
1 parent 1fd00fb commit d038b7c
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 4 deletions.
34 changes: 34 additions & 0 deletions deploy/job_analyze_network.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: batch/v1
kind: Job
metadata:
name: noobaa-analyze-network
labels:
app: noobaa
spec:
completions: 1
parallelism: 1
backoffLimit: 0
activeDeadlineSeconds: 60
ttlSecondsAfterFinished: 10
template:
spec:
containers:
- name: noobaa-analyze-network
image: NOOBAA_CORE_IMAGE_PLACEHOLDER
env:
- name: CONTAINER_PLATFORM
value: KUBERNETES
# - name: RESOURCE_NAME
# - name: BUCKET
# - name: ENDPOINT
# - name: REGION
# - name: S3_SIGNATURE_VERSION
# - name: HTTP_PROXY
# - name: HTTPS_PROXY
# - name: NO_PROXY
# - name: NODE_EXTRA_CA_CERTS
command:
- /bin/bash
- -c
- "cd /root/node_modules/noobaa-core/; node ./src/tools/diagnostics/analyze_network.js"
restartPolicy: Never
38 changes: 38 additions & 0 deletions pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5255,6 +5255,44 @@ const File_deploy_internal_text_system_status_readme_rejected_tmpl = `
NooBaa Operator Version: {{.OperatorVersion}}
`

const Sha256_deploy_job_analyze_network_yml = "3ee84a8b230fc2cf9ae5f6c6aafbb2d245b1435262a04e0d9fe7d817b9ae4476"

const File_deploy_job_analyze_network_yml = `apiVersion: batch/v1
kind: Job
metadata:
name: noobaa-analyze-network
labels:
app: noobaa
spec:
completions: 1
parallelism: 1
backoffLimit: 0
activeDeadlineSeconds: 60
ttlSecondsAfterFinished: 10
template:
spec:
containers:
- name: noobaa-analyze-network
image: NOOBAA_CORE_IMAGE_PLACEHOLDER
env:
- name: CONTAINER_PLATFORM
value: KUBERNETES
# - name: RESOURCE_NAME
# - name: BUCKET
# - name: ENDPOINT
# - name: REGION
# - name: S3_SIGNATURE_VERSION
# - name: HTTP_PROXY
# - name: HTTPS_PROXY
# - name: NO_PROXY
# - name: NODE_EXTRA_CA_CERTS
command:
- /bin/bash
- -c
- "cd /root/node_modules/noobaa-core/; node ./src/tools/diagnostics/analyze_network.js"
restartPolicy: Never
`

const Sha256_deploy_job_analyze_resource_yml = "c80810baeda94fd9dd97a6c62241be5c582e08009bdbb1f2a13992c99d90ea33"

const File_deploy_job_analyze_resource_yml = `apiVersion: batch/v1
Expand Down
35 changes: 32 additions & 3 deletions pkg/diagnostics/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,45 @@ func analyzeNamespaceStore(cmd *cobra.Command, namespaceStore *nbv1.NamespaceSto
setJobAnalyzeResource(cmd, analyzeResourceJob, collector)
}

// RunAnalyzeNetwork runs a CLI command
func RunAnalyzeNetwork(cmd *cobra.Command, args []string) {
log := util.Logger()

log.Printf("⏳ Running this command will run the network diagnostic\n")
collector := collectorInstance(cmd)
makeDirForLogs(collector.folderName)
analyzeNetwork(cmd, collector)
destDir, _ := cmd.Flags().GetString("dir")
err := printTestsSummary(collector.folderName)
if err != nil {
log.Errorln("❌ Could not print tests summary")
}
collector.ExportDiagnostics(destDir)
}

func analyzeNetwork(cmd *cobra.Command, collector *Collector) {
analyzeResourceJob := loadAnalyzeNetworkJob()
setImageInJob(analyzeResourceJob)
setJobAnalyzeResource(cmd, analyzeResourceJob, collector)
}


func loadAnalyzeResourceJob() *batchv1.Job {
analyzeResourceJob := util.KubeObject(bundle.File_deploy_job_analyze_resource_yml).(*batchv1.Job)
analyzeResourceJob.Namespace = options.Namespace
return analyzeResourceJob
}

func loadAnalyzeNetworkJob() *batchv1.Job {
analyzeNetworkJob := util.KubeObject(bundle.File_deploy_job_analyze_network_yml).(*batchv1.Job)
analyzeNetworkJob.Namespace = options.Namespace
return analyzeNetworkJob
}

func collectorInstance(cmd *cobra.Command) *Collector {
kubeconfig, _ := cmd.Flags().GetString("kubeconfig")
collector := &Collector{
folderName: fmt.Sprintf("%s_%d", "noobaa_analyze_resource", time.Now().Unix()),
folderName: fmt.Sprintf("%s_%d", "noobaa_analyze_result", time.Now().Unix()),
log: util.Logger(),
kubeconfig: kubeconfig,
kubeCommand: util.GetAvailabeKubeCli(),
Expand Down Expand Up @@ -479,8 +508,8 @@ func printTestsSummary(folderName string) error {
scanner := bufio.NewScanner(file)
shouldPrint := false
// this is a printing that appears if it fails configuring or after the tests run (in the core repo)
prefixToSearchFailed := "Test Diagnose Resource Failed"
prefixToSearchSummary := "Analyze Resource Tests Result"
prefixToSearchFailed := "Test Diagnose Network Failed"
prefixToSearchSummary := "Analyze Network Tests Result"
var indexToExtractLine int
for scanner.Scan() {
line := scanner.Text()
Expand Down
15 changes: 14 additions & 1 deletion pkg/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ func CmdDbDump() *cobra.Command {
func CmdAnalyze() *cobra.Command {
cmd := &cobra.Command{
Use: "analyze",
Short: "Analyze the resource status by running tests on it",
Short: "Analyze the resource/network status by running tests on it",
}
cmd.AddCommand(
CmdAnalyzeBackingStore(),
CmdAnalyzeNamespaceStore(),
CmdAnalyzeResources(),
CmdAnalyzeNetwork(),
)
return cmd
}
Expand All @@ -79,6 +80,18 @@ func CmdReport() *cobra.Command {
return cmd
}

// CmdAnalyzeNetwork returns a CLI command
func CmdAnalyzeNetwork() *cobra.Command {
cmd := &cobra.Command{
Use: "network",
Short: "Run network analyze",
Run: RunAnalyzeNetwork,
}
cmd.Flags().String("job-resources", "", "Analyze job resources JSON")
cmd.Flags().String("dir", "", "collect analyze network tar file into destination directory")
return cmd
}

// CmdAnalyzeBackingStore returns a CLI command
func CmdAnalyzeBackingStore() *cobra.Command {
cmd := &cobra.Command{
Expand Down

0 comments on commit d038b7c

Please sign in to comment.