本文整理汇总了Golang中github.com/cockroachdb/cockroach/build.GetInfo函数的典型用法代码示例。如果您正苦于以下问题:Golang GetInfo函数的具体用法?Golang GetInfo怎么用?Golang GetInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCheckVersion
func TestCheckVersion(t *testing.T) {
defer leaktest.AfterTest(t)()
updateChecks := int32(0)
uuid := ""
version := ""
recorder := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
atomic.AddInt32(&updateChecks, 1)
uuid = r.URL.Query().Get("uuid")
version = r.URL.Query().Get("version")
}))
s := StartTestServer(t)
s.parsedUpdatesURL, _ = url.Parse(recorder.URL)
s.checkForUpdates()
recorder.Close()
s.Stop()
if expected, actual := int32(1), atomic.LoadInt32(&updateChecks); actual != expected {
t.Fatalf("expected %v update checks, got %v", expected, actual)
}
if expected, actual := s.node.ClusterID.String(), uuid; expected != actual {
t.Errorf("expected uuid %v, got %v", expected, actual)
}
if expected, actual := build.GetInfo().Tag, version; expected != actual {
t.Errorf("expected version tag %v, got %v", expected, actual)
}
}
示例2: runGenManCmd
func runGenManCmd(cmd *cobra.Command, args []string) error {
info := build.GetInfo()
header := &doc.GenManHeader{
Section: "1",
Manual: "CockroachDB Manual",
Source: fmt.Sprintf("CockroachDB %s", info.Tag),
}
if !strings.HasSuffix(manPath, string(os.PathSeparator)) {
manPath += string(os.PathSeparator)
}
if _, err := os.Stat(manPath); err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(manPath, 0755); err != nil {
return err
}
} else {
return err
}
}
if err := doc.GenManTree(cmd.Root(), header, manPath); err != nil {
return err
}
// TODO(cdo): The man page generated by the cobra package doesn't include a list of commands, so
// one has to notice the "See Also" section at the bottom of the page to know which commands
// are supported. I'd like to make this better somehow.
fmt.Println("Generated CockroachDB man pages in", manPath)
return nil
}
示例3: reportUsage
func (s *Server) reportUsage() {
b := new(bytes.Buffer)
if err := json.NewEncoder(b).Encode(s.getReportingInfo()); err != nil {
log.Warning(context.TODO(), err)
return
}
q := reportingURL.Query()
q.Set("version", build.GetInfo().Tag)
q.Set("uuid", s.node.ClusterID.String())
reportingURL.RawQuery = q.Encode()
res, err := http.Post(reportingURL.String(), "application/json", b)
if err != nil && log.V(2) {
// This is probably going to be relatively common in production
// environments where network access is usually curtailed.
log.Warning(context.TODO(), "Failed to report node usage metrics: ", err)
return
}
if res.StatusCode != http.StatusOK {
b, err := ioutil.ReadAll(res.Body)
log.Warningf(context.TODO(), "Failed to report node usage metrics: status: %s, body: %s, "+
"error: %v", res.Status, b, err)
}
}
示例4: ClusterFreeze
func (s *adminServer) ClusterFreeze(
ctx context.Context, req *ClusterFreezeRequest,
) (*ClusterFreezeResponse, error) {
var resp ClusterFreezeResponse
stores := make(map[roachpb.StoreID]roachpb.NodeID)
process := func(from, to roachpb.Key) (roachpb.Key, error) {
b := &client.Batch{}
fa := roachpb.NewChangeFrozen(from, to, req.Freeze, build.GetInfo().Tag)
b.AddRawRequest(fa)
if err := s.server.db.Run(b); err != nil {
return nil, err
}
fr := b.RawResponse().Responses[0].GetInner().(*roachpb.ChangeFrozenResponse)
resp.RangesAffected += fr.RangesAffected
for storeID, nodeID := range fr.Stores {
stores[storeID] = nodeID
}
return fr.MinStartKey.AsRawKey(), nil
}
if req.Freeze {
// When freezing, we save the meta2 and meta1 range for last to avoid
// interfering with command routing.
// Note that we freeze only Ranges whose StartKey is included. In
// particular, a Range which contains some meta keys will not be frozen
// by the request that begins at Meta2KeyMax. ChangeFreeze gives us the
// leftmost covered Range back, which we use for the next request to
// avoid split-related races.
freezeTo := roachpb.KeyMax // updated as we go along
freezeFroms := []roachpb.Key{
keys.Meta2KeyMax, // freeze userspace
keys.Meta1KeyMax, // freeze all meta2 ranges
keys.LocalMax, // freeze first range (meta1)
}
for _, freezeFrom := range freezeFroms {
var err error
if freezeTo, err = process(freezeFrom, freezeTo); err != nil {
return nil, err
}
}
} else {
// When unfreezing, we walk in opposite order and try the first range
// first. We should be able to get there if the first range manages to
// gossip. From that, we can talk to the second level replicas, and
// then to everyone else. Because ChangeFrozen works in forward order,
// we can simply hit the whole keyspace at once.
// TODO(tschottdorf): make the first range replicas gossip their
// descriptor unconditionally or we won't always be able to unfreeze
// (except by restarting a node which holds the first range).
if _, err := process(keys.LocalMax, roachpb.KeyMax); err != nil {
return nil, err
}
}
return &resp, s.waitForStoreFrozen(stores, req.Freeze)
}
示例5: GetStatusSummary
// GetStatusSummary returns a status summary messages for the node. The summary
// includes the recent values of metrics for both the node and all of its
// component stores.
func (mr *MetricsRecorder) GetStatusSummary() *NodeStatus {
mr.mu.Lock()
defer mr.mu.Unlock()
if mr.mu.nodeRegistry == nil {
// We haven't yet processed initialization information; do nothing.
if log.V(1) {
log.Warning(context.TODO(), "MetricsRecorder.GetStatusSummary called before NodeID allocation.")
}
return nil
}
now := mr.mu.clock.PhysicalNow()
// Generate an node status with no store data.
nodeStat := &NodeStatus{
Desc: mr.mu.desc,
BuildInfo: build.GetInfo(),
UpdatedAt: now,
StartedAt: mr.mu.startedAt,
StoreStatuses: make([]StoreStatus, 0, mr.mu.lastSummaryCount),
Metrics: make(map[string]float64, mr.mu.lastNodeMetricCount),
}
eachRecordableValue(mr.mu.nodeRegistry, func(name string, val float64) {
nodeStat.Metrics[name] = val
})
// Generate status summaries for stores.
for storeID, r := range mr.mu.storeRegistries {
storeMetrics := make(map[string]float64, mr.mu.lastStoreMetricCount)
eachRecordableValue(r, func(name string, val float64) {
storeMetrics[name] = val
})
// Gather descriptor from store.
descriptor, err := mr.mu.stores[storeID].Descriptor()
if err != nil {
log.Errorf(context.TODO(), "Could not record status summaries: Store %d could not return descriptor, error: %s", storeID, err)
continue
}
nodeStat.StoreStatuses = append(nodeStat.StoreStatuses, StoreStatus{
Desc: *descriptor,
Metrics: storeMetrics,
})
}
mr.mu.lastSummaryCount = len(nodeStat.StoreStatuses)
mr.mu.lastNodeMetricCount = len(nodeStat.Metrics)
if len(nodeStat.StoreStatuses) > 0 {
mr.mu.lastStoreMetricCount = len(nodeStat.StoreStatuses[0].Metrics)
}
return nodeStat
}
示例6: TestStatusJson
// TestStatusJson verifies that status endpoints return expected Json results.
// The content type of the responses is always util.JSONContentType.
func TestStatusJson(t *testing.T) {
defer leaktest.AfterTest(t)()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
ts := s.(*TestServer)
nodeID := ts.Gossip().GetNodeID()
addr, err := ts.Gossip().GetNodeIDAddress(nodeID)
if err != nil {
t.Fatal(err)
}
var nodes serverpb.NodesResponse
util.SucceedsSoon(t, func() error {
if err := getRequestProto(t, s, statusNodesPrefix, &nodes); err != nil {
t.Fatal(err)
}
if len(nodes.Nodes) == 0 {
return errors.Errorf("expected non-empty node list, got: %v", nodes)
}
return nil
})
for _, path := range []string{
"/health",
"/_status/details/local",
"/_status/details/" + strconv.FormatUint(uint64(nodeID), 10),
} {
var details serverpb.DetailsResponse
if err := getRequestProto(t, s, path, &details); err != nil {
t.Fatal(err)
}
if a, e := details.NodeID, nodeID; a != e {
t.Errorf("expected: %d, got: %d", e, a)
}
if a, e := details.Address, *addr; a != e {
t.Errorf("expected: %v, got: %v", e, a)
}
if a, e := details.BuildInfo, build.GetInfo(); a != e {
t.Errorf("expected: %v, got: %v", e, a)
}
}
}
示例7: rotateFile
// rotateFile closes the syncBuffer's file and starts a new one.
func (sb *syncBuffer) rotateFile(now time.Time) error {
if sb.file != nil {
if err := sb.Flush(); err != nil {
return err
}
if err := sb.file.Close(); err != nil {
return err
}
}
var err error
sb.file, _, err = create(sb.sev, now)
sb.nbytes = 0
if err != nil {
return err
}
sb.Writer = bufio.NewWriterSize(sb.file, bufferSize)
f, l, _ := caller.Lookup(1)
for _, msg := range []string{
fmt.Sprintf("[config] file created at: %s\n", now.Format("2006/01/02 15:04:05")),
fmt.Sprintf("[config] running on machine: %s\n", host),
fmt.Sprintf("[config] binary: %s\n", build.GetInfo().Short()),
fmt.Sprintf("[config] arguments: %s\n", os.Args),
fmt.Sprintf("line format: [IWEF]yymmdd hh:mm:ss.uuuuuu goid file:line msg\n"),
} {
buf := formatLogEntry(Entry{
Severity: sb.sev,
Time: now.UnixNano(),
Goroutine: goid.Get(),
File: f,
Line: int64(l),
Message: msg,
}, nil, nil)
var n int
n, err = sb.file.Write(buf.Bytes())
sb.nbytes += uint64(n)
if err != nil {
return err
}
logging.putBuffer(buf)
}
return nil
}
示例8: Details
// Details returns node details.
func (s *statusServer) Details(ctx context.Context, req *serverpb.DetailsRequest) (*serverpb.DetailsResponse, error) {
nodeID, local, err := s.parseNodeID(req.NodeId)
if err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, err.Error())
}
if local {
resp := &serverpb.DetailsResponse{
NodeID: s.gossip.GetNodeID(),
BuildInfo: build.GetInfo(),
}
if addr, err := s.gossip.GetNodeIDAddress(s.gossip.GetNodeID()); err == nil {
resp.Address = *addr
}
return resp, nil
}
status, err := s.dialNode(nodeID)
if err != nil {
return nil, err
}
return status.Details(ctx, req)
}
示例9: checkForUpdates
func (s *Server) checkForUpdates() {
q := updatesURL.Query()
q.Set("version", build.GetInfo().Tag)
q.Set("uuid", s.node.ClusterID.String())
updatesURL.RawQuery = q.Encode()
res, err := http.Get(updatesURL.String())
if err != nil {
// This is probably going to be relatively common in production
// environments where network access is usually curtailed.
if log.V(2) {
log.Warning(context.TODO(), "Failed to check for updates: ", err)
}
return
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
b, err := ioutil.ReadAll(res.Body)
log.Warningf(context.TODO(), "Failed to check for updates: status: %s, body: %s, error: %v",
res.Status, b, err)
return
}
decoder := json.NewDecoder(res.Body)
r := struct {
Details []versionInfo `json:"details"`
}{}
err = decoder.Decode(&r)
if err != nil && err != io.EOF {
log.Warning(context.TODO(), "Error decoding updates info: ", err)
return
}
for _, v := range r.Details {
log.Infof(context.TODO(), "A new version is available: %s, details: %s", v.Version, v.Details)
}
}
示例10: checkForUpdates
func (s *Server) checkForUpdates() {
// Don't phone home in tests (SetupReportingURLs is called in cli/start.go).
if s.parsedUpdatesURL == nil {
return
}
q := s.parsedUpdatesURL.Query()
q.Set("version", build.GetInfo().Tag)
q.Set("uuid", s.node.ClusterID.String())
s.parsedUpdatesURL.RawQuery = q.Encode()
res, err := http.Get(s.parsedUpdatesURL.String())
if err != nil {
// This is probably going to be relatively common in production
// environments where network access is usually curtailed.
if log.V(2) {
log.Warning("Error checking for updates: ", err)
}
return
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
r := struct {
Details []versionInfo `json:"details"`
}{}
err = decoder.Decode(&r)
if err != nil && err != io.EOF {
log.Warning("Error decoding updates info: ", err)
return
}
for _, v := range r.Details {
log.Infof("A new version is available: %s, details: %s", v.Version, v.Details)
}
}
示例11: MakeRuntimeStatSampler
// MakeRuntimeStatSampler constructs a new RuntimeStatSampler object.
func MakeRuntimeStatSampler(clock *hlc.Clock) RuntimeStatSampler {
// Construct the build info metric. It is constant.
// We first build set the labels on the metadata.
info := build.GetInfo()
timestamp, err := info.Timestamp()
if err != nil {
// We can't panic here, tests don't have a build timestamp.
log.Warningf(context.TODO(), "Could not parse build timestamp: %v", err)
}
metaBuildTimestamp.AddLabel("tag", info.Tag)
metaBuildTimestamp.AddLabel("go_version", info.GoVersion)
buildTimestamp := metric.NewGauge(metaBuildTimestamp)
buildTimestamp.Update(timestamp)
return RuntimeStatSampler{
clock: clock,
startTimeNanos: clock.PhysicalNow(),
CgoCalls: metric.NewGauge(metaCgoCalls),
Goroutines: metric.NewGauge(metaGoroutines),
GoAllocBytes: metric.NewGauge(metaGoAllocBytes),
GoTotalBytes: metric.NewGauge(metaGoTotalBytes),
CgoAllocBytes: metric.NewGauge(metaCgoAllocBytes),
CgoTotalBytes: metric.NewGauge(metaCgoTotalBytes),
GcCount: metric.NewGauge(metaGCCount),
GcPauseNS: metric.NewGauge(metaGCPauseNS),
GcPausePercent: metric.NewGaugeFloat64(metaGCPausePercent),
CPUUserNS: metric.NewGauge(metaCPUUserNS),
CPUUserPercent: metric.NewGaugeFloat64(metaCPUUserPercent),
CPUSysNS: metric.NewGauge(metaCPUSysNS),
CPUSysPercent: metric.NewGaugeFloat64(metaCPUSysPercent),
Rss: metric.NewGauge(metaRSS),
Uptime: metric.NewGauge(metaUptime),
BuildTimestamp: buildTimestamp,
}
}
示例12: reportUsage
func (s *Server) reportUsage() {
// Don't phone home in tests (SetupReportingURLs is called in cli/start.go).
if s.parsedReportingURL == nil {
return
}
b := new(bytes.Buffer)
if err := json.NewEncoder(b).Encode(s.getReportingInfo()); err != nil {
log.Warning(err)
return
}
q := s.parsedReportingURL.Query()
q.Set("version", build.GetInfo().Tag)
q.Set("uuid", s.node.ClusterID.String())
s.parsedReportingURL.RawQuery = q.Encode()
_, err := http.Post(s.parsedReportingURL.String(), "application/json", b)
if err != nil && log.V(2) {
// This is probably going to be relatively common in production
// environments where network access is usually curtailed.
log.Warning("Error checking reporting node usage metrics: ", err)
}
}
示例13: TestMetricsRecorder
//.........这里部分代码省略.........
// all stores in our tests have identical values; when comparing
// status summaries, the same map is used as expected data for all
// stores.
expectedStoreSummaryMetrics[prefix+name] = float64(val)
}
}
for _, reg := range regList {
for _, data := range metricNames {
switch data.typ {
case "gauge":
reg.reg.Gauge(data.name).Update(data.val)
addExpected(reg.prefix, data.name, reg.source, 100, data.val, reg.isNode)
case "floatgauge":
reg.reg.GaugeFloat64(data.name).Update(float64(data.val))
addExpected(reg.prefix, data.name, reg.source, 100, data.val, reg.isNode)
case "counter":
reg.reg.Counter(data.name).Inc(data.val)
addExpected(reg.prefix, data.name, reg.source, 100, data.val, reg.isNode)
case "rate":
reg.reg.Rates(data.name).Add(data.val)
addExpected(reg.prefix, data.name+"-count", reg.source, 100, data.val, reg.isNode)
for _, scale := range metric.DefaultTimeScales {
// Rate data is subject to timing errors in tests. Zero out
// these values.
addExpected(reg.prefix, data.name+sep+scale.Name(), reg.source, 100, 0, reg.isNode)
}
case "histogram":
reg.reg.Histogram(data.name, time.Second, 1000, 2).RecordValue(data.val)
for _, q := range recordHistogramQuantiles {
addExpected(reg.prefix, data.name+q.suffix, reg.source, 100, data.val, reg.isNode)
}
case "latency":
reg.reg.Latency(data.name).RecordValue(data.val)
// Latency is simply three histograms (at different resolution
// time scales).
for _, scale := range metric.DefaultTimeScales {
for _, q := range recordHistogramQuantiles {
addExpected(reg.prefix, data.name+sep+scale.Name()+q.suffix, reg.source, 100, data.val, reg.isNode)
}
}
}
}
}
// ========================================
// Verify time series data
// ========================================
actual := recorder.GetTimeSeriesData()
// Zero-out timing-sensitive rate values from actual data.
for _, act := range actual {
match, err := regexp.MatchString(`testRate-\d+m`, act.Name)
if err != nil {
t.Fatal(err)
}
if match {
act.Datapoints[0].Value = 0.0
}
}
// Actual comparison is simple: sort the resulting arrays by time and name,
// and use reflect.DeepEqual.
sort.Sort(byTimeAndName(actual))
sort.Sort(byTimeAndName(expected))
if a, e := actual, expected; !reflect.DeepEqual(a, e) {
t.Errorf("recorder did not yield expected time series collection; diff:\n %v", pretty.Diff(e, a))
}
// ========================================
// Verify node summary generation
// ========================================
expectedNodeSummary := &NodeStatus{
Desc: nodeDesc,
BuildInfo: build.GetInfo(),
StartedAt: 50,
UpdatedAt: 100,
Metrics: expectedNodeSummaryMetrics,
StoreStatuses: []StoreStatus{
{
Desc: storeDesc1,
Metrics: expectedStoreSummaryMetrics,
},
{
Desc: storeDesc2,
Metrics: expectedStoreSummaryMetrics,
},
},
}
nodeSummary := recorder.GetStatusSummary()
if nodeSummary == nil {
t.Fatalf("recorder did not return nodeSummary.")
}
sort.Sort(byStoreDescID(nodeSummary.StoreStatuses))
if a, e := nodeSummary, expectedNodeSummary; !reflect.DeepEqual(a, e) {
t.Errorf("recorder did not produce expected NodeSummary; diff:\n %v", pretty.Diff(e, a))
}
}
示例14:
"github.com/spf13/cobra"
)
// Proxy to allow overrides in tests.
var osStderr = os.Stderr
var versionIncludesDeps bool
var versionCmd = &cobra.Command{
Use: "version",
Short: "output version information",
Long: `
Output build version information.
`,
Run: func(cmd *cobra.Command, args []string) {
info := build.GetInfo()
tw := tabwriter.NewWriter(os.Stdout, 2, 1, 2, ' ', 0)
fmt.Fprintf(tw, "Build Tag: %s\n", info.Tag)
fmt.Fprintf(tw, "Build Time: %s\n", info.Time)
fmt.Fprintf(tw, "Platform: %s\n", info.Platform)
fmt.Fprintf(tw, "Go Version: %s\n", info.GoVersion)
fmt.Fprintf(tw, "C Compiler: %s\n", info.CgoCompiler)
if versionIncludesDeps {
fmt.Fprintf(tw, "Build Deps:\n\t%s\n",
strings.Replace(strings.Replace(info.Dependencies, " ", "\n\t", -1), ":", "\t", -1))
}
_ = tw.Flush()
},
}
var cockroachCmd = &cobra.Command{
示例15: checkNodeStatus
func checkNodeStatus(t *testing.T, c cliTest, output string, start time.Time) {
buf := bytes.NewBufferString(output)
s := bufio.NewScanner(buf)
// Skip command line.
if !s.Scan() {
t.Fatalf("Couldn't skip command line: %s", s.Err())
}
checkSeparatorLine(t, s)
// check column names.
if !s.Scan() {
t.Fatalf("Error reading column names: %s", s.Err())
}
cols, err := extractFields(s.Text())
if err != nil {
t.Fatalf("%s", err)
}
if !reflect.DeepEqual(cols, nodesColumnHeaders) {
t.Fatalf("columns (%s) don't match expected (%s)", cols, nodesColumnHeaders)
}
checkSeparatorLine(t, s)
// Check node status.
if !s.Scan() {
t.Fatalf("error reading node status: %s", s.Err())
}
fields, err := extractFields(s.Text())
if err != nil {
t.Fatalf("%s", err)
}
nodeID := c.Gossip().GetNodeID()
nodeIDStr := strconv.FormatInt(int64(nodeID), 10)
if a, e := fields[0], nodeIDStr; a != e {
t.Errorf("node id (%s) != expected (%s)", a, e)
}
nodeAddr, err := c.Gossip().GetNodeIDAddress(nodeID)
if err != nil {
t.Fatal(err)
}
if a, e := fields[1], nodeAddr.String(); a != e {
t.Errorf("node address (%s) != expected (%s)", a, e)
}
// Verify Build Tag.
if a, e := fields[2], build.GetInfo().Tag; a != e {
t.Errorf("build tag (%s) != expected (%s)", a, e)
}
// Verify that updated_at and started_at are reasonably recent.
// CircleCI can be very slow. This was flaky at 5s.
checkTimeElapsed(t, fields[3], 15*time.Second, start)
checkTimeElapsed(t, fields[4], 15*time.Second, start)
// Verify all byte/range metrics.
testcases := []struct {
name string
idx int
maxval int64
}{
{"live_bytes", 5, 30000},
{"key_bytes", 6, 30000},
{"value_bytes", 7, 30000},
{"intent_bytes", 8, 30000},
{"system_bytes", 9, 30000},
{"leader_ranges", 10, 3},
{"repl_ranges", 11, 3},
{"avail_ranges", 12, 3},
}
for _, tc := range testcases {
val, err := strconv.ParseInt(fields[tc.idx], 10, 64)
if err != nil {
t.Errorf("couldn't parse %s '%s': %v", tc.name, fields[tc.idx], err)
continue
}
if val < 0 {
t.Errorf("value for %s (%d) cannot be less than 0", tc.name, val)
continue
}
if val > tc.maxval {
t.Errorf("value for %s (%d) greater than max (%d)", tc.name, val, tc.maxval)
}
}
checkSeparatorLine(t, s)
}