@@ -10,9 +10,9 @@ import (
1010 "time"
1111
1212 "github.com/noderax/noderax-agent/internal/api"
13- "github.com/noderax/noderax-agent/internal/cloudmetadata"
1413 "github.com/noderax/noderax-agent/internal/config"
1514 "github.com/noderax/noderax-agent/internal/metrics"
15+ "github.com/noderax/noderax-agent/internal/nodelocation"
1616 "github.com/noderax/noderax-agent/internal/realtime"
1717 "github.com/noderax/noderax-agent/internal/rootaccess"
1818 "github.com/noderax/noderax-agent/internal/system"
@@ -159,7 +159,7 @@ func NewService(cfg config.Config, client *api.Client, logger *slog.Logger, vers
159159 }
160160 if realtimeService != nil {
161161 realtimeService .SetRuntimeAgentVersion (version )
162- setRealtimeCloudLocation (context .Background (), logger , realtimeService , false )
162+ setRealtimeNodeLocation (context .Background (), cfg , logger , realtimeService , false )
163163 hostInfo , hostInfoErr := system .HostInfo (context .Background ())
164164 if hostInfoErr != nil {
165165 logger .Warn ("failed to read host metadata for realtime auth" , "error" , hostInfoErr )
@@ -210,7 +210,7 @@ func (s *Service) Run(ctx context.Context) error {
210210 name string
211211 run func (context.Context ) error
212212 }{
213- {name : "cloud-metadata " , run : s .runCloudMetadataSync },
213+ {name : "node-location " , run : s .runNodeLocationSync },
214214 {name : "realtime" , run : s .realtime .Run },
215215 {name : "metrics" , run : s .metrics .Run },
216216 {name : "tasks" , run : s .tasks .Run },
@@ -246,7 +246,7 @@ func (s *Service) Run(ctx context.Context) error {
246246 }
247247}
248248
249- func (s * Service ) runCloudMetadataSync (ctx context.Context ) error {
249+ func (s * Service ) runNodeLocationSync (ctx context.Context ) error {
250250 if s .realtime == nil || s .realtime .RuntimeLocation () != nil {
251251 return nil
252252 }
@@ -267,24 +267,25 @@ func (s *Service) runCloudMetadataSync(ctx context.Context) error {
267267 case <- timer .C :
268268 }
269269
270- if setRealtimeCloudLocation (ctx , s .logger , s .realtime , true ) {
270+ if setRealtimeNodeLocation (ctx , s . cfg , s .logger , s .realtime , true ) {
271271 return nil
272272 }
273273 }
274274
275275 return nil
276276}
277277
278- func setRealtimeCloudLocation (
278+ func setRealtimeNodeLocation (
279279 ctx context.Context ,
280+ cfg config.Config ,
280281 logger * slog.Logger ,
281282 realtimeService * realtime.Service ,
282283 refreshAuth bool ,
283284) bool {
284- location , err := cloudmetadata .Detect (ctx )
285+ location , err := nodelocation .Detect (ctx , cfg )
285286 if err != nil {
286287 if logger != nil {
287- logger .Debug ("cloud metadata location detection skipped" , "error" , err )
288+ logger .Debug ("node location detection skipped" , "error" , err )
288289 }
289290 return false
290291 }
@@ -295,8 +296,9 @@ func setRealtimeCloudLocation(
295296 realtimeService .SetRuntimeLocation (location )
296297 if logger != nil {
297298 logger .Info (
298- "cloud metadata location detected" ,
299+ "node location detected" ,
299300 "provider" , location .Provider ,
301+ "source" , location .Source ,
300302 "region" , location .Region ,
301303 "zone" , location .Zone ,
302304 )
@@ -305,7 +307,7 @@ func setRealtimeCloudLocation(
305307 refreshCtx , cancel := context .WithTimeout (ctx , 10 * time .Second )
306308 defer cancel ()
307309 if err := realtimeService .RefreshAuth (refreshCtx ); err != nil && ! errors .Is (err , realtime .ErrSessionNotActive ) && logger != nil {
308- logger .Debug ("cloud metadata realtime auth refresh skipped" , "error" , err )
310+ logger .Debug ("node location realtime auth refresh skipped" , "error" , err )
309311 }
310312 }
311313 return true
0 commit comments