X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3a1face2e3bc02e1fb9c53a2268095811b2e069d..a4211acb465bd42869bf2a2f9fad6ff2c5e518e0:/services/datamanager/datamanager.go diff --git a/services/datamanager/datamanager.go b/services/datamanager/datamanager.go index f63f4628a0..a8e506eacb 100644 --- a/services/datamanager/datamanager.go +++ b/services/datamanager/datamanager.go @@ -9,31 +9,48 @@ import ( "git.curoverse.com/arvados.git/sdk/go/util" "git.curoverse.com/arvados.git/services/datamanager/collection" "git.curoverse.com/arvados.git/services/datamanager/keep" + "git.curoverse.com/arvados.git/services/datamanager/loggerutil" "log" - "os" - "runtime" "time" ) var ( - logEventType string + logEventTypePrefix string logFrequencySeconds int + minutesBetweenRuns int ) func init() { - flag.StringVar(&logEventType, - "log-event-type", - "experimental-data-manager-report", - "event_type to use in our arvados log entries. Set to empty to turn off logging") + flag.StringVar(&logEventTypePrefix, + "log-event-type-prefix", + "experimental-data-manager", + "Prefix to use in the event_type of our arvados log entries. Set to empty to turn off logging") flag.IntVar(&logFrequencySeconds, "log-frequency-seconds", 20, "How frequently we'll write log entries in seconds.") + flag.IntVar(&minutesBetweenRuns, + "minutes-between-runs", + 0, + "How many minutes we wait betwen data manager runs. 0 means run once and exit.") } func main() { flag.Parse() + if minutesBetweenRuns == 0 { + singlerun() + } else { + waitTime := time.Minute * time.Duration(minutesBetweenRuns) + for { + log.Println("Beginning Run") + singlerun() + log.Printf("Sleeping for %d minutes", minutesBetweenRuns) + time.Sleep(waitTime) + } + } +} +func singlerun() { arv, err := arvadosclient.MakeArvadosClient() if err != nil { log.Fatalf("Error setting up arvados client %s", err.Error()) @@ -46,29 +63,15 @@ func main() { } var arvLogger *logger.Logger - if logEventType != "" { + if logEventTypePrefix != "" { arvLogger = logger.NewLogger(logger.LoggerParams{Client: arv, - EventType: logEventType, - WriteInterval: time.Second * time.Duration(logFrequencySeconds)}) + EventTypePrefix: logEventTypePrefix, + WriteInterval: time.Second * time.Duration(logFrequencySeconds)}) } + loggerutil.LogRunInfo(arvLogger) if arvLogger != nil { - now := time.Now() - arvLogger.Update(func(p map[string]interface{}, e map[string]interface{}) { - runInfo := make(map[string]interface{}) - runInfo["time_started"] = now - runInfo["args"] = os.Args - hostname, err := os.Hostname() - if err != nil { - runInfo["hostname_error"] = err.Error() - } else { - runInfo["hostname"] = hostname - } - runInfo["pid"] = os.Getpid() - p["run_info"] = runInfo - }) - - arvLogger.AddWriteHook(LogMemoryAlloc) + arvLogger.AddWriteHook(loggerutil.LogMemoryAlloc) } collectionChannel := make(chan collection.ReadCollections) @@ -92,15 +95,7 @@ func main() { // not wait for the timer before exiting. if arvLogger != nil { arvLogger.FinalUpdate(func(p map[string]interface{}, e map[string]interface{}) { - p["run_info"].(map[string]interface{})["time_finished"] = time.Now() + p["run_info"].(map[string]interface{})["finished_at"] = time.Now() }) } } - -// TODO(misha): Consider moving this to loggerutil -func LogMemoryAlloc(properties map[string]interface{}, entry map[string]interface{}) { - runInfo := properties["run_info"].(map[string]interface{}) - var memStats runtime.MemStats - runtime.ReadMemStats(&memStats) - runInfo["alloc_bytes_in_use"] = memStats.Alloc -}