Skip to content

Commit 1fd19e0

Browse files
authored
Merge pull request #1163 from kiril-keranov/patch-14
[go-migration] Fix omitting of finalize phase by some frameworks
2 parents de383b7 + e977ba5 commit 1fd19e0

10 files changed

Lines changed: 197 additions & 89 deletions

src/java/frameworks/azure_application_insights_agent.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,12 @@ func (a *AzureApplicationInsightsAgentFramework) Supply() error {
101101
a.context.Log.Warning("Could not install default Azure Application Insights configuration: %s", err.Error())
102102
}
103103

104-
// Find the installed JAR
105-
jarPattern := filepath.Join(agentDir, "applicationinsights-agent-*.jar")
106-
matches, err := filepath.Glob(jarPattern)
104+
// constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check
105+
// if jar path exists after the dependency install
106+
err = a.constructJarPath(agentDir)
107107
if err != nil {
108-
return fmt.Errorf("failed to search for Azure Application Insights agent JAR: %w", err)
109-
}
110-
if len(matches) == 0 {
111-
return fmt.Errorf("Azure Application Insights agent JAR not found after installation in %s", agentDir)
108+
return fmt.Errorf("azure application insights agent not found during supply: %w", err)
112109
}
113-
a.jarPath = matches[0]
114110

115111
a.context.Log.Info("Azure Application Insights agent %s installed", dep.Version)
116112
return nil
@@ -145,8 +141,10 @@ func (a *AzureApplicationInsightsAgentFramework) installDefaultConfiguration(age
145141

146142
// Finalize configures the Azure Application Insights agent
147143
func (a *AzureApplicationInsightsAgentFramework) Finalize() error {
148-
if a.jarPath == "" {
149-
return nil
144+
agentDir := filepath.Join(a.context.Stager.DepDir(), "azure_application_insights_agent")
145+
err := a.constructJarPath(agentDir)
146+
if err != nil {
147+
return fmt.Errorf("azure application insights agent not found during finalize: %w", err)
150148
}
151149

152150
a.context.Log.BeginStep("Configuring Azure Application Insights agent")
@@ -277,3 +275,17 @@ func (a *AzureApplicationInsightsAgentFramework) getApplicationName() string {
277275

278276
return ""
279277
}
278+
279+
func (a *AzureApplicationInsightsAgentFramework) constructJarPath(agentDir string) error {
280+
// Find the installed JAR
281+
jarPattern := filepath.Join(agentDir, "applicationinsights-agent-*.jar")
282+
matches, err := filepath.Glob(jarPattern)
283+
if err != nil {
284+
return fmt.Errorf("failed to search for Azure Application Insights agent JAR: %w", err)
285+
}
286+
if len(matches) == 0 {
287+
return fmt.Errorf("agent jar not found after installation in %s", agentDir)
288+
}
289+
a.jarPath = matches[0]
290+
return nil
291+
}

src/java/frameworks/checkmarx_iast_agent.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ func (c *CheckmarxIASTAgentFramework) Supply() error {
8888

8989
// Finalize configures the Checkmarx IAST agent
9090
func (c *CheckmarxIASTAgentFramework) Finalize() error {
91-
if c.jarPath == "" {
92-
return nil
93-
}
91+
agentDir := filepath.Join(c.context.Stager.DepDir(), "checkmarx_iast_agent")
92+
c.jarPath = filepath.Join(agentDir, "cx-agent.jar")
9493

9594
c.context.Log.BeginStep("Configuring Checkmarx IAST agent")
9695

src/java/frameworks/datadog_javaagent.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,11 @@ func (d *DatadogJavaagentFramework) Supply() error {
9696
return fmt.Errorf("failed to install Datadog Javaagent: %w", err)
9797
}
9898

99-
// Find the installed JAR
100-
jarPattern := filepath.Join(datadogDir, "dd-java-agent*.jar")
101-
matches, err := filepath.Glob(jarPattern)
99+
// constructJarPathAndFixClassCount can be skipped here and do it only in finalize, but it can be left
100+
// as a double check if jar path exists after the dependency install
101+
err = d.constructJarPathAndFixClassCount(datadogDir)
102102
if err != nil {
103-
return fmt.Errorf("failed to search for Datadog agent JAR: %w", err)
104-
}
105-
if len(matches) == 0 {
106-
return fmt.Errorf("Datadog agent JAR not found after installation in %s", datadogDir)
107-
}
108-
d.jarPath = matches[0]
109-
110-
// Fix class count (critical for Datadog agent)
111-
if err := d.fixClassCount(); err != nil {
112-
d.context.Log.Warning("Failed to fix class count: %s", err)
113-
// Continue anyway
103+
return fmt.Errorf("datadog Java agent JAR path not found during supply: %w", err)
114104
}
115105

116106
d.context.Log.Info("Datadog Java agent %s installed", dep.Version)
@@ -119,8 +109,10 @@ func (d *DatadogJavaagentFramework) Supply() error {
119109

120110
// Finalize configures the Datadog Java agent
121111
func (d *DatadogJavaagentFramework) Finalize() error {
122-
if d.jarPath == "" {
123-
return nil
112+
datadogDir := filepath.Join(d.context.Stager.DepDir(), "datadog_javaagent")
113+
err := d.constructJarPathAndFixClassCount(datadogDir)
114+
if err != nil {
115+
return fmt.Errorf("datadog Java agent JAR path not found during finalize: %w", err)
124116
}
125117

126118
d.context.Log.BeginStep("Configuring Datadog Java agent")
@@ -310,3 +302,23 @@ func (d *DatadogJavaagentFramework) getApplicationVersion() string {
310302

311303
return ""
312304
}
305+
306+
func (d *DatadogJavaagentFramework) constructJarPathAndFixClassCount(datadogDir string) error {
307+
// Find the installed JAR
308+
jarPattern := filepath.Join(datadogDir, "dd-java-agent*.jar")
309+
matches, err := filepath.Glob(jarPattern)
310+
if err != nil {
311+
return fmt.Errorf("failed to search for Datadog agent JAR: %w", err)
312+
}
313+
if len(matches) == 0 {
314+
return fmt.Errorf("agent jar not found after installation in %s", datadogDir)
315+
}
316+
d.jarPath = matches[0]
317+
318+
// Fix class count (critical for Datadog agent)
319+
if err := d.fixClassCount(); err != nil {
320+
d.context.Log.Warning("Failed to fix class count: %s", err)
321+
// Continue anyway
322+
}
323+
return nil
324+
}

src/java/frameworks/elastic_apm_agent.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,28 @@ func (e *ElasticApmAgentFramework) Supply() error {
7373
return fmt.Errorf("failed to install Elastic APM agent: %w", err)
7474
}
7575

76-
// Find the installed JAR
77-
jarPattern := filepath.Join(elasticDir, "elastic-apm-agent*.jar")
78-
matches, err := filepath.Glob(jarPattern)
76+
err = e.constructJarPath(elasticDir)
7977
if err != nil {
80-
return fmt.Errorf("failed to search for Elastic APM agent JAR: %w", err)
78+
return fmt.Errorf("elastic apm agent jar not found during supply: %w", err)
8179
}
82-
if len(matches) == 0 {
83-
return fmt.Errorf("Elastic APM agent JAR not found after installation in %s", elasticDir)
84-
}
85-
e.jarPath = matches[0]
8680

8781
e.context.Log.Info("Elastic APM agent %s installed", dep.Version)
8882
return nil
8983
}
9084

9185
// Finalize configures the Elastic APM agent
9286
func (e *ElasticApmAgentFramework) Finalize() error {
93-
if e.jarPath == "" || e.service == nil {
94-
return nil
87+
elasticDir := filepath.Join(e.context.Stager.DepDir(), "elastic_apm_agent")
88+
err := e.constructJarPath(elasticDir)
89+
if err != nil {
90+
return fmt.Errorf("elastic apm agent jar not found during finalize: %w", err)
91+
}
92+
service := e.findElasticApmService()
93+
// service should not be nil as detect has already passed
94+
if service == nil {
95+
e.context.Log.Debug("Elastic APM Agent: No elastic-apm service found")
9596
}
97+
e.service = service
9698

9799
e.context.Log.BeginStep("Configuring Elastic APM agent")
98100

@@ -257,3 +259,17 @@ func (e *ElasticApmAgentFramework) getApplicationName() string {
257259

258260
return ""
259261
}
262+
263+
func (e *ElasticApmAgentFramework) constructJarPath(elasticDir string) error {
264+
// Find the installed JAR
265+
jarPattern := filepath.Join(elasticDir, "elastic-apm-agent*.jar")
266+
matches, err := filepath.Glob(jarPattern)
267+
if err != nil {
268+
return fmt.Errorf("failed to search for Elastic APM agent JAR: %w", err)
269+
}
270+
if len(matches) == 0 {
271+
return fmt.Errorf("agent jar not found after installation in %s", elasticDir)
272+
}
273+
e.jarPath = matches[0]
274+
return nil
275+
}

src/java/frameworks/google_stackdriver_profiler.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,23 @@ func (g *GoogleStackdriverProfilerFramework) Supply() error {
8383
return fmt.Errorf("failed to install Google Stackdriver Profiler: %w", err)
8484
}
8585

86-
// Find the installed agent (native library)
87-
agentPattern := filepath.Join(profilerDir, "profiler_java_agent.so")
88-
if _, err := os.Stat(agentPattern); err != nil {
89-
return fmt.Errorf("Google Stackdriver Profiler agent not found after installation: %w", err)
86+
// constructAgentPath can be skipped here and do it only in finalize, but it can be left as a double check
87+
// if jar path exists after the dependency install
88+
err = g.constructAgentPath(profilerDir)
89+
if err != nil {
90+
return fmt.Errorf("google stackdriver profiler agent not found during supply: %w", err)
9091
}
91-
g.agentPath = agentPattern
9292

9393
g.context.Log.Info("Google Stackdriver Profiler %s installed", dep.Version)
9494
return nil
9595
}
9696

9797
// Finalize configures the Google Stackdriver Profiler
9898
func (g *GoogleStackdriverProfilerFramework) Finalize() error {
99-
if g.agentPath == "" {
100-
return nil
99+
profilerDir := filepath.Join(g.context.Stager.DepDir(), "google_stackdriver_profiler")
100+
err := g.constructAgentPath(profilerDir)
101+
if err != nil {
102+
return fmt.Errorf("google stackdriver profiler agent not found during finalize: %w", err)
101103
}
102104

103105
g.context.Log.BeginStep("Configuring Google Stackdriver Profiler")
@@ -233,3 +235,13 @@ func (g *GoogleStackdriverProfilerFramework) getApplicationVersion() string {
233235

234236
return ""
235237
}
238+
239+
func (g *GoogleStackdriverProfilerFramework) constructAgentPath(profilerDir string) error {
240+
// Find the installed agent (native library)
241+
agentPattern := filepath.Join(profilerDir, "profiler_java_agent.so")
242+
if _, err := os.Stat(agentPattern); err != nil {
243+
return fmt.Errorf("agent not found after installation: %w", err)
244+
}
245+
g.agentPath = agentPattern
246+
return nil
247+
}

src/java/frameworks/introscope_agent.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,23 @@ func (i *IntroscopeAgentFramework) Supply() error {
6363
return fmt.Errorf("failed to install Introscope agent: %w", err)
6464
}
6565

66-
// Find the installed agent JAR
67-
agentPattern := filepath.Join(agentDir, "Agent.jar")
68-
if _, err := os.Stat(agentPattern); err != nil {
69-
return fmt.Errorf("Introscope Agent.jar not found after installation: %w", err)
66+
// constructAgentPath can be skipped here and do it only in finalize, but it can be left as a double check
67+
// if jar path exists after the dependency install
68+
err = i.constructAgentPath(agentDir)
69+
if err != nil {
70+
return fmt.Errorf("introscope Agent.jar not found during supply: %w", err)
7071
}
71-
i.agentPath = agentPattern
7272

7373
i.context.Log.Info("Introscope agent %s installed", dep.Version)
7474
return nil
7575
}
7676

7777
// Finalize configures the Introscope agent
7878
func (i *IntroscopeAgentFramework) Finalize() error {
79-
if i.agentPath == "" {
80-
return nil
79+
agentDir := filepath.Join(i.context.Stager.DepDir(), "introscope_agent")
80+
err := i.constructAgentPath(agentDir)
81+
if err != nil {
82+
return fmt.Errorf("introscope Agent.jar not found during finalize: %w", err)
8183
}
8284

8385
i.context.Log.BeginStep("Configuring Introscope agent")
@@ -241,3 +243,13 @@ func (i *IntroscopeAgentFramework) getApplicationName() string {
241243

242244
return ""
243245
}
246+
247+
func (i *IntroscopeAgentFramework) constructAgentPath(agentDir string) error {
248+
// Find the installed agent JAR
249+
agentPattern := filepath.Join(agentDir, "Agent.jar")
250+
if _, err := os.Stat(agentPattern); err != nil {
251+
return fmt.Errorf("agent jar not found after installation: %w", err)
252+
}
253+
i.agentPath = agentPattern
254+
return nil
255+
}

src/java/frameworks/maria_db_jdbc.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,23 @@ func (f *MariaDBJDBCFramework) Supply() error {
6767
return fmt.Errorf("failed to install MariaDB JDBC: %w", err)
6868
}
6969

70-
// Find the installed JAR
71-
jarPattern := filepath.Join(mariadbDir, "mariadb-jdbc-*.jar")
72-
matches, err := filepath.Glob(jarPattern)
70+
// constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check
71+
// if jar path exists after the dependency install
72+
err = f.constructJarPath(mariadbDir)
7373
if err != nil {
74-
return fmt.Errorf("failed to search for MariaDB JDBC JAR: %w", err)
75-
}
76-
if len(matches) == 0 {
77-
return fmt.Errorf("MariaDB JDBC JAR not found after installation in %s", mariadbDir)
74+
return fmt.Errorf("jdbc jar not found during supply: %w", err)
7875
}
79-
f.jarPath = matches[0]
8076

8177
f.context.Log.Info("MariaDB JDBC %s installed", dep.Version)
8278
return nil
8379
}
8480

8581
// Finalize adds the MariaDB JDBC driver to the classpath
8682
func (f *MariaDBJDBCFramework) Finalize() error {
87-
if f.jarPath == "" {
88-
// Not installed, skip
89-
return nil
83+
mariadbDir := filepath.Join(f.context.Stager.DepDir(), "mariadb_jdbc")
84+
err := f.constructJarPath(mariadbDir)
85+
if err != nil {
86+
return fmt.Errorf("jdbc jar not found during finalize: %w", err)
9087
}
9188

9289
f.context.Log.BeginStep("Configuring MariaDB JDBC driver")
@@ -192,3 +189,16 @@ func (f *MariaDBJDBCFramework) hasExistingDriver() bool {
192189

193190
return false
194191
}
192+
193+
func (f *MariaDBJDBCFramework) constructJarPath(mariadbDir string) error {
194+
jarPattern := filepath.Join(mariadbDir, "mariadb-jdbc-*.jar")
195+
matches, err := filepath.Glob(jarPattern)
196+
if err != nil {
197+
return fmt.Errorf("failed to search for MariaDB JDBC JAR: %w", err)
198+
}
199+
if len(matches) == 0 {
200+
return fmt.Errorf("jdbc jar not found after installation in %s", mariadbDir)
201+
}
202+
f.jarPath = matches[0]
203+
return nil
204+
}

src/java/frameworks/riverbed_appinternals_agent.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,23 @@ func (r *RiverbedAppInternalsAgentFramework) Supply() error {
6363
return fmt.Errorf("failed to install Riverbed AppInternals agent: %w", err)
6464
}
6565

66-
// Find the installed agent directory (contains lib/rvbd-agent.jar)
67-
agentJarPath := filepath.Join(agentDir, "lib", "rvbd-agent.jar")
68-
if _, err := os.Stat(agentJarPath); err != nil {
69-
return fmt.Errorf("Riverbed AppInternals agent JAR not found after installation: %w", err)
66+
// constructAgentJarPath can be skipped here and do it only in finalize, but it can be left as a double check
67+
// if jar path exists after the dependency install
68+
err = r.constructAgentJarPath(agentDir)
69+
if err != nil {
70+
return fmt.Errorf("riverbed appinternals agent JAR not found during supply: %w", err)
7071
}
71-
r.agentPath = agentJarPath
7272

7373
r.context.Log.Info("Riverbed AppInternals agent %s installed", dep.Version)
7474
return nil
7575
}
7676

7777
// Finalize configures the Riverbed AppInternals agent
7878
func (r *RiverbedAppInternalsAgentFramework) Finalize() error {
79-
if r.agentPath == "" {
80-
return nil
79+
agentDir := filepath.Join(r.context.Stager.DepDir(), "riverbed_appinternals_agent")
80+
err := r.constructAgentJarPath(agentDir)
81+
if err != nil {
82+
return fmt.Errorf("riverbed appinternals agent JAR not found during finalize: %w", err)
8183
}
8284

8385
r.context.Log.BeginStep("Configuring Riverbed AppInternals agent")
@@ -214,3 +216,13 @@ func (r *RiverbedAppInternalsAgentFramework) getApplicationName() string {
214216

215217
return ""
216218
}
219+
220+
func (r *RiverbedAppInternalsAgentFramework) constructAgentJarPath(agentDir string) error {
221+
// Find the installed agent directory (contains lib/rvbd-agent.jar)
222+
agentJarPath := filepath.Join(agentDir, "lib", "rvbd-agent.jar")
223+
if _, err := os.Stat(agentJarPath); err != nil {
224+
return fmt.Errorf("agent jar not found after installation: %w", err)
225+
}
226+
r.agentPath = agentJarPath
227+
return nil
228+
}

0 commit comments

Comments
 (0)