github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cli/demo_telemetry.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package cli
    12  
    13  import (
    14  	"fmt"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/server/telemetry"
    17  )
    18  
    19  // demoTelemetry corresponds to different sources of telemetry we are recording from cockroach demo.
    20  type demoTelemetry int
    21  
    22  const (
    23  	_ demoTelemetry = iota
    24  	// demo represents when cockroach demo is used at all.
    25  	demo
    26  	// nodes represents when cockroach demo is started with multiple nodes.
    27  	nodes
    28  	// demoLocality represents when cockroach demo is started with user defined localities.
    29  	demoLocality
    30  	// withLoad represents when cockroach demo is used with a background workload
    31  	withLoad
    32  	// geoPartitionedReplicas is used when cockroach demo is started with the geo-partitioned-replicas topology.
    33  	geoPartitionedReplicas
    34  )
    35  
    36  var demoTelemetryMap = map[demoTelemetry]string{
    37  	demo:                   "demo",
    38  	nodes:                  "nodes",
    39  	demoLocality:           "demo-locality",
    40  	withLoad:               "withload",
    41  	geoPartitionedReplicas: "geo-partitioned-replicas",
    42  }
    43  
    44  var demoTelemetryCounters map[demoTelemetry]telemetry.Counter
    45  
    46  func init() {
    47  	demoTelemetryCounters = make(map[demoTelemetry]telemetry.Counter)
    48  	for ty, s := range demoTelemetryMap {
    49  		demoTelemetryCounters[ty] = telemetry.GetCounterOnce(fmt.Sprintf("cli.demo.%s", s))
    50  	}
    51  }
    52  
    53  func incrementDemoCounter(d demoTelemetry) {
    54  	telemetry.Inc(demoTelemetryCounters[d])
    55  }