func getLogsWithFollow(c v1alpha.PublicAPIClient, p *v1alpha.Pod) { if len(p.Apps) == 0 { fmt.Printf("Pod %q has no apps\n", p.Id) return } logsResp, err := c.GetLogs(context.Background(), &v1alpha.GetLogsRequest{ PodId: p.Id, Follow: true, AppName: p.Apps[0].Name, }) if err != nil { fmt.Println(err) os.Exit(1) } for { logsRecvResp, err := logsResp.Recv() if err == io.EOF { return } if err != nil { fmt.Println(err) return } for _, l := range logsRecvResp.Lines { fmt.Println(l) } } }
func getLogsWithoutFollow(c v1alpha.PublicAPIClient, p *v1alpha.Pod) { if len(p.Apps) == 0 { fmt.Printf("Pod %q has no apps\n", p.Id) return } logsResp, err := c.GetLogs(context.Background(), &v1alpha.GetLogsRequest{ PodId: p.Id, Follow: false, AppName: p.Apps[0].Name, SinceTime: time.Now().Add(-time.Second * 5).Unix(), Lines: 10, }) if err != nil { fmt.Println(err) os.Exit(1) } logsRecvResp, err := logsResp.Recv() if err == io.EOF { return } if err != nil { fmt.Println(err) return } for _, l := range logsRecvResp.Lines { fmt.Println(l) } }
func benchListPods(b *testing.B, c v1alpha.PublicAPIClient, detail bool) { b.ResetTimer() for i := 0; i < b.N; i++ { _, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{Detail: detail}) if err != nil { b.Error(err) } } b.StopTimer() }
func benchInspectPod(b *testing.B, c v1alpha.PublicAPIClient) { resp, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{}) if err != nil { b.Fatalf("Unexpected error: %v", err) } b.ResetTimer() for i := 0; i < b.N; i++ { _, err := c.InspectPod(context.Background(), &v1alpha.InspectPodRequest{Id: resp.Pods[0].Id}) if err != nil { b.Error(err) } } b.StopTimer() }
func newRktContainerHandler(name string, rktClient rktapi.PublicAPIClient, rktPath string, cgroupSubsystems *libcontainer.CgroupSubsystems, machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, rootFs string, ignoreMetrics container.MetricSet) (container.ContainerHandler, error) { aliases := make([]string, 1) isPod := false apiPod := &rktapi.Pod{} parsed, err := parseName(name) if err != nil { return nil, fmt.Errorf("this should be impossible!, new handler failing, but factory allowed, name = %s", name) } //rktnetes uses containerID: rkt://fff40827-b994-4e3a-8f88-6427c2c8a5ac:nginx if parsed.Container == "" { isPod = true aliases = append(aliases, "rkt://"+parsed.Pod) } else { aliases = append(aliases, "rkt://"+parsed.Pod+":"+parsed.Container) } pid := os.Getpid() labels := make(map[string]string) resp, err := rktClient.InspectPod(context.Background(), &rktapi.InspectPodRequest{ Id: parsed.Pod, }) if err != nil { return nil, err } else { var annotations []*rktapi.KeyValue if parsed.Container == "" { pid = int(resp.Pod.Pid) apiPod = resp.Pod annotations = resp.Pod.Annotations } else { var ok bool if annotations, ok = findAnnotations(resp.Pod.Apps, parsed.Container); !ok { glog.Warningf("couldn't find application in Pod matching %v", parsed.Container) } } labels = createLabels(annotations) } cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name) // Generate the equivalent cgroup manager for this container. cgroupManager := &cgroupfs.Manager{ Cgroups: &configs.Cgroup{ Name: name, }, Paths: cgroupPaths, } hasNetwork := false if isPod { hasNetwork = true } rootfsStorageDir := getRootFs(rktPath, parsed) handler := &rktContainerHandler{ name: name, rktClient: rktClient, cgroupSubsystems: cgroupSubsystems, machineInfoFactory: machineInfoFactory, cgroupPaths: cgroupPaths, cgroupManager: cgroupManager, fsInfo: fsInfo, hasNetwork: hasNetwork, rootFs: rootFs, isPod: isPod, aliases: aliases, pid: pid, labels: labels, rootfsStorageDir: rootfsStorageDir, ignoreMetrics: ignoreMetrics, apiPod: apiPod, } if !ignoreMetrics.Has(container.DiskUsageMetrics) { handler.fsHandler = common.NewFsHandler(time.Minute, rootfsStorageDir, "", fsInfo) } return handler, nil }