stackdriver

package
v0.0.0-...-50fdf0b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2018 License: Apache-2.0 Imports: 38 Imported by: 1

Documentation

Overview

Copyright 2018 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2018 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2018 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2017 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	ProjectIdLabel   = "_stackdriver_project_id"
	LocationLabel    = "_kubernetes_location"
	ClusterNameLabel = "_kubernetes_cluster_name"
)
View Source
const (
	MonitoringWriteScope = "https://www.googleapis.com/auth/monitoring.write"
)

Variables

View Source
var DefaultResourceMappings = []ResourceMap{
	{

		Type: "gke_container",
		LabelMap: map[string]string{
			ProjectIdLabel:                   "project_id",
			LocationLabel:                    "zone",
			ClusterNameLabel:                 "cluster_name",
			"_kubernetes_namespace":          "namespace_id",
			"_kubernetes_pod_name":           "pod_id",
			"_kubernetes_pod_node_name":      "instance_id",
			"_kubernetes_pod_container_name": "container_name",
		},
	},
}

TODO(jkohen): ensure these are sorted from more specific to less specific.

View Source
var (
	DefaultStackdriverConfig = StackdriverConfig{
		K8sResourceTypes: false,
		MetricPrefix:     "external.googleapis.com/prometheus",
	}
)
View Source
var K8sResourceMappings = []ResourceMap{
	{
		Type: "k8s_container",
		LabelMap: map[string]string{
			ProjectIdLabel:                         "project_id",
			LocationLabel:                          "location",
			ClusterNameLabel:                       "cluster_name",
			"__meta_kubernetes_namespace":          "namespace_name",
			"__meta_kubernetes_pod_name":           "pod_name",
			"__meta_kubernetes_pod_container_name": "container_name",
		},
	},
	{
		Type: "k8s_pod",
		LabelMap: map[string]string{
			ProjectIdLabel:                "project_id",
			LocationLabel:                 "location",
			ClusterNameLabel:              "cluster_name",
			"__meta_kubernetes_namespace": "namespace_name",
			"__meta_kubernetes_pod_name":  "pod_name",
		},
	},
	{
		Type: "k8s_node",
		LabelMap: map[string]string{
			ProjectIdLabel:                "project_id",
			LocationLabel:                 "location",
			ClusterNameLabel:              "cluster_name",
			"__meta_kubernetes_node_name": "node_name",
		},
	},
	{
		Type: "k8s_cluster",
		LabelMap: map[string]string{
			ProjectIdLabel:   "project_id",
			LocationLabel:    "location",
			ClusterNameLabel: "cluster_name",
		},
	},
}

TODO(jkohen): ensure these are sorted from more specific to less specific.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client allows reading and writing from/to a remote gRPC endpoint. The implementation may hit a single backend, so the application should create a number of these clients.

func NewClient

func NewClient(index int, conf *ClientConfig) *Client

NewClient creates a new Client.

func (Client) Close

func (c Client) Close() error

func (Client) Name

func (c Client) Name() string

Name identifies the client.

func (*Client) Store

Store sends a batch of samples to the HTTP endpoint.

type ClientConfig

type ClientConfig struct {
	Logger      log.Logger
	ProjectId   string // The Stackdriver project id in "projects/name-or-number" format.
	ClusterName string
	Location    string
	URL         *config_util.URL
	Timeout     model.Duration
}

ClientConfig configures a Client.

type QueueManager

type QueueManager struct {
	// contains filtered or unexported fields
}

QueueManager manages a queue of samples to be sent to the Storage indicated by the provided StorageClient.

func NewQueueManager

func NewQueueManager(logger log.Logger, cfg config.QueueConfig, externalLabelSet model.LabelSet, relabelConfigs []*config.RelabelConfig, clientFactory StorageClientFactory, sdCfg *StackdriverConfig) *QueueManager

NewQueueManager builds a new QueueManager.

func (*QueueManager) Append

func (t *QueueManager) Append(metricFamily *retrieval.MetricFamily) error

Append queues a sample to be sent to the remote storage. It drops the sample on the floor if the queue is full. Always returns nil.

func (*QueueManager) Start

func (t *QueueManager) Start()

Start the queue manager sending samples to the remote storage. Does not block.

func (*QueueManager) Stop

func (t *QueueManager) Stop()

Stop stops sending samples to the remote storage and waits for pending sends to complete.

type ResourceMap

type ResourceMap struct {
	// The name of the Stackdriver MonitoredResource.
	Type string
	// Mapping from Prometheus to Stackdriver labels
	LabelMap map[string]string
}

func (*ResourceMap) Translate

func (m *ResourceMap) Translate(targetLabels labels.Labels, labels []*dto.LabelPair) map[string]string

type StackdriverConfig

type StackdriverConfig struct {
	// Whether to export Stackdriver k8s_* resource types or gke_container. The former require joining an early-access program.
	K8sResourceTypes bool

	// Prefix for all metrics.
	MetricPrefix string
}

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage(logger log.Logger, cfg *StackdriverConfig) *Storage

func (*Storage) Add

func (s *Storage) Add(metricFamily *retrieval.MetricFamily) error

Add implements the retrieval.Appender interface.

func (*Storage) Appender

func (s *Storage) Appender() (retrieval.Appender, error)

Appender implements the retrieval.Appendable interface.

func (*Storage) ApplyConfig

func (s *Storage) ApplyConfig(conf *config.Config) error

ApplyConfig updates the state as the new config requires.

func (*Storage) Close

func (s *Storage) Close() error

Close closes the storage and all its underlying resources.

type StorageClient

type StorageClient interface {
	// Store stores the given metric families in the remote storage.
	Store(*monitoring.CreateTimeSeriesRequest) error
	// Name identifies the remote storage implementation.
	Name() string
	// Release the resources allocated by the client.
	Close() error
}

StorageClient defines an interface for sending a batch of samples to an external timeseries database.

type StorageClientFactory

type StorageClientFactory interface {
	New() StorageClient
	Name() string
}

type Translator

type Translator struct {
	// contains filtered or unexported fields
}

Translator allows converting Prometheus samples to Stackdriver TimeSeries.

func NewTranslator

func NewTranslator(logger log.Logger, metricsPrefix string, resourceMappings []ResourceMap) *Translator

NewTranslator creates a new Translator.

func (*Translator) ToCreateTimeSeriesRequest

func (t *Translator) ToCreateTimeSeriesRequest(
	metrics []*retrieval.MetricFamily) *monitoring_pb.CreateTimeSeriesRequest

ToCreateTimeSeriesRequest translates metrics in Prometheus format to Stackdriver format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL