MCPcopy
hub / github.com/koderover/zadig / RunAnalysis

Method RunAnalysis

pkg/tool/analysis/analysis.go:100–201  ·  view source on GitHub ↗
(activeFilters []string)

Source from the content-addressed store, hash-verified

98}
99
100func (a *Analysis) RunAnalysis(activeFilters []string) {
101 coreAnalyzerMap, analyzerMap := GetAnalyzerMap()
102
103 // we get the openapi schema from the server only if required by the flag "with-doc"
104 openapiSchema := &openapi_v2.Document{}
105 if a.WithDoc {
106 var openApiErr error
107 openapiSchema, openApiErr = a.Client.Client.Discovery().OpenAPISchema()
108 if openApiErr != nil {
109 a.Errors = append(a.Errors, fmt.Sprintf("[KubernetesDoc] %s", openApiErr))
110 }
111 }
112
113 analyzerConfig := Analyzer{
114 Client: a.Client,
115 Context: a.Context,
116 Namespace: a.Namespace,
117 AIClient: a.AIClient,
118 OpenapiSchema: openapiSchema,
119 }
120
121 semaphore := make(chan struct{}, a.MaxConcurrency)
122 // if there are no filters selected and no active_filters then run coreAnalyzer
123 if len(a.Filters) == 0 && len(activeFilters) == 0 {
124 var wg sync.WaitGroup
125 var mutex sync.Mutex
126 for _, analyzer := range coreAnalyzerMap {
127 wg.Add(1)
128 semaphore <- struct{}{}
129 go func(analyzer IAnalyzer, wg *sync.WaitGroup, semaphore chan struct{}) {
130 defer wg.Done()
131 results, err := analyzer.Analyze(analyzerConfig)
132 if err != nil {
133 mutex.Lock()
134 a.Errors = append(a.Errors, fmt.Sprintf("[%s] %s", reflect.TypeOf(analyzer).Name(), err))
135 mutex.Unlock()
136 }
137 mutex.Lock()
138 a.Results = append(a.Results, results...)
139 mutex.Unlock()
140 <-semaphore
141 }(analyzer, &wg, semaphore)
142
143 }
144 wg.Wait()
145 return
146 }
147 semaphore = make(chan struct{}, a.MaxConcurrency)
148 // if the filters flag is specified
149 if len(a.Filters) != 0 {
150 var wg sync.WaitGroup
151 var mutex sync.Mutex
152 for _, filter := range a.Filters {
153 if analyzer, ok := analyzerMap[filter]; ok {
154 semaphore <- struct{}{}
155 wg.Add(1)
156 go func(analyzer IAnalyzer, filter string) {
157 defer wg.Done()

Callers 2

EnvAnalysisFunction · 0.95

Calls 6

GetAnalyzerMapFunction · 0.85
AddMethod · 0.80
DoneMethod · 0.65
AnalyzeMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1