// NewMetricsClient creates a new metrics service client.
//
// Service for configuring logs-based metrics.
func NewMetricsClient(ctx context.Context, opts ...option.ClientOption) (*MetricsClient, error) {
	conn, err := transport.DialGRPC(ctx, append(defaultMetricsClientOptions(), opts...)...)
	if err != nil {
		return nil, err
	}
	c := &MetricsClient{
		conn:        conn,
		client:      loggingpb.NewMetricsServiceV2Client(conn),
		CallOptions: defaultMetricsCallOptions(),
	}
	c.SetGoogleClientInfo("gax", gax.Version)
	return c, nil
}
Beispiel #2
0
func (it *MetricIterator) fetch(pageSize int, pageToken string) (string, error) {
	// TODO(jba): Do this a nicer way if the generated code supports one.
	// TODO(jba): If the above TODO can't be done, find a way to pass metadata in the call.
	client := logpb.NewMetricsServiceV2Client(it.client.Connection())
	var res *logpb.ListLogMetricsResponse
	err := gax.Invoke(it.ctx, func(ctx context.Context) error {
		it.req.PageSize = trunc32(pageSize)
		it.req.PageToken = pageToken
		var err error
		res, err = client.ListLogMetrics(ctx, it.req)
		return err
	}, it.client.CallOptions.ListLogMetrics...)
	if err != nil {
		return "", err
	}
	for _, sp := range res.Metrics {
		it.items = append(it.items, fromLogMetric(sp))
	}
	return res.NextPageToken, nil
}