func (c *Client) reportCumulativeCount(ctx context.Context, metricType, imageName string, success bool) error {
	reset := &timestamp.Timestamp{
		Seconds: c.resetTs.Unix(),
	}
	if time.Now().Sub(c.resetTs).Seconds() < 1 {
		time.Sleep(time.Second * 2)
	}
	now := &timestamp.Timestamp{
		Seconds: time.Now().Unix(),
	}
	req := &monitoringpb.CreateTimeSeriesRequest{
		Name: "projects/" + c.projectID,
		TimeSeries: []*monitoringpb.TimeSeries{{
			Metric: &metric.Metric{
				Type: metricType,
				Labels: map[string]string{
					"docker_image": imageName,
					"success":      fmt.Sprintf("%v", success),
				},
			},
			Resource: &monitoredres.MonitoredResource{
				Type: "generic_task",
				Labels: map[string]string{
					"project_id": c.projectID,
					"job":        "monitoring",
					"location":  "us-central1",
					"namespace": "monitoring",
					"task_id":   "monitoring",
				},
			},
			Points: []*monitoringpb.Point{{
				Interval: &monitoringpb.TimeInterval{
					StartTime: reset,
					EndTime:   now,
				},
				Value: &monitoringpb.TypedValue{
					Value: &monitoringpb.TypedValue_Int64Value{
						Int64Value: int64(1),
					},
				},
			}},
		}},
	}
	if err := c.mc.CreateTimeSeries(ctx, req); err != nil {
		return fmt.Errorf("unable to report time series to Google Cloud Monitoring: %w", err)
	}
	return nil
}
reportCumulativeCount reports the given metric type which is expected to be of kind
cumulative (https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors#metrickind)
adding "1" to the cumulative count. Other arguments:
imageName: The toolchain container image for which the metric is being reported.
success: Indicates if the workflow was successful.
package monitoring
import (
	"context"
	"fmt"
	"time"
	monitoring "cloud.google.com/go/monitoring/apiv3"
	"github.com/golang/protobuf/ptypes/timestamp"
	gax "github.com/googleapis/gax-go/v2"
	"google.golang.org/genproto/googleapis/api/label"
	"google.golang.org/genproto/googleapis/api/metric"
	"google.golang.org/genproto/googleapis/api/monitoredres"
	monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
)
const (
	mtypeToolchainConfigsGenRuns = "custom.googleapis.com/rbe/bazel-toolchains/generation/runs"
	mtypeToolchainConfigsUploadRuns = "custom.googleapis.com/rbe/bazel-toolchains/upload/runs"
	mtypeToolchainConfigsTestRuns = "custom.googleapis.com/rbe/bazel-toolchains/test/runs"
)
type metricClient interface {
	CreateMetricDescriptor(ctx context.Context, req *monitoringpb.CreateMetricDescriptorRequest, opts ...gax.CallOption) (*metric.MetricDescriptor, error)
	DeleteMetricDescriptor(ctx context.Context, req *monitoringpb.DeleteMetricDescriptorRequest, opts ...gax.CallOption) error
	CreateTimeSeries(ctx context.Context, req *monitoringpb.CreateTimeSeriesRequest, opts ...gax.CallOption) error
}
type Client struct {
	mc metricClient
	projectID string
	resetTs   time.Time
}
func NewClient(ctx context.Context, projectID string) (*Client, error) {
	if len(projectID) == 0 {
		return nil, fmt.Errorf("GCP project ID was not specified")
	}
	mc, err := monitoring.NewMetricClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("unable to initialize the Google Cloud Monitoring Metrics Client: %w", err)
	}
	c := &Client{
		mc:        mc,
		projectID: projectID,
		resetTs:   time.Now(),
	}
	if err := c.createMetrics(ctx); err != nil {
		return nil, fmt.Errorf("error initializing Google Cloud Monitoring Metrics Descriptors: %w", err)
	}
	return c, nil
}
func (c *Client) createMetrics(ctx context.Context) error {
	if err := c.createToolchainConfigsMetrics(ctx); err != nil {
		return fmt.Errorf("unable to initialize the toolchain config runs metric: %w", err)
	}
	return nil
}
func (c *Client) createToolchainConfigsMetrics(ctx context.Context) error {
	metrics := []struct {
		name        string
		metricType  string
		description string
	}{
		{
			name:        "RBE Toolchain Configs Generation",
			metricType:  mtypeToolchainConfigsGenRuns,
			description: "Count number of times RBE Bazel C++/Java toolchain config generation completed",
		},
		{
			name:        "RBE Toolchain Configs Upload",
			metricType:  mtypeToolchainConfigsUploadRuns,
			description: "Count number of times RBE Bazel C++/Java toolchain config upload completed",
		},
		{
			name:        "RBE Toolchain Configs E2E Test",
			metricType:  mtypeToolchainConfigsTestRuns,
			description: "Count number of times RBE Bazel C++/Java toolchain config e2e test completed",
		},
	}
	for _, m := range metrics {
		md := &metric.MetricDescriptor{
			Name: m.name,
			Type: m.metricType,
			Labels: []*label.LabelDescriptor{
				{
					Key:         "docker_image",
					ValueType:   label.LabelDescriptor_STRING,
					Description: "Name of the OS of the toolchain container image",
				},
				{
					Key:         "success",
					ValueType:   label.LabelDescriptor_BOOL,
					Description: "Indicates of configs generation, upload & testing was successful",
				},
			},
			MetricKind:  metric.MetricDescriptor_CUMULATIVE,
			ValueType:   metric.MetricDescriptor_INT64,
			Unit:        "1",
			Description: m.description,
			DisplayName: m.name,
		}
		req := &monitoringpb.CreateMetricDescriptorRequest{
			Name:             "projects/" + c.projectID,
			MetricDescriptor: md,
		}
		if _, err := c.mc.CreateMetricDescriptor(ctx, req); err != nil {
			return fmt.Errorf("unable to create Google Cloud Monitoring Metric for %s: %v", m.name, err)
		}
	}
	return nil
}