"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.IntVar(&logFrequencySeconds,
+ 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())
}
var arvLogger *logger.Logger
- if logEventType != "" {
+ if logEventTypePrefix != "" {
arvLogger = logger.NewLogger(logger.LoggerParams{Client: arv,
- EventType: logEventType,
- MinimumWriteInterval: time.Second * time.Duration(logFrequencySeconds)})
+ EventTypePrefix: logEventTypePrefix,
+ WriteInterval: time.Second * time.Duration(logFrequencySeconds)})
}
+ loggerutil.LogRunInfo(arvLogger)
if arvLogger != nil {
- properties, _ := arvLogger.Edit()
- runInfo := make(map[string]interface{})
- runInfo["start_time"] = time.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()
- properties["run_info"] = runInfo
-
- arvLogger.AddWriteHook(LogMemoryAlloc)
-
- arvLogger.Record()
+ arvLogger.AddWriteHook(loggerutil.LogMemoryAlloc)
}
collectionChannel := make(chan collection.ReadCollections)
- go func() { collectionChannel <- collection.GetCollectionsAndSummarize(
- collection.GetCollectionsParams{
- Client: arv, Logger: arvLogger, BatchSize: 50}) }()
+ go func() {
+ collectionChannel <- collection.GetCollectionsAndSummarize(
+ collection.GetCollectionsParams{
+ Client: arv, Logger: arvLogger, BatchSize: 50})
+ }()
- RunKeep(keep.GetKeepServersParams{Client: arv, Limit: 1000})
+ keepServerInfo := keep.GetKeepServersAndSummarize(
+ keep.GetKeepServersParams{Client: arv, Logger: arvLogger, Limit: 1000})
readCollections := <-collectionChannel
- _ = readCollections // Make compiler happy.
- // Log that we're finished
- if arvLogger != nil {
- properties,_ := arvLogger.Edit()
- properties["run_info"].(map[string]interface{})["end_time"] = time.Now()
- // Force the recording, since go will not wait for the timer before exiting.
- arvLogger.ForceRecord()
- }
-}
-
-func RunKeep(params keep.GetKeepServersParams) {
- readServers := keep.GetKeepServers(params)
+ // TODO(misha): Use these together to verify replication.
+ _ = readCollections
+ _ = keepServerInfo
- log.Printf("Returned %d keep disks", len(readServers.ServerToContents))
-
- blockReplicationCounts := make(map[int]int)
- for _, infos := range readServers.BlockToServers {
- replication := len(infos)
- blockReplicationCounts[replication] += 1
+ // Log that we're finished. We force the recording, since go will
+ // 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{})["finished_at"] = time.Now()
+ })
}
-
- log.Printf("Replication level distribution: %v", blockReplicationCounts)
-}
-
-func LogMemoryAlloc(properties map[string]interface{}, entry map[string]interface{}) {
- _ = entry // keep the compiler from complaining
- runInfo := properties["run_info"].(map[string]interface{})
- var memStats runtime.MemStats
- runtime.ReadMemStats(&memStats)
- runInfo["alloc_bytes_in_use"] = memStats.Alloc
}