repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
events/sinks/influxdb/influxdb.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/events/sinks/influxdb/influxdb.go#L61-L68
go
train
// Generate point value for event
func getEventValue(event *kube_api.Event) (string, error)
// Generate point value for event func getEventValue(event *kube_api.Event) (string, error)
{ // TODO: check whether indenting is required. bytes, err := json.MarshalIndent(event, "", " ") if err != nil { return "", err } return string(bytes), nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
events/sinks/influxdb/influxdb.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/events/sinks/influxdb/influxdb.go#L230-L239
go
train
// Returns a thread-safe implementation of core.EventSink for InfluxDB.
func newSink(c influxdb_common.InfluxdbConfig) core.EventSink
// Returns a thread-safe implementation of core.EventSink for InfluxDB. func newSink(c influxdb_common.InfluxdbConfig) core.EventSink
{ client, err := influxdb_common.NewClient(c) if err != nil { glog.Errorf("issues while creating an InfluxDB sink: %v, will retry on use", err) } return &influxdbSink{ client: client, // can be nil c: c, } }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
common/elasticsearch/aws.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/elasticsearch/aws.go#L29-L31
go
train
// RoundTrip implementation
func (a AWSSigningTransport) RoundTrip(req *http.Request) (*http.Response, error)
// RoundTrip implementation func (a AWSSigningTransport) RoundTrip(req *http.Request) (*http.Response, error)
{ return a.HTTPClient.Do(awsauth.Sign4(req, a.Credentials)) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/opentsdb/driver.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/opentsdb/driver.go#L106-L113
go
train
// Converts the given OpenTSDB metric or tag name/value to a form that is // accepted by OpenTSDB. As the OpenTSDB documentation states: // 'Metric names, tag names and tag values have to be made of alpha numeric // characters, dash "-", underscore "_", period ".", and forward slash "/".'
func toValidOpenTsdbName(name string) (validName string)
// Converts the given OpenTSDB metric or tag name/value to a form that is // accepted by OpenTSDB. As the OpenTSDB documentation states: // 'Metric names, tag names and tag values have to be made of alpha numeric // characters, dash "-", underscore "_", period ".", and forward slash "/".' func toValidOpenTsdbName(name ...
{ // This takes care of some cases where dash "-" characters were // encoded as '\\x2d' in received Timeseries Points validName = fmt.Sprintf("%s", name) // replace all illegal characters with '_' return disallowedCharsRegexp.ReplaceAllLiteralString(validName, "_") }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/opentsdb/driver.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/opentsdb/driver.go#L117-L146
go
train
// timeSeriesToPoint transfers the contents holding in the given pointer of sink_api.Timeseries // into the instance of opentsdbclient.DataPoint
func (tsdbSink *openTSDBSink) metricToPoint(name string, value core.MetricValue, timestamp time.Time, labels map[string]string) opentsdbclient.DataPoint
// timeSeriesToPoint transfers the contents holding in the given pointer of sink_api.Timeseries // into the instance of opentsdbclient.DataPoint func (tsdbSink *openTSDBSink) metricToPoint(name string, value core.MetricValue, timestamp time.Time, labels map[string]string) opentsdbclient.DataPoint
{ seriesName := strings.Replace(toValidOpenTsdbName(name), "/", "_", -1) if value.MetricType.String() != "" { seriesName = fmt.Sprintf("%s_%s", seriesName, value.MetricType.String()) } datapoint := opentsdbclient.DataPoint{ Metric: seriesName, Tags: make(map[string]string, len(labels)), Timestamp...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/opentsdb/driver.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/opentsdb/driver.go#L151-L153
go
train
// putDefaultTags just fills in the default key-value pair for the tags. // OpenTSDB requires at least one non-empty tag otherwise the OpenTSDB will return error and the operation of putting // datapoint will be failed.
func (tsdbSink *openTSDBSink) putDefaultTags(datapoint *opentsdbclient.DataPoint)
// putDefaultTags just fills in the default key-value pair for the tags. // OpenTSDB requires at least one non-empty tag otherwise the OpenTSDB will return error and the operation of putting // datapoint will be failed. func (tsdbSink *openTSDBSink) putDefaultTags(datapoint *opentsdbclient.DataPoint)
{ datapoint.Tags[clusterNameTagName] = tsdbSink.clusterName }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/api.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/api.go#L42-L72
go
train
// Create a new Api to serve from the specified cache.
func NewApi(runningInKubernetes bool, metricSink *metricsink.MetricSink, historicalSource core.HistoricalSource, disableMetricExport bool) *Api
// Create a new Api to serve from the specified cache. func NewApi(runningInKubernetes bool, metricSink *metricsink.MetricSink, historicalSource core.HistoricalSource, disableMetricExport bool) *Api
{ gkeMetrics := make(map[string]core.MetricDescriptor) gkeLabels := make(map[string]core.LabelDescriptor) for _, val := range core.StandardMetrics { gkeMetrics[val.Name] = val.MetricDescriptor } for _, val := range core.LabeledMetrics { gkeMetrics[val.Name] = val.MetricDescriptor } gkeMetrics[core.MetricCpu...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/api.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/api.go#L75-L104
go
train
// Register the mainApi on the specified endpoint.
func (a *Api) Register(container *restful.Container)
// Register the mainApi on the specified endpoint. func (a *Api) Register(container *restful.Container)
{ ws := new(restful.WebService) ws.Path("/api/v1/metric-export"). Doc("Exports the latest point for all Heapster metrics"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(a.exportMetrics). Doc("export the latest data point for all metrics"). Operation("exportMetrics"). Writes([]*types.Timeseries{})...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/hawkular/driver.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/driver.go#L54-L70
go
train
// START: ExternalSink interface implementations
func (h *hawkularSink) Register(mds []core.MetricDescriptor) error
// START: ExternalSink interface implementations func (h *hawkularSink) Register(mds []core.MetricDescriptor) error
{ // Create model definitions based on the MetricDescriptors for _, md := range mds { hmd := h.descriptorToDefinition(&md) h.models[md.Name] = &hmd } if !h.disablePreCaching { // Fetch currently known metrics from Hawkular-Metrics and cache them err := h.cacheDefinitions() if err != nil { return err ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/hawkular/driver.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/driver.go#L178-L193
go
train
// NewHawkularSink Creates and returns a new hawkularSink instance
func NewHawkularSink(u *url.URL) (core.DataSink, error)
// NewHawkularSink Creates and returns a new hawkularSink instance func NewHawkularSink(u *url.URL) (core.DataSink, error)
{ sink := &hawkularSink{ uri: u, batchSize: 1000, } if err := sink.init(); err != nil { return nil, err } metrics := make([]core.MetricDescriptor, 0, len(core.AllMetrics)) for _, metric := range core.AllMetrics { metrics = append(metrics, metric.MetricDescriptor) } sink.Register(metrics) return...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
common/elasticsearch/elasticsearch.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/elasticsearch/elasticsearch.go#L54-L122
go
train
// SaveDataIntoES save metrics and events to ES by using ES client
func (esSvc *ElasticSearchService) SaveData(date time.Time, typeName string, sinkData []interface{}) error
// SaveDataIntoES save metrics and events to ES by using ES client func (esSvc *ElasticSearchService) SaveData(date time.Time, typeName string, sinkData []interface{}) error
{ if typeName == "" || len(sinkData) == 0 { return nil } indexName := esSvc.Index(date) // Use the IndexExists service to check if a specified index exists. exists, err := esSvc.EsClient.IndexExists(indexName) if err != nil { return err } if !exists { // Create a new index. createIndex, err := esSvc...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
common/elasticsearch/elasticsearch.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/elasticsearch/elasticsearch.go#L126-L252
go
train
// CreateElasticSearchConfig creates an ElasticSearch configuration struct // which contains an ElasticSearch client for later use
func CreateElasticSearchService(uri *url.URL) (*ElasticSearchService, error)
// CreateElasticSearchConfig creates an ElasticSearch configuration struct // which contains an ElasticSearch client for later use func CreateElasticSearchService(uri *url.URL) (*ElasticSearchService, error)
{ var esSvc ElasticSearchService opts, err := url.ParseQuery(uri.RawQuery) if err != nil { return nil, fmt.Errorf("Failed to parse url's query string: %s", err) } version := 5 if len(opts["ver"]) > 0 { version, err = strconv.Atoi(opts["ver"][0]) if err != nil { return nil, fmt.Errorf("Failed to parse ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb.go#L294-L304
go
train
// Returns a thread-compatible implementation of influxdb interactions.
func newSink(c influxdb_common.InfluxdbConfig) core.DataSink
// Returns a thread-compatible implementation of influxdb interactions. func newSink(c influxdb_common.InfluxdbConfig) core.DataSink
{ client, err := influxdb_common.NewClient(c) if err != nil { glog.Errorf("issues while creating an InfluxDB sink: %v, will retry on use", err) } return &influxdbSink{ client: client, // can be nil c: c, conChan: make(chan struct{}, c.Concurrency), } }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
integration/framework.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/integration/framework.go#L402-L413
go
train
// Parses and Returns a RBAC object contained in 'filePath'
func (self *realKubeFramework) ParseRBAC(filePath string) (*rbacv1.ClusterRoleBinding, error)
// Parses and Returns a RBAC object contained in 'filePath' func (self *realKubeFramework) ParseRBAC(filePath string) (*rbacv1.ClusterRoleBinding, error)
{ obj, err := self.loadRBACObject(filePath) if err != nil { return nil, err } rbac, ok := obj.(*rbacv1.ClusterRoleBinding) if !ok { return nil, fmt.Errorf("Failed to cast clusterrolebinding: %v", obj) } return rbac, nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
integration/framework.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/integration/framework.go#L416-L419
go
train
// CreateRBAC creates the RBAC object
func (self *realKubeFramework) CreateRBAC(rbac *rbacv1.ClusterRoleBinding) error
// CreateRBAC creates the RBAC object func (self *realKubeFramework) CreateRBAC(rbac *rbacv1.ClusterRoleBinding) error
{ _, err := self.kubeClient.RbacV1().ClusterRoleBindings().Create(rbac) return err }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
integration/framework.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/integration/framework.go#L422-L433
go
train
// Parses and Returns a ServiceAccount object contained in 'filePath'
func (self *realKubeFramework) ParseServiceAccount(filePath string) (*v1.ServiceAccount, error)
// Parses and Returns a ServiceAccount object contained in 'filePath' func (self *realKubeFramework) ParseServiceAccount(filePath string) (*v1.ServiceAccount, error)
{ obj, err := self.loadObject(filePath) if err != nil { return nil, err } sa, ok := obj.(*v1.ServiceAccount) if !ok { return nil, fmt.Errorf("Failed to cast serviceaccount: %v", obj) } return sa, nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
integration/framework.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/integration/framework.go#L436-L439
go
train
// CreateServiceAccount creates the ServiceAccount object
func (self *realKubeFramework) CreateServiceAccount(sa *v1.ServiceAccount) error
// CreateServiceAccount creates the ServiceAccount object func (self *realKubeFramework) CreateServiceAccount(sa *v1.ServiceAccount) error
{ _, err := self.kubeClient.CoreV1().ServiceAccounts(sa.Namespace).Create(sa) return err }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
common/honeycomb/honeycomb.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/honeycomb/honeycomb.go#L108-L130
go
train
// SendBatch splits the top-level batch into sub-batches if needed. Otherwise, // requests that are too large will be rejected by the Honeycomb API.
func (c *HoneycombClient) SendBatch(batch Batch) error
// SendBatch splits the top-level batch into sub-batches if needed. Otherwise, // requests that are too large will be rejected by the Honeycomb API. func (c *HoneycombClient) SendBatch(batch Batch) error
{ if len(batch) == 0 { // Nothing to send return nil } errs := []string{} for i := 0; i < len(batch); i += maxBatchSize { offset := i + maxBatchSize if offset > len(batch) { offset = len(batch) } if err := c.sendBatch(batch[i:offset]); err != nil { errs = append(errs, err.Error()) } } if le...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/storage/nodemetrics/reststorage.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/storage/nodemetrics/reststorage.go#L75-L99
go
train
// Lister interface
func (m *MetricStorage) List(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (runtime.Object, error)
// Lister interface func (m *MetricStorage) List(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (runtime.Object, error)
{ labelSelector := labels.Everything() if options != nil && options.LabelSelector != nil { labelSelector = options.LabelSelector } nodes, err := m.nodeLister.ListWithPredicate(func(node *v1.Node) bool { if labelSelector.Empty() { return true } return labelSelector.Matches(labels.Set(node.Labels)) }) i...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/storage/nodemetrics/reststorage.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/storage/nodemetrics/reststorage.go#L102-L109
go
train
// Getter interface
func (m *MetricStorage) Get(ctx genericapirequest.Context, name string, opts *metav1.GetOptions) (runtime.Object, error)
// Getter interface func (m *MetricStorage) Get(ctx genericapirequest.Context, name string, opts *metav1.GetOptions) (runtime.Object, error)
{ // TODO: pay attention to get options nodeMetrics := m.getNodeMetrics(name) if nodeMetrics == nil { return &metrics.NodeMetrics{}, errors.NewNotFound(m.groupResource, name) } return nodeMetrics, nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L50-L74
go
train
// checkSanitizedKey errors out if invalid characters are found in the key, since InfluxDB does not widely // support bound parameters yet (see https://github.com/influxdata/influxdb/pull/6634) and we need to // sanitize our inputs.
func (sink *influxdbSink) checkSanitizedKey(key *core.HistoricalKey) error
// checkSanitizedKey errors out if invalid characters are found in the key, since InfluxDB does not widely // support bound parameters yet (see https://github.com/influxdata/influxdb/pull/6634) and we need to // sanitize our inputs. func (sink *influxdbSink) checkSanitizedKey(key *core.HistoricalKey) error
{ if key.NodeName != "" && !nameAllowedChars.MatchString(key.NodeName) { return fmt.Errorf("Invalid node name %q", key.NodeName) } if key.NamespaceName != "" && !nameAllowedChars.MatchString(key.NamespaceName) { return fmt.Errorf("Invalid namespace name %q", key.NamespaceName) } if key.PodName != "" && !nam...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L78-L84
go
train
// checkSanitizedMetricName errors out if invalid characters are found in the metric name, since InfluxDB // does not widely support bound parameters yet, and we need to sanitize our inputs.
func (sink *influxdbSink) checkSanitizedMetricName(name string) error
// checkSanitizedMetricName errors out if invalid characters are found in the metric name, since InfluxDB // does not widely support bound parameters yet, and we need to sanitize our inputs. func (sink *influxdbSink) checkSanitizedMetricName(name string) error
{ if !metricAllowedChars.MatchString(name) { return fmt.Errorf("Invalid metric name %q", name) } return nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L88-L110
go
train
// checkSanitizedMetricLabels errors out if invalid characters are found in the label name or label value, since // InfluxDb does not widely support bound parameters yet, and we need to sanitize our inputs.
func (sink *influxdbSink) checkSanitizedMetricLabels(labels map[string]string) error
// checkSanitizedMetricLabels errors out if invalid characters are found in the label name or label value, since // InfluxDb does not widely support bound parameters yet, and we need to sanitize our inputs. func (sink *influxdbSink) checkSanitizedMetricLabels(labels map[string]string) error
{ // label names have the same restrictions as metric names, here for k, v := range labels { if !metricAllowedChars.MatchString(k) { return fmt.Errorf("Invalid label name %q", k) } // for metric values, we're somewhat more permissive. We allow any // Printable unicode character, except quotation marks, ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L114-L136
go
train
// aggregationFunc converts an aggregation name into the equivalent call to an InfluxQL // aggregation function
func (sink *influxdbSink) aggregationFunc(aggregationName core.AggregationType, fieldName string) string
// aggregationFunc converts an aggregation name into the equivalent call to an InfluxQL // aggregation function func (sink *influxdbSink) aggregationFunc(aggregationName core.AggregationType, fieldName string) string
{ switch aggregationName { case core.AggregationTypeAverage: return fmt.Sprintf("MEAN(%q)", fieldName) case core.AggregationTypeMaximum: return fmt.Sprintf("MAX(%q)", fieldName) case core.AggregationTypeMinimum: return fmt.Sprintf("MIN(%q)", fieldName) case core.AggregationTypeMedian: return fmt.Sprintf("...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L139-L166
go
train
// keyToSelector converts a HistoricalKey to an InfluxQL predicate
func (sink *influxdbSink) keyToSelector(key core.HistoricalKey) string
// keyToSelector converts a HistoricalKey to an InfluxQL predicate func (sink *influxdbSink) keyToSelector(key core.HistoricalKey) string
{ typeSel := fmt.Sprintf("type = '%s'", key.ObjectType) switch key.ObjectType { case core.MetricSetTypeNode: return fmt.Sprintf("%s AND %s = '%s'", typeSel, core.LabelNodename.Key, key.NodeName) case core.MetricSetTypeSystemContainer: return fmt.Sprintf("%s AND %s = '%s' AND %s = '%s'", typeSel, core.LabelCont...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L169-L180
go
train
// labelsToPredicate composes an InfluxQL predicate based on the given map of labels
func (sink *influxdbSink) labelsToPredicate(labels map[string]string) string
// labelsToPredicate composes an InfluxQL predicate based on the given map of labels func (sink *influxdbSink) labelsToPredicate(labels map[string]string) string
{ if len(labels) == 0 { return "" } parts := make([]string, 0, len(labels)) for k, v := range labels { parts = append(parts, fmt.Sprintf("%q = '%s'", k, v)) } return strings.Join(parts, " AND ") }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L184-L195
go
train
// metricToSeriesAndField retrieves the appropriate field name and series name for a given metric // (this varies depending on whether or not WithFields is enabled)
func (sink *influxdbSink) metricToSeriesAndField(metricName string) (string, string)
// metricToSeriesAndField retrieves the appropriate field name and series name for a given metric // (this varies depending on whether or not WithFields is enabled) func (sink *influxdbSink) metricToSeriesAndField(metricName string) (string, string)
{ if sink.c.WithFields { seriesName := strings.SplitN(metricName, "/", 2) if len(seriesName) > 1 { return seriesName[0], seriesName[1] } else { return seriesName[0], "value" } } else { return metricName, "value" } }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L198-L217
go
train
// composeRawQuery creates the InfluxQL query to fetch the given metric values
func (sink *influxdbSink) composeRawQuery(metricName string, labels map[string]string, metricKeys []core.HistoricalKey, start, end time.Time) string
// composeRawQuery creates the InfluxQL query to fetch the given metric values func (sink *influxdbSink) composeRawQuery(metricName string, labels map[string]string, metricKeys []core.HistoricalKey, start, end time.Time) string
{ seriesName, fieldName := sink.metricToSeriesAndField(metricName) queries := make([]string, len(metricKeys)) for i, key := range metricKeys { pred := sink.keyToSelector(key) if labels != nil { pred += fmt.Sprintf(" AND %s", sink.labelsToPredicate(labels)) } if !start.IsZero() { pred += fmt.Sprintf("...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L221-L252
go
train
// parseRawQueryRow parses a set of timestamped metric values from unstructured JSON output into the // appropriate Heapster form
func (sink *influxdbSink) parseRawQueryRow(rawRow influx_models.Row) ([]core.TimestampedMetricValue, error)
// parseRawQueryRow parses a set of timestamped metric values from unstructured JSON output into the // appropriate Heapster form func (sink *influxdbSink) parseRawQueryRow(rawRow influx_models.Row) ([]core.TimestampedMetricValue, error)
{ vals := make([]core.TimestampedMetricValue, len(rawRow.Values)) wasInt := make(map[string]bool, 1) for i, rawVal := range rawRow.Values { val := core.TimestampedMetricValue{} if ts, err := time.Parse(time.RFC3339, rawVal[0].(string)); err != nil { return nil, fmt.Errorf("Unable to parse timestamp %q in se...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L256-L291
go
train
// GetMetric retrieves the given metric for one or more objects (specified by metricKeys) of // the same type, within the given time interval
func (sink *influxdbSink) GetMetric(metricName string, metricKeys []core.HistoricalKey, start, end time.Time) (map[core.HistoricalKey][]core.TimestampedMetricValue, error)
// GetMetric retrieves the given metric for one or more objects (specified by metricKeys) of // the same type, within the given time interval func (sink *influxdbSink) GetMetric(metricName string, metricKeys []core.HistoricalKey, start, end time.Time) (map[core.HistoricalKey][]core.TimestampedMetricValue, error)
{ for _, key := range metricKeys { if err := sink.checkSanitizedKey(&key); err != nil { return nil, err } } if err := sink.checkSanitizedMetricName(metricName); err != nil { return nil, err } query := sink.composeRawQuery(metricName, nil, metricKeys, start, end) sink.RLock() defer sink.RUnlock() r...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L337-L378
go
train
// composeAggregateQuery creates the InfluxQL query to fetch the given aggregation values
func (sink *influxdbSink) composeAggregateQuery(metricName string, labels map[string]string, aggregations []core.AggregationType, metricKeys []core.HistoricalKey, start, end time.Time, bucketSize time.Duration) string
// composeAggregateQuery creates the InfluxQL query to fetch the given aggregation values func (sink *influxdbSink) composeAggregateQuery(metricName string, labels map[string]string, aggregations []core.AggregationType, metricKeys []core.HistoricalKey, start, end time.Time, bucketSize time.Duration) string
{ seriesName, fieldName := sink.metricToSeriesAndField(metricName) var bucketSizeNanoSeconds int64 = 0 if bucketSize != 0 { bucketSizeNanoSeconds = int64(bucketSize.Nanoseconds() / int64(time.Microsecond/time.Nanosecond)) } queries := make([]string, len(metricKeys)) for i, key := range metricKeys { pred :=...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L382-L422
go
train
// parseRawQueryRow parses a set of timestamped aggregation values from unstructured JSON output into the // appropriate Heapster form
func (sink *influxdbSink) parseAggregateQueryRow(rawRow influx_models.Row, aggregationLookup map[core.AggregationType]int, bucketSize time.Duration) ([]core.TimestampedAggregationValue, error)
// parseRawQueryRow parses a set of timestamped aggregation values from unstructured JSON output into the // appropriate Heapster form func (sink *influxdbSink) parseAggregateQueryRow(rawRow influx_models.Row, aggregationLookup map[core.AggregationType]int, bucketSize time.Duration) ([]core.TimestampedAggregationValue,...
{ vals := make([]core.TimestampedAggregationValue, len(rawRow.Values)) wasInt := make(map[string]bool, len(aggregationLookup)) for i, rawVal := range rawRow.Values { val := core.TimestampedAggregationValue{ BucketSize: bucketSize, AggregationValue: core.AggregationValue{ Aggregations: map[core.Aggregat...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L426-L469
go
train
// GetAggregation fetches the given aggregations for one or more objects (specified by metricKeys) of // the same type, within the given time interval, calculated over a series of buckets
func (sink *influxdbSink) GetAggregation(metricName string, aggregations []core.AggregationType, metricKeys []core.HistoricalKey, start, end time.Time, bucketSize time.Duration) (map[core.HistoricalKey][]core.TimestampedAggregationValue, error)
// GetAggregation fetches the given aggregations for one or more objects (specified by metricKeys) of // the same type, within the given time interval, calculated over a series of buckets func (sink *influxdbSink) GetAggregation(metricName string, aggregations []core.AggregationType, metricKeys []core.HistoricalKey, st...
{ for _, key := range metricKeys { if err := sink.checkSanitizedKey(&key); err != nil { return nil, err } } if err := sink.checkSanitizedMetricName(metricName); err != nil { return nil, err } // make it easy to look up where the different aggregations are in the list aggregationLookup := make(map[core...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L524-L535
go
train
// setAggregationValueIfPresent checks if the given metric value is present in the list of raw values, and if so, // copies it to the output format
func setAggregationValueIfPresent(aggName core.AggregationType, rawVal []interface{}, aggregations *core.AggregationValue, indexLookup map[core.AggregationType]int, wasInt map[string]bool) error
// setAggregationValueIfPresent checks if the given metric value is present in the list of raw values, and if so, // copies it to the output format func setAggregationValueIfPresent(aggName core.AggregationType, rawVal []interface{}, aggregations *core.AggregationValue, indexLookup map[core.AggregationType]int, wasInt ...
{ if fieldIndex, ok := indexLookup[aggName]; ok { targetValue := &core.MetricValue{} if err := tryParseMetricValue(string(aggName), rawVal, targetValue, fieldIndex, wasInt); err != nil { return err } aggregations.Aggregations[aggName] = *targetValue } return nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L538-L567
go
train
// tryParseMetricValue attempts to parse a raw metric value into the appropriate go type.
func tryParseMetricValue(aggName string, rawVal []interface{}, targetValue *core.MetricValue, fieldIndex int, wasInt map[string]bool) error
// tryParseMetricValue attempts to parse a raw metric value into the appropriate go type. func tryParseMetricValue(aggName string, rawVal []interface{}, targetValue *core.MetricValue, fieldIndex int, wasInt map[string]bool) error
{ // the Influx client decodes numeric fields to json.Number (a string), so we have to deal with that -- // assume, starting off, that values may be either float or int. Try int until we fail once, and always // try float. At the end, figure out which is which. var rv string if rvN, ok := rawVal[fieldIndex].(j...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L570-L575
go
train
// GetMetricNames retrieves the available metric names for the given object
func (sink *influxdbSink) GetMetricNames(metricKey core.HistoricalKey) ([]string, error)
// GetMetricNames retrieves the available metric names for the given object func (sink *influxdbSink) GetMetricNames(metricKey core.HistoricalKey) ([]string, error)
{ if err := sink.checkSanitizedKey(&metricKey); err != nil { return nil, err } return sink.stringListQuery(fmt.Sprintf("SHOW MEASUREMENTS WHERE %s", sink.keyToSelector(metricKey)), "Unable to list available metrics") }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L578-L580
go
train
// GetNodes retrieves the list of nodes in the cluster
func (sink *influxdbSink) GetNodes() ([]string, error)
// GetNodes retrieves the list of nodes in the cluster func (sink *influxdbSink) GetNodes() ([]string, error)
{ return sink.stringListQuery(fmt.Sprintf("SHOW TAG VALUES WITH KEY = %s", core.LabelNodename.Key), "Unable to list all nodes") }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L583-L585
go
train
// GetNamespaces retrieves the list of namespaces in the cluster
func (sink *influxdbSink) GetNamespaces() ([]string, error)
// GetNamespaces retrieves the list of namespaces in the cluster func (sink *influxdbSink) GetNamespaces() ([]string, error)
{ return sink.stringListQuery(fmt.Sprintf("SHOW TAG VALUES WITH KEY = %s", core.LabelNamespaceName.Key), "Unable to list all namespaces") }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L588-L597
go
train
// GetPodsFromNamespace retrieves the list of pods in a given namespace
func (sink *influxdbSink) GetPodsFromNamespace(namespace string) ([]string, error)
// GetPodsFromNamespace retrieves the list of pods in a given namespace func (sink *influxdbSink) GetPodsFromNamespace(namespace string) ([]string, error)
{ if !nameAllowedChars.MatchString(namespace) { return nil, fmt.Errorf("Invalid namespace name %q", namespace) } // This is a bit difficult for the influx query language, so we cheat a bit here -- // we just get all series for the uptime measurement for pods which match our namespace // (any measurement should ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L600-L609
go
train
// GetSystemContainersFromNode retrieves the list of free containers for a given node
func (sink *influxdbSink) GetSystemContainersFromNode(node string) ([]string, error)
// GetSystemContainersFromNode retrieves the list of free containers for a given node func (sink *influxdbSink) GetSystemContainersFromNode(node string) ([]string, error)
{ if !nameAllowedChars.MatchString(node) { return nil, fmt.Errorf("Invalid node name %q", node) } // This is a bit difficult for the influx query language, so we cheat a bit here -- // we just get all series for the uptime measurement for system containers on our node // (any measurement should work here, thoug...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L612-L643
go
train
// stringListQueryCol runs the given query, and returns all results from the given column as a string list
func (sink *influxdbSink) stringListQueryCol(q, colName string, errStr string) ([]string, error)
// stringListQueryCol runs the given query, and returns all results from the given column as a string list func (sink *influxdbSink) stringListQueryCol(q, colName string, errStr string) ([]string, error)
{ sink.RLock() defer sink.RUnlock() resp, err := sink.runQuery(q) if err != nil { return nil, fmt.Errorf(errStr) } if len(resp[0].Series) < 1 { return nil, fmt.Errorf(errStr) } colInd := -1 for i, col := range resp[0].Series[0].Columns { if col == colName { colInd = i break } } if colInd =...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L646-L664
go
train
// stringListQuery runs the given query, and returns all results from the first column as a string list
func (sink *influxdbSink) stringListQuery(q string, errStr string) ([]string, error)
// stringListQuery runs the given query, and returns all results from the first column as a string list func (sink *influxdbSink) stringListQuery(q string, errStr string) ([]string, error)
{ sink.RLock() defer sink.RUnlock() resp, err := sink.runQuery(q) if err != nil { return nil, fmt.Errorf(errStr) } if len(resp[0].Series) < 1 { return nil, fmt.Errorf(errStr) } res := make([]string, len(resp[0].Series[0].Values)) for i, rv := range resp[0].Series[0].Values { res[i] = rv[0].(string) ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L668-L697
go
train
// runQuery executes the given query against InfluxDB (using the default database for this sink) // The caller is responsible for locking the sink before use.
func (sink *influxdbSink) runQuery(queryStr string) ([]influxdb.Result, error)
// runQuery executes the given query against InfluxDB (using the default database for this sink) // The caller is responsible for locking the sink before use. func (sink *influxdbSink) runQuery(queryStr string) ([]influxdb.Result, error)
{ // ensure we have a valid client handle before attempting to use it if err := sink.ensureClient(); err != nil { glog.Errorf("Unable to ensure InfluxDB client is present: %v", err) return nil, fmt.Errorf("unable to run query: unable to connect to database") } q := influxdb.Query{ Command: queryStr, Data...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L700-L709
go
train
// populateAggregations extracts aggregation values from a given data point
func populateAggregations(rawRowName string, rawVal []interface{}, val *core.TimestampedAggregationValue, aggregationLookup map[core.AggregationType]int, wasInt map[string]bool) error
// populateAggregations extracts aggregation values from a given data point func populateAggregations(rawRowName string, rawVal []interface{}, val *core.TimestampedAggregationValue, aggregationLookup map[core.AggregationType]int, wasInt map[string]bool) error
{ for _, aggregation := range core.MultiTypedAggregations { if err := setAggregationValueIfPresent(aggregation, rawVal, &val.AggregationValue, aggregationLookup, wasInt); err != nil { glog.Errorf("Unable to parse field %q in series %q: %v", aggregation, rawRowName, err) return fmt.Errorf("Unable to parse valu...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/influxdb/influxdb_historical.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/influxdb/influxdb_historical.go#L713-L729
go
train
// setAggregationValueTypes inspects a set of aggregation values and figures out whether each aggregation value // returned as a float column, or an int column
func setAggregationValueTypes(vals []core.TimestampedAggregationValue, wasInt map[string]bool)
// setAggregationValueTypes inspects a set of aggregation values and figures out whether each aggregation value // returned as a float column, or an int column func setAggregationValueTypes(vals []core.TimestampedAggregationValue, wasInt map[string]bool)
{ for _, aggregation := range core.MultiTypedAggregations { if isInt, ok := wasInt[string(aggregation)]; ok && isInt { for i := range vals { val := vals[i].Aggregations[aggregation] val.ValueType = core.ValueInt64 vals[i].Aggregations[aggregation] = val } } else if ok { for i := range vals { ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/metric/metric_sink.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/metric/metric_sink.go#L256-L260
go
train
/* * For debugging only. */
func (this *MetricSink) GetMetricSetKeys() []string
/* * For debugging only. */ func (this *MetricSink) GetMetricSetKeys() []string
{ return this.getAllNames( func(ms *core.MetricSet) bool { return true }, func(key string, ms *core.MetricSet) string { return key }) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/gcm/gcm.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/gcm/gcm.go#L217-L297
go
train
// Adds the specified metrics or updates them if they already exist.
func (sink *gcmSink) register(metrics []core.Metric) error
// Adds the specified metrics or updates them if they already exist. func (sink *gcmSink) register(metrics []core.Metric) error
{ sink.Lock() defer sink.Unlock() if sink.registered { return nil } for _, metric := range metrics { metricName := fullMetricName(sink.project, metric.MetricDescriptor.Name) metricType := fullMetricType(metric.MetricDescriptor.Name) if _, err := sink.gcmService.Projects.MetricDescriptors.Delete(metricNa...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/manager.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/manager.go#L106-L124
go
train
// Guarantees that the export will complete in sinkExportDataTimeout.
func (this *sinkManager) ExportData(data *core.DataBatch)
// Guarantees that the export will complete in sinkExportDataTimeout. func (this *sinkManager) ExportData(data *core.DataBatch)
{ var wg sync.WaitGroup for _, sh := range this.sinkHolders { wg.Add(1) go func(sh sinkHolder, wg *sync.WaitGroup) { defer wg.Done() glog.V(2).Infof("Pushing data to: %s", sh.sink.Name()) select { case sh.dataBatchChannel <- data: glog.V(2).Infof("Data push completed: %s", sh.sink.Name()) // ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
events/sinks/riemann/driver.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/events/sinks/riemann/driver.go#L38-L49
go
train
// creates a Riemann sink. Returns a riemannSink
func CreateRiemannSink(uri *url.URL) (core.EventSink, error)
// creates a Riemann sink. Returns a riemannSink func CreateRiemannSink(uri *url.URL) (core.EventSink, error)
{ var sink, err = riemannCommon.CreateRiemannSink(uri) if err != nil { glog.Warningf("Error creating the Riemann metrics sink: %v", err) return nil, err } rs := &RiemannSink{ client: sink.Client, config: sink.Config, } return rs, nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/cmd/heapster-apiserver/app/server.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/cmd/heapster-apiserver/app/server.go#L39-L42
go
train
// Run runs the specified APIServer. This should never exit.
func (h *HeapsterAPIServer) RunServer() error
// Run runs the specified APIServer. This should never exit. func (h *HeapsterAPIServer) RunServer() error
{ h.PrepareRun().Run(wait.NeverStop) return nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sources/kubelet/kubelet_client.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/kubelet/kubelet_client.go#L152-L156
go
train
// Get stats for all non-Kubernetes containers.
func (self *KubeletClient) GetAllRawContainers(host Host, start, end time.Time) ([]cadvisor.ContainerInfo, error)
// Get stats for all non-Kubernetes containers. func (self *KubeletClient) GetAllRawContainers(host Host, start, end time.Time) ([]cadvisor.ContainerInfo, error)
{ url := self.getUrl(host, "/stats/container/") return self.getAllContainers(url, start, end) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/util/metrics/http.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/util/metrics/http.go#L36-L103
go
train
// InstrumentRouteFunc works like Prometheus' InstrumentHandlerFunc but wraps // the go-restful RouteFunction instead of a HandlerFunc
func InstrumentRouteFunc(handlerName string, routeFunc restful.RouteFunction) restful.RouteFunction
// InstrumentRouteFunc works like Prometheus' InstrumentHandlerFunc but wraps // the go-restful RouteFunction instead of a HandlerFunc func InstrumentRouteFunc(handlerName string, routeFunc restful.RouteFunction) restful.RouteFunction
{ opts := prometheus.SummaryOpts{ Subsystem: "http", ConstLabels: prometheus.Labels{"handler": handlerName}, } reqCnt := prometheus.NewCounterVec( prometheus.CounterOpts{ Subsystem: opts.Subsystem, Name: "requests_total", Help: "Total number of HTTP requests made.", ConstLabels:...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/core/ms_keys.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/core/ms_keys.go#L26-L28
go
train
// MetricsSet keys are inside of DataBatch. The structure of the returned string is // an implementation detail and no component should rely on it as it may change // anytime. It only guaranteed that it is unique for the unique combination of // passed parameters.
func PodContainerKey(namespace, podName, containerName string) string
// MetricsSet keys are inside of DataBatch. The structure of the returned string is // an implementation detail and no component should rely on it as it may change // anytime. It only guaranteed that it is unique for the unique combination of // passed parameters. func PodContainerKey(namespace, podName, containerName ...
{ return fmt.Sprintf("namespace:%s/pod:%s/container:%s", namespace, podName, containerName) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/processors/namespace_based_enricher.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/processors/namespace_based_enricher.go#L49-L78
go
train
// Adds UID to all namespaced elements.
func (this *NamespaceBasedEnricher) addNamespaceInfo(metricSet *core.MetricSet)
// Adds UID to all namespaced elements. func (this *NamespaceBasedEnricher) addNamespaceInfo(metricSet *core.MetricSet)
{ metricSetType, found := metricSet.Labels[core.LabelMetricSetType.Key] if !found { return } if metricSetType != core.MetricSetTypePodContainer && metricSetType != core.MetricSetTypePod && metricSetType != core.MetricSetTypeNamespace { return } namespaceName, found := metricSet.Labels[core.LabelNamespac...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L79-L257
go
train
// addClusterMetricsRoutes adds all the standard model routes to a WebService. // It should already have a base path registered.
func addClusterMetricsRoutes(a clusterMetricsFetcher, ws *restful.WebService)
// addClusterMetricsRoutes adds all the standard model routes to a WebService. // It should already have a base path registered. func addClusterMetricsRoutes(a clusterMetricsFetcher, ws *restful.WebService)
{ // The /metrics/ endpoint returns a list of all available metrics for the Cluster entity of the model. ws.Route(ws.GET("/metrics/"). To(metrics.InstrumentRouteFunc("availableClusterMetrics", a.availableClusterMetrics)). Doc("Get a list of all available metrics for the Cluster entity"). Operation("availableCl...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L266-L280
go
train
// RegisterModel registers the Model API endpoints. // All endpoints that end with a {metric-name} also receive a start time query parameter. // The start and end times should be specified as a string, formatted according to RFC 3339.
func (a *Api) RegisterModel(container *restful.Container)
// RegisterModel registers the Model API endpoints. // All endpoints that end with a {metric-name} also receive a start time query parameter. // The start and end times should be specified as a string, formatted according to RFC 3339. func (a *Api) RegisterModel(container *restful.Container)
{ ws := new(restful.WebService) ws.Path("/api/v1/model"). Doc("Root endpoint of the stats model"). Consumes("*/*"). Produces(restful.MIME_JSON) addClusterMetricsRoutes(a, ws) ws.Route(ws.GET("/debug/allkeys"). To(metrics.InstrumentRouteFunc("debugAllKeys", a.allKeys)). Doc("Get keys of all metric sets ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L283-L285
go
train
// availableMetrics returns a list of available cluster metric names.
func (a *Api) availableClusterMetrics(request *restful.Request, response *restful.Response)
// availableMetrics returns a list of available cluster metric names. func (a *Api) availableClusterMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricNamesRequest(core.ClusterKey(), response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L288-L290
go
train
// availableMetrics returns a list of available node metric names.
func (a *Api) availableNodeMetrics(request *restful.Request, response *restful.Response)
// availableMetrics returns a list of available node metric names. func (a *Api) availableNodeMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricNamesRequest(core.NodeKey(request.PathParameter("node-name")), response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L293-L295
go
train
// availableMetrics returns a list of available namespace metric names.
func (a *Api) availableNamespaceMetrics(request *restful.Request, response *restful.Response)
// availableMetrics returns a list of available namespace metric names. func (a *Api) availableNamespaceMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricNamesRequest(core.NamespaceKey(request.PathParameter("namespace-name")), response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L298-L302
go
train
// availableMetrics returns a list of available pod metric names.
func (a *Api) availablePodMetrics(request *restful.Request, response *restful.Response)
// availableMetrics returns a list of available pod metric names. func (a *Api) availablePodMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricNamesRequest( core.PodKey(request.PathParameter("namespace-name"), request.PathParameter("pod-name")), response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L305-L311
go
train
// availableMetrics returns a list of available pod metric names.
func (a *Api) availablePodContainerMetrics(request *restful.Request, response *restful.Response)
// availableMetrics returns a list of available pod metric names. func (a *Api) availablePodContainerMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricNamesRequest( core.PodContainerKey(request.PathParameter("namespace-name"), request.PathParameter("pod-name"), request.PathParameter("container-name"), ), response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L314-L319
go
train
// availableMetrics returns a list of available pod metric names.
func (a *Api) availableFreeContainerMetrics(request *restful.Request, response *restful.Response)
// availableMetrics returns a list of available pod metric names. func (a *Api) availableFreeContainerMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricNamesRequest( core.NodeContainerKey(request.PathParameter("node-name"), request.PathParameter("container-name"), ), response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L346-L348
go
train
// clusterMetrics returns a metric timeseries for a metric of the Cluster entity.
func (a *Api) clusterMetrics(request *restful.Request, response *restful.Response)
// clusterMetrics returns a metric timeseries for a metric of the Cluster entity. func (a *Api) clusterMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricRequest(core.ClusterKey(), request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L351-L354
go
train
// nodeMetrics returns a metric timeseries for a metric of the Node entity.
func (a *Api) nodeMetrics(request *restful.Request, response *restful.Response)
// nodeMetrics returns a metric timeseries for a metric of the Node entity. func (a *Api) nodeMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricRequest(core.NodeKey(request.PathParameter("node-name")), request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L357-L360
go
train
// namespaceMetrics returns a metric timeseries for a metric of the Namespace entity.
func (a *Api) namespaceMetrics(request *restful.Request, response *restful.Response)
// namespaceMetrics returns a metric timeseries for a metric of the Namespace entity. func (a *Api) namespaceMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricRequest(core.NamespaceKey(request.PathParameter("namespace-name")), request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L363-L368
go
train
// podMetrics returns a metric timeseries for a metric of the Pod entity.
func (a *Api) podMetrics(request *restful.Request, response *restful.Response)
// podMetrics returns a metric timeseries for a metric of the Pod entity. func (a *Api) podMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricRequest( core.PodKey(request.PathParameter("namespace-name"), request.PathParameter("pod-name")), request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L409-L416
go
train
// podContainerMetrics returns a metric timeseries for a metric of a Pod Container entity. // podContainerMetrics uses the namespace-name/pod-name/container-name path.
func (a *Api) podContainerMetrics(request *restful.Request, response *restful.Response)
// podContainerMetrics returns a metric timeseries for a metric of a Pod Container entity. // podContainerMetrics uses the namespace-name/pod-name/container-name path. func (a *Api) podContainerMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricRequest( core.PodContainerKey(request.PathParameter("namespace-name"), request.PathParameter("pod-name"), request.PathParameter("container-name"), ), request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L420-L426
go
train
// freeContainerMetrics returns a metric timeseries for a metric of the Container entity. // freeContainerMetrics addresses only free containers, by using the node-name/container-name path.
func (a *Api) freeContainerMetrics(request *restful.Request, response *restful.Response)
// freeContainerMetrics returns a metric timeseries for a metric of the Container entity. // freeContainerMetrics addresses only free containers, by using the node-name/container-name path. func (a *Api) freeContainerMetrics(request *restful.Request, response *restful.Response)
{ a.processMetricRequest( core.NodeContainerKey(request.PathParameter("node-name"), request.PathParameter("container-name"), ), request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/model_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/model_handlers.go#L429-L438
go
train
// parseRequestParam parses a time.Time from a named QueryParam, using the RFC3339 format.
func parseTimeParam(queryParam string, defaultValue time.Time) (time.Time, error)
// parseRequestParam parses a time.Time from a named QueryParam, using the RFC3339 format. func parseTimeParam(queryParam string, defaultValue time.Time) (time.Time, error)
{ if queryParam != "" { reqStamp, err := time.Parse(time.RFC3339, queryParam) if err != nil { return time.Time{}, fmt.Errorf("timestamp argument cannot be parsed: %s", err) } return reqStamp, nil } return defaultValue, nil }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/riemann/driver.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/riemann/driver.go#L61-L85
go
train
// Receives a list of riemanngo.Event, the sink, and parameters. // Creates a new event using the parameters and the sink config, and add it into the Event list. // Can send events if events is full // Return the list.
func appendEvent(events []riemanngo.Event, sink *RiemannSink, host, name string, value interface{}, labels map[string]string, timestamp int64) []riemanngo.Event
// Receives a list of riemanngo.Event, the sink, and parameters. // Creates a new event using the parameters and the sink config, and add it into the Event list. // Can send events if events is full // Return the list. func appendEvent(events []riemanngo.Event, sink *RiemannSink, host, name string, value interface{}, l...
{ event := riemanngo.Event{ Time: timestamp, Service: name, Host: host, Description: "", Attributes: labels, Metric: value, Ttl: sink.config.Ttl, State: sink.config.State, Tags: sink.config.Tags, } // state everywhere events = append(events, event) if...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/sinks/riemann/driver.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/riemann/driver.go#L88-L137
go
train
// ExportData Send a collection of Timeseries to Riemann
func (sink *RiemannSink) ExportData(dataBatch *core.DataBatch)
// ExportData Send a collection of Timeseries to Riemann func (sink *RiemannSink) ExportData(dataBatch *core.DataBatch)
{ sink.Lock() defer sink.Unlock() if sink.client == nil { // the client could be nil here, so we reconnect client, err := riemannCommon.GetRiemannClient(sink.config) if err != nil { glog.Warningf("Riemann sink not connected: %v", err) return } sink.client = client } var events []riemanngo.Event ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L51-L199
go
train
// addAggregationRoutes adds routes to a webservice which point to a metricsAggregationFetcher's methods
func addAggregationRoutes(a metricsAggregationFetcher, ws *restful.WebService)
// addAggregationRoutes adds routes to a webservice which point to a metricsAggregationFetcher's methods func addAggregationRoutes(a metricsAggregationFetcher, ws *restful.WebService)
{ // The /metrics-aggregated/{aggregations}/{metric-name} endpoint exposes some aggregations for the Cluster entity of the historical API. ws.Route(ws.GET("/metrics-aggregated/{aggregations}/{metric-name:*}"). To(metrics.InstrumentRouteFunc("clusterMetrics", a.clusterAggregations)). Doc("Export some cluster-leve...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L204-L256
go
train
// RegisterHistorical registers the Historical API endpoints. It will register the same endpoints // as those in the model API, plus endpoints for aggregation retrieval, and endpoints to retrieve pod // metrics by using the pod id.
func (normalApi *Api) RegisterHistorical(container *restful.Container)
// RegisterHistorical registers the Historical API endpoints. It will register the same endpoints // as those in the model API, plus endpoints for aggregation retrieval, and endpoints to retrieve pod // metrics by using the pod id. func (normalApi *Api) RegisterHistorical(container *restful.Container)
{ ws := new(restful.WebService) ws.Path("/api/v1/historical"). Doc("Root endpoint of the historical access API"). Consumes("*/*"). Produces(restful.MIME_JSON) a := &HistoricalApi{normalApi} addClusterMetricsRoutes(a, ws) addAggregationRoutes(a, ws) // register the endpoint for fetching raw metrics based ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L259-L262
go
train
// availableClusterMetrics returns a list of available cluster metric names.
func (a *HistoricalApi) availableClusterMetrics(request *restful.Request, response *restful.Response)
// availableClusterMetrics returns a list of available cluster metric names. func (a *HistoricalApi) availableClusterMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ObjectType: core.MetricSetTypeCluster} a.processMetricNamesRequest(key, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L265-L271
go
train
// availableNodeMetrics returns a list of available node metric names.
func (a *HistoricalApi) availableNodeMetrics(request *restful.Request, response *restful.Response)
// availableNodeMetrics returns a list of available node metric names. func (a *HistoricalApi) availableNodeMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNode, NodeName: request.PathParameter("node-name"), } a.processMetricNamesRequest(key, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L274-L280
go
train
// availableNamespaceMetrics returns a list of available namespace metric names.
func (a *HistoricalApi) availableNamespaceMetrics(request *restful.Request, response *restful.Response)
// availableNamespaceMetrics returns a list of available namespace metric names. func (a *HistoricalApi) availableNamespaceMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNamespace, NamespaceName: request.PathParameter("namespace-name"), } a.processMetricNamesRequest(key, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L283-L290
go
train
// availablePodMetrics returns a list of available pod metric names.
func (a *HistoricalApi) availablePodMetrics(request *restful.Request, response *restful.Response)
// availablePodMetrics returns a list of available pod metric names. func (a *HistoricalApi) availablePodMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypePod, NamespaceName: request.PathParameter("namespace-name"), PodName: request.PathParameter("pod-name"), } a.processMetricNamesRequest(key, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L293-L301
go
train
// availablePodContainerMetrics returns a list of available pod container metric names.
func (a *HistoricalApi) availablePodContainerMetrics(request *restful.Request, response *restful.Response)
// availablePodContainerMetrics returns a list of available pod container metric names. func (a *HistoricalApi) availablePodContainerMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypePodContainer, NamespaceName: request.PathParameter("namespace-name"), PodName: request.PathParameter("pod-name"), ContainerName: request.PathParameter("container-name"), } a.processMetricNamesRequest(key, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L304-L311
go
train
// availableFreeContainerMetrics returns a list of available pod metric names.
func (a *HistoricalApi) availableFreeContainerMetrics(request *restful.Request, response *restful.Response)
// availableFreeContainerMetrics returns a list of available pod metric names. func (a *HistoricalApi) availableFreeContainerMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeSystemContainer, NodeName: request.PathParameter("node-name"), ContainerName: request.PathParameter("container-name"), } a.processMetricNamesRequest(key, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L314-L320
go
train
// nodeList lists all nodes for which we have metrics
func (a *HistoricalApi) nodeList(request *restful.Request, response *restful.Response)
// nodeList lists all nodes for which we have metrics func (a *HistoricalApi) nodeList(request *restful.Request, response *restful.Response)
{ if resp, err := a.historicalSource.GetNodes(); err != nil { response.WriteError(http.StatusInternalServerError, err) } else { response.WriteEntity(resp) } }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L323-L329
go
train
// namespaceList lists all namespaces for which we have metrics
func (a *HistoricalApi) namespaceList(request *restful.Request, response *restful.Response)
// namespaceList lists all namespaces for which we have metrics func (a *HistoricalApi) namespaceList(request *restful.Request, response *restful.Response)
{ if resp, err := a.historicalSource.GetNamespaces(); err != nil { response.WriteError(http.StatusInternalServerError, err) } else { response.WriteEntity(resp) } }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L332-L338
go
train
// namespacePodList lists all pods for which we have metrics in a particular namespace
func (a *HistoricalApi) namespacePodList(request *restful.Request, response *restful.Response)
// namespacePodList lists all pods for which we have metrics in a particular namespace func (a *HistoricalApi) namespacePodList(request *restful.Request, response *restful.Response)
{ if resp, err := a.historicalSource.GetPodsFromNamespace(request.PathParameter("namespace-name")); err != nil { response.WriteError(http.StatusInternalServerError, err) } else { response.WriteEntity(resp) } }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L350-L353
go
train
// clusterMetrics returns a metric timeseries for a metric of the Cluster entity.
func (a *HistoricalApi) clusterMetrics(request *restful.Request, response *restful.Response)
// clusterMetrics returns a metric timeseries for a metric of the Cluster entity. func (a *HistoricalApi) clusterMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ObjectType: core.MetricSetTypeCluster} a.processMetricRequest(key, request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L356-L362
go
train
// nodeMetrics returns a metric timeseries for a metric of the Node entity.
func (a *HistoricalApi) nodeMetrics(request *restful.Request, response *restful.Response)
// nodeMetrics returns a metric timeseries for a metric of the Node entity. func (a *HistoricalApi) nodeMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNode, NodeName: request.PathParameter("node-name"), } a.processMetricRequest(key, request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L365-L371
go
train
// namespaceMetrics returns a metric timeseries for a metric of the Namespace entity.
func (a *HistoricalApi) namespaceMetrics(request *restful.Request, response *restful.Response)
// namespaceMetrics returns a metric timeseries for a metric of the Namespace entity. func (a *HistoricalApi) namespaceMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNamespace, NamespaceName: request.PathParameter("namespace-name"), } a.processMetricRequest(key, request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L374-L389
go
train
// podMetrics returns a metric timeseries for a metric of the Pod entity.
func (a *HistoricalApi) podMetrics(request *restful.Request, response *restful.Response)
// podMetrics returns a metric timeseries for a metric of the Pod entity. func (a *HistoricalApi) podMetrics(request *restful.Request, response *restful.Response)
{ var key core.HistoricalKey if request.PathParameter("pod-id") != "" { key = core.HistoricalKey{ ObjectType: core.MetricSetTypePod, PodId: request.PathParameter("pod-id"), } } else { key = core.HistoricalKey{ ObjectType: core.MetricSetTypePod, NamespaceName: request.PathParameter("namespa...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L393-L400
go
train
// freeContainerMetrics returns a metric timeseries for a metric of the Container entity. // freeContainerMetrics addresses only free containers.
func (a *HistoricalApi) freeContainerMetrics(request *restful.Request, response *restful.Response)
// freeContainerMetrics returns a metric timeseries for a metric of the Container entity. // freeContainerMetrics addresses only free containers. func (a *HistoricalApi) freeContainerMetrics(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeSystemContainer, NodeName: request.PathParameter("node-name"), ContainerName: request.PathParameter("container-name"), } a.processMetricRequest(key, request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L403-L459
go
train
// podListMetrics returns a list of metric timeseries for each for the listed nodes
func (a *HistoricalApi) podListMetrics(request *restful.Request, response *restful.Response)
// podListMetrics returns a list of metric timeseries for each for the listed nodes func (a *HistoricalApi) podListMetrics(request *restful.Request, response *restful.Response)
{ start, end, err := getStartEndTimeHistorical(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } keys := []core.HistoricalKey{} if request.PathParameter("pod-id-list") != "" { for _, podId := range strings.Split(request.PathParameter("pod-id-list"), ",") { key := core.His...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L482-L485
go
train
// clusterAggregations returns a metric timeseries for a metric of the Cluster entity.
func (a *HistoricalApi) clusterAggregations(request *restful.Request, response *restful.Response)
// clusterAggregations returns a metric timeseries for a metric of the Cluster entity. func (a *HistoricalApi) clusterAggregations(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ObjectType: core.MetricSetTypeCluster} a.processAggregationRequest(key, request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L488-L494
go
train
// nodeAggregations returns a metric timeseries for a metric of the Node entity.
func (a *HistoricalApi) nodeAggregations(request *restful.Request, response *restful.Response)
// nodeAggregations returns a metric timeseries for a metric of the Node entity. func (a *HistoricalApi) nodeAggregations(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNode, NodeName: request.PathParameter("node-name"), } a.processAggregationRequest(key, request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L497-L503
go
train
// namespaceAggregations returns a metric timeseries for a metric of the Namespace entity.
func (a *HistoricalApi) namespaceAggregations(request *restful.Request, response *restful.Response)
// namespaceAggregations returns a metric timeseries for a metric of the Namespace entity. func (a *HistoricalApi) namespaceAggregations(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNamespace, NamespaceName: request.PathParameter("namespace-name"), } a.processAggregationRequest(key, request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L524-L541
go
train
// podContainerAggregations returns a metric timeseries for a metric of a Pod Container entity.
func (a *HistoricalApi) podContainerAggregations(request *restful.Request, response *restful.Response)
// podContainerAggregations returns a metric timeseries for a metric of a Pod Container entity. func (a *HistoricalApi) podContainerAggregations(request *restful.Request, response *restful.Response)
{ var key core.HistoricalKey if request.PathParameter("pod-id") != "" { key = core.HistoricalKey{ ObjectType: core.MetricSetTypePodContainer, PodId: request.PathParameter("pod-id"), ContainerName: request.PathParameter("container-name"), } } else { key = core.HistoricalKey{ ObjectType: ...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L545-L552
go
train
// freeContainerAggregations returns a metric timeseries for a metric of the Container entity. // freeContainerAggregations addresses only free containers.
func (a *HistoricalApi) freeContainerAggregations(request *restful.Request, response *restful.Response)
// freeContainerAggregations returns a metric timeseries for a metric of the Container entity. // freeContainerAggregations addresses only free containers. func (a *HistoricalApi) freeContainerAggregations(request *restful.Request, response *restful.Response)
{ key := core.HistoricalKey{ ObjectType: core.MetricSetTypeSystemContainer, NodeName: request.PathParameter("node-name"), ContainerName: request.PathParameter("container-name"), } a.processAggregationRequest(key, request, response) }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L555-L616
go
train
// podListAggregations returns a list of metric timeseries for the specified pods.
func (a *HistoricalApi) podListAggregations(request *restful.Request, response *restful.Response)
// podListAggregations returns a list of metric timeseries for the specified pods. func (a *HistoricalApi) podListAggregations(request *restful.Request, response *restful.Response)
{ start, end, err := getStartEndTimeHistorical(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } bucketSize, err := getBucketSize(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } aggregations, err := getAggregations(request) if err != nil...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L619-L646
go
train
// processMetricRequest retrieves a metric for the object at the requested key.
func (a *HistoricalApi) processMetricRequest(key core.HistoricalKey, request *restful.Request, response *restful.Response)
// processMetricRequest retrieves a metric for the object at the requested key. func (a *HistoricalApi) processMetricRequest(key core.HistoricalKey, request *restful.Request, response *restful.Response)
{ start, end, err := getStartEndTimeHistorical(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } labels, err := getLabels(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } metricName := request.PathParameter("metric-name") convertedMetricN...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L649-L655
go
train
// processMetricNamesRequest retrieves the available metrics for the object at the specified key.
func (a *HistoricalApi) processMetricNamesRequest(key core.HistoricalKey, response *restful.Response)
// processMetricNamesRequest retrieves the available metrics for the object at the specified key. func (a *HistoricalApi) processMetricNamesRequest(key core.HistoricalKey, response *restful.Response)
{ if resp, err := a.historicalSource.GetMetricNames(key); err != nil { response.WriteError(http.StatusInternalServerError, err) } else { response.WriteEntity(resp) } }
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L658-L695
go
train
// processAggregationRequest retrieves one or more aggregations (across time) of a metric for the object specified at the given key.
func (a *HistoricalApi) processAggregationRequest(key core.HistoricalKey, request *restful.Request, response *restful.Response)
// processAggregationRequest retrieves one or more aggregations (across time) of a metric for the object specified at the given key. func (a *HistoricalApi) processAggregationRequest(key core.HistoricalKey, request *restful.Request, response *restful.Response)
{ start, end, err := getStartEndTimeHistorical(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } bucketSize, err := getBucketSize(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } aggregations, err := getAggregations(request) if err != nil...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L698-L739
go
train
// getBucketSize parses the bucket size specifier into a
func getBucketSize(request *restful.Request) (time.Duration, error)
// getBucketSize parses the bucket size specifier into a func getBucketSize(request *restful.Request) (time.Duration, error)
{ rawSize := request.QueryParameter("bucket") if rawSize == "" { return 0, nil } if len(rawSize) < 2 { return 0, fmt.Errorf("unable to parse bucket size: %q is too short to be a duration", rawSize) } var multiplier time.Duration var num string switch rawSize[len(rawSize)-1] { case 's': // could be s o...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L742-L759
go
train
// getAggregations extracts and validates the list of requested aggregations
func getAggregations(request *restful.Request) ([]core.AggregationType, error)
// getAggregations extracts and validates the list of requested aggregations func getAggregations(request *restful.Request) ([]core.AggregationType, error)
{ aggregationsRaw := strings.Split(request.PathParameter("aggregations"), ",") if len(aggregationsRaw) == 0 { return nil, fmt.Errorf("No aggregations specified") } aggregations := make([]core.AggregationType, len(aggregationsRaw)) for ind, aggNameRaw := range aggregationsRaw { aggName := core.AggregationTyp...
kubernetes-retired/heapster
e1e83412787b60d8a70088f09a2cb12339b305c3
metrics/api/v1/historical_handlers.go
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L762-L777
go
train
// exportMetricValue converts a core.MetricValue into an API MetricValue
func exportMetricValue(value *core.MetricValue) *types.MetricValue
// exportMetricValue converts a core.MetricValue into an API MetricValue func exportMetricValue(value *core.MetricValue) *types.MetricValue
{ if value == nil { return nil } if value.ValueType == core.ValueInt64 { return &types.MetricValue{ IntValue: &value.IntValue, } } else { floatVal := float64(value.FloatValue) return &types.MetricValue{ FloatValue: &floatVal, } } }