Documentation ¶
Index ¶
- Constants
- Variables
- type FilterBuilder
- func (fb FilterBuilder) Build() string
- func (fb FilterBuilder) WithCluster(cluster string) FilterBuilder
- func (fb FilterBuilder) WithContainer() FilterBuilder
- func (fb FilterBuilder) WithLocation(location string) FilterBuilder
- func (fb FilterBuilder) WithMetricType(metricType string) FilterBuilder
- func (fb FilterBuilder) WithNamespace(namespace string) FilterBuilder
- func (fb FilterBuilder) WithNodes(nodes []string) FilterBuilder
- func (fb FilterBuilder) WithPods(pods []string) FilterBuilder
- func (fb FilterBuilder) WithProject(project string) FilterBuilder
- type Schema
Constants ¶
const ( PodSchemaKey = "pod" // PodSchemaKey is the key to use pod type filter schema. ContainerSchemaKey = "container" // ContainerSchemaKey is the key to use container type filter schema. PrometheusSchemaKey = "prometheus" // PrometheusSchemaKey is the key to use prometheus type filter schema. NodeSchemaKey = "node" // NodeSchemaKey is the key to use node type filter schema LegacySchemaKey = "legacy" // LegacySchemaKey is the key to use legacy pod type filter schema. PodType = "k8s_pod" // PodType is the resource value for pod type. (also used in the query) ContainerType = "k8s_container" // ContainerType is the resource value for container type. (also used in the query) NodeType = "k8s_node" // NodeType is the resource value for node type. (also used in the query) PrometheusType = "prometheus_target" // PrometheusType is the resource value for prometheus type. (also used in the query) LegacyType = "<not_allowed>" // LegacyType is the resource value for legacy type. (NOT used in the query) )
Variables ¶
var ( // PodSchema is the predefined schema for building pod type queries. PodSchema = &Schema{ resourceType: "resource.type", metricType: "metric.type", project: "resource.labels.project_id", cluster: "resource.labels.cluster_name", location: "resource.labels.location", namespace: "resource.labels.namespace_name", pods: "resource.labels.pod_name", } // ContainerSchema is the predefined schema for building container type queries, // and it uses the same schema as pod type. ContainerSchema = PodSchema // LegacyPodSchema is the predefined schema for building legacy pod type queries. LegacyPodSchema = &Schema{ resourceType: "", metricType: "metric.type", project: "resource.labels.project_id", cluster: "resource.labels.cluster_name", location: "resource.labels.location", namespace: "resource.labels.namespace_name", pods: "resource.labels.pod_id", } // NodeSchema is the predefined schema for building node type queries. NodeSchema = &Schema{ resourceType: "resource.type", metricType: "metric.type", project: "resource.labels.project_id", cluster: "resource.labels.cluster_name", location: "resource.labels.location", nodes: "resource.labels.node_name", } // PrometheusSchema is the predefined schema for building prometheus type queries. PrometheusSchema = &Schema{ resourceType: "resource.type", metricType: "metric.type", project: "resource.labels.project_id", cluster: "resource.labels.cluster", location: "resource.labels.location", namespace: "resource.labels.namespace", nodes: "metric.labels.node", pods: "metric.labels.pod", } // SchemaTypes is a collection of all FilterBuilder supported resource types for external uses. SchemaTypes = map[string]string{ PodSchemaKey: PodType, ContainerSchemaKey: ContainerType, PrometheusSchemaKey: PrometheusType, NodeSchemaKey: NodeType, LegacySchemaKey: LegacyType, } )
Functions ¶
This section is empty.
Types ¶
type FilterBuilder ¶
type FilterBuilder struct {
// contains filtered or unexported fields
}
FilterBuilder composes criteria into a string which can be used in TimeSeries queries.
func NewFilterBuilder ¶
func NewFilterBuilder(resourceType string) FilterBuilder
NewFilterBuilder is the initializer for FilterBuilder.
Parameter:
- resourceType defines the query schema to use
Example:
// To initialize with a filter "resource.type = \"k8s_pod\"" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey])
func (FilterBuilder) Build ¶
func (fb FilterBuilder) Build() string
Build is the last step for FilterBuilder
it combines all filter criteria with AND
func (FilterBuilder) WithCluster ¶
func (fb FilterBuilder) WithCluster(cluster string) FilterBuilder
WithCluster adds a filter for cluster name.
Example:
// To add "resource.labels.cluster_name = \"my-cluster\"" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey]).WithCluster("my-cluster")
func (FilterBuilder) WithContainer ¶
func (fb FilterBuilder) WithContainer() FilterBuilder
WithContainer adds a filter for container. (used ONLY in the legacy model)
Example:
// To add "resource.labels.container_name = \"my-container\"" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey]).WithContainer("my-container")
func (FilterBuilder) WithLocation ¶
func (fb FilterBuilder) WithLocation(location string) FilterBuilder
WithLocation adds a filter for location.
Example:
// To add "resource.labels.location = \"my-location\"" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey]).WithLocation("my-location")
func (FilterBuilder) WithMetricType ¶
func (fb FilterBuilder) WithMetricType(metricType string) FilterBuilder
WithMetricType adds a filter for metric type.
Example:
// To add "resource.type = \"custom.googleapis.com/foo\"" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey]).WithMetricType("custom.googleapis.com/foo")
func (FilterBuilder) WithNamespace ¶
func (fb FilterBuilder) WithNamespace(namespace string) FilterBuilder
WithNamespace adds a filter for namespace. (note: empty namespace will be ignored)
Example:
// To add "resource.labels.namespace_name = \"my-namepace\"" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey]).WithNamespace("my-namespace")
func (FilterBuilder) WithNodes ¶
func (fb FilterBuilder) WithNodes(nodes []string) FilterBuilder
WithNodes adds a filter for nodes.
Example:
// To filter for nodes gke-test--default-pool-cee13989-0i75 and // gke-test--default-pool-cee13989-qsky with the query // metric.labels.node = monitoring.regex.full_match("^" + // "(gke-test--default-pool-cee13989-0i75|gke-test--default-pool-cee13989-qsky)"+ // "$" // ) filterBuilder := NewFilterBuilder(SchemaTypes[NodeSchemaKey]).WithNodes([]string{ "gke-test--default-pool-cee13989-0i75", "gke-test--default-pool-cee13989-qsky", })
func (FilterBuilder) WithPods ¶
func (fb FilterBuilder) WithPods(pods []string) FilterBuilder
WithPods adds a filter for pods.
Number of pods should NOT be more than 100 according to "https://cloud.google.com/monitoring/api/v3/filters#comparisons"
Example:
To add "resource.labels.pod_name = my-pod" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey]).WithPods([]string{"my-pod"})
To add "resource.lables.pod_name = one_of(my-pod-1,my-pod-2)" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey]).WithPods([]string{"my-pod-1", "my-pod-2"})
func (FilterBuilder) WithProject ¶
func (fb FilterBuilder) WithProject(project string) FilterBuilder
WithProject adds a filter for project id.
Example:
// To add "resource.labels.project_id = \"my-project\"" filterBuilder := NewFilterBuilder(SchemaTypes[PodSchemaKey]).WithProject("my-project")