@@ -22,14 +22,25 @@ const (
2222 LocalPrometheusURL = "http://localhost:3000/explore?panes=%7B%22qZw%22:%7B%22datasource%22:%22PBFA97CFB590B2093%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22expr%22:%22%22,%22range%22:true,%22datasource%22:%7B%22type%22:%22prometheus%22,%22uid%22:%22PBFA97CFB590B2093%22%7D%7D%5D,%22range%22:%7B%22from%22:%22now-15m%22,%22to%22:%22now%22%7D%7D%7D&schemaVersion=1&orgId=1"
2323 LocalPostgresDebugURL = "http://localhost:3000/d/000000039/postgresql-database?orgId=1&refresh=5s&var-DS_PROMETHEUS=PBFA97CFB590B2093&var-interval=$__auto_interval_interval&var-namespace=&var-release=&var-instance=postgres_exporter_0:9187&var-datname=All&var-mode=All&from=now-15m&to=now"
2424 LocalPyroScopeURL = "http://localhost:4040/?query=process_cpu%3Acpu%3Ananoseconds%3Acpu%3Ananoseconds%7Bservice_name%3D%22chainlink-node%22%7D&from=now-15m"
25+
26+ CTFCacheDir = ".local/share/ctf"
2527)
2628
27- // extractAllFiles goes through the embedded directory and extracts all files to the current directory
29+ // getObservabilityDir returns the fixed directory where observability files are extracted
30+ func getObservabilityDir () (string , error ) {
31+ homeDir , err := os .UserHomeDir ()
32+ if err != nil {
33+ return "" , fmt .Errorf ("failed to get home directory: %w" , err )
34+ }
35+ return filepath .Join (homeDir , CTFCacheDir ), nil
36+ }
37+
38+ // extractAllFiles goes through the embedded directory and extracts all files to the fixed observability directory
2839func extractAllFiles (embeddedDir string ) error {
29- // Get current working directory where CLI is running
30- currentDir , err := os . Getwd ()
40+ // Get fixed observability directory
41+ obsDir , err := getObservabilityDir ()
3142 if err != nil {
32- return fmt . Errorf ( "failed to get current directory: %w" , err )
43+ return err
3344 }
3445
3546 // Walk through the embedded files
@@ -47,7 +58,7 @@ func extractAllFiles(embeddedDir string) error {
4758 }
4859
4960 // Read file content from embedded file system
50- content , err := EmbeddedObservabilityFiles .ReadFile (path )
61+ content , err := fs .ReadFile (EmbeddedObservabilityFiles , path )
5162 if err != nil {
5263 return fmt .Errorf ("failed to read file %s: %w" , path , err )
5364 }
@@ -57,7 +68,7 @@ func extractAllFiles(embeddedDir string) error {
5768 if err != nil {
5869 return fmt .Errorf ("failed to determine relative path for %s: %w" , path , err )
5970 }
60- targetPath := filepath .Join (currentDir , relativePath )
71+ targetPath := filepath .Join (obsDir , relativePath )
6172
6273 // Create target directories if necessary
6374 targetDir := filepath .Dir (targetPath )
@@ -83,8 +94,13 @@ func BlockScoutUp(url, chainID string) error {
8394 if err := extractAllFiles ("observability" ); err != nil {
8495 return err
8596 }
97+ obsDir , err := getObservabilityDir ()
98+ if err != nil {
99+ return err
100+ }
101+ blockscoutDir := filepath .Join (obsDir , "blockscout" )
86102 os .Setenv ("BLOCKSCOUT_RPC_URL" , url )
87- os .Setenv ("BLOCKSCOUT_CHAID_ID " , chainID )
103+ os .Setenv ("BLOCKSCOUT_CHAIN_ID " , chainID )
88104 // old migrations for v15 is still applied somehow, cleaning up DB helps
89105 if err := RunCommand ("bash" , "-c" , fmt .Sprintf (`
90106 cd %s && \
@@ -93,13 +109,13 @@ func BlockScoutUp(url, chainID string) error {
93109 rm -rf redis-data && \
94110 rm -rf stats-db-data && \
95111 rm -rf dets
96- ` , filepath .Join ("blockscout" , "services" ))); err != nil {
112+ ` , filepath .Join (blockscoutDir , "services" ))); err != nil {
97113 return err
98114 }
99- err : = RunCommand ("bash" , "-c" , fmt .Sprintf (`
115+ err = RunCommand ("bash" , "-c" , fmt .Sprintf (`
100116 cd %s && \
101117 docker compose up -d
102- ` , "blockscout" ))
118+ ` , blockscoutDir ))
103119 if err != nil {
104120 return err
105121 }
@@ -110,15 +126,16 @@ func BlockScoutUp(url, chainID string) error {
110126
111127func BlockScoutDown (url string ) error {
112128 L .Info ().Msg ("Removing local Blockscout stack" )
113- os .Setenv ("BLOCKSCOUT_RPC_URL" , url )
114- err := RunCommand ("bash" , "-c" , fmt .Sprintf (`
115- cd %s && \
116- docker compose down -v
117- ` , "blockscout" ))
129+ obsDir , err := getObservabilityDir ()
118130 if err != nil {
119131 return err
120132 }
121- return RunCommand ("bash" , "-c" , "rm -rf blockscout/" )
133+ blockscoutDir := filepath .Join (obsDir , "blockscout" )
134+ os .Setenv ("BLOCKSCOUT_RPC_URL" , url )
135+ return RunCommand ("bash" , "-c" , fmt .Sprintf (`
136+ cd %s && \
137+ docker compose down -v
138+ ` , blockscoutDir ))
122139}
123140
124141// ObservabilityUpOnlyLoki slim stack with only Loki to verify specific logs of CL nodes or services in tests
@@ -127,14 +144,19 @@ func ObservabilityUpOnlyLoki() error {
127144 if err := extractAllFiles ("observability" ); err != nil {
128145 return err
129146 }
147+ obsDir , err := getObservabilityDir ()
148+ if err != nil {
149+ return err
150+ }
151+ composeDir := filepath .Join (obsDir , "compose" )
130152 _ = DefaultNetwork (nil )
131153 if err := NewPromtail (); err != nil {
132154 return err
133155 }
134- err : = RunCommand ("bash" , "-c" , fmt .Sprintf (`
156+ err = RunCommand ("bash" , "-c" , fmt .Sprintf (`
135157 cd %s && \
136158 docker compose up -d loki grafana
137- ` , "compose" ))
159+ ` , composeDir ))
138160 if err != nil {
139161 return err
140162 }
@@ -149,14 +171,19 @@ func ObservabilityUp() error {
149171 if err := extractAllFiles ("observability" ); err != nil {
150172 return err
151173 }
174+ obsDir , err := getObservabilityDir ()
175+ if err != nil {
176+ return err
177+ }
178+ composeDir := filepath .Join (obsDir , "compose" )
152179 _ = DefaultNetwork (nil )
153180 if err := NewPromtail (); err != nil {
154181 return err
155182 }
156- err : = RunCommand ("bash" , "-c" , fmt .Sprintf (`
183+ err = RunCommand ("bash" , "-c" , fmt .Sprintf (`
157184 cd %s && \
158185 docker compose up -d otel-collector prometheus loki grafana
159- ` , "compose" ))
186+ ` , composeDir ))
160187 if err != nil {
161188 return err
162189 }
@@ -174,14 +201,19 @@ func ObservabilityUpFull() error {
174201 if err := extractAllFiles ("observability" ); err != nil {
175202 return err
176203 }
204+ obsDir , err := getObservabilityDir ()
205+ if err != nil {
206+ return err
207+ }
208+ composeDir := filepath .Join (obsDir , "compose" )
177209 _ = DefaultNetwork (nil )
178210 if err := NewPromtail (); err != nil {
179211 return err
180212 }
181- err : = RunCommand ("bash" , "-c" , fmt .Sprintf (`
213+ err = RunCommand ("bash" , "-c" , fmt .Sprintf (`
182214 cd %s && \
183215 docker compose up -d
184- ` , "compose" ))
216+ ` , composeDir ))
185217 if err != nil {
186218 return err
187219 }
@@ -197,10 +229,14 @@ func ObservabilityUpFull() error {
197229
198230func ObservabilityDown () error {
199231 L .Info ().Msg ("Removing local observability stack" )
232+ obsDir , err := getObservabilityDir ()
233+ if err != nil {
234+ return err
235+ }
236+ composeDir := filepath .Join (obsDir , "compose" )
200237 _ = RunCommand ("bash" , "-c" , fmt .Sprintf (`
201238 cd %s && \
202239 docker compose down -v && docker rm -f promtail
203- ` , "compose" ))
204- _ = RunCommand ("bash" , "-c" , "rm -rf compose/" )
240+ ` , composeDir ))
205241 return nil
206242}
0 commit comments