github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/metrics/sinks/graphite/driver_test.go (about)

     1  // Copyright 2016 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package graphite
    16  
    17  import (
    18  	"testing"
    19  
    20  	"k8s.io/heapster/metrics/core"
    21  
    22  	"github.com/stretchr/testify/assert"
    23  )
    24  
    25  var metricsTestCases = []struct {
    26  	metric graphiteMetric
    27  	path   string
    28  	value  string
    29  }{
    30  	{
    31  		graphiteMetric{},
    32  		"",
    33  		"0",
    34  	},
    35  	{
    36  		graphiteMetric{
    37  			name:  "metric/avg",
    38  			value: core.MetricValue{IntValue: 100, ValueType: core.ValueInt64},
    39  			labels: map[string]string{
    40  				"hostname":       "example",
    41  				"type":           "pod_container",
    42  				"namespace_name": "namespace",
    43  				"pod_name":       "pod-name-12345",
    44  				"container_name": "container",
    45  			},
    46  		},
    47  		"nodes.example.pods.namespace.pod-name-12345.containers.container.metric.avg",
    48  		"100",
    49  	},
    50  	{
    51  		graphiteMetric{
    52  			name:  "metric/avg",
    53  			value: core.MetricValue{IntValue: 100, ValueType: core.ValueInt64},
    54  			labels: map[string]string{
    55  				"hostname":       "example",
    56  				"type":           "sys_container",
    57  				"container_name": "container",
    58  			},
    59  		},
    60  		"nodes.example.sys-containers.container.metric.avg",
    61  		"100",
    62  	},
    63  	{
    64  		graphiteMetric{
    65  			name:  "metric/avg",
    66  			value: core.MetricValue{IntValue: 100, ValueType: core.ValueInt64},
    67  			labels: map[string]string{
    68  				"hostname":       "example",
    69  				"type":           "pod",
    70  				"namespace_name": "namespace",
    71  				"pod_name":       "pod-name-12345",
    72  			},
    73  		},
    74  		"nodes.example.pods.namespace.pod-name-12345.metric.avg",
    75  		"100",
    76  	},
    77  	{
    78  		graphiteMetric{
    79  			name:  "metric/avg",
    80  			value: core.MetricValue{IntValue: 100, ValueType: core.ValueInt64},
    81  			labels: map[string]string{
    82  				"type":           "ns",
    83  				"namespace_name": "namespace",
    84  			},
    85  		},
    86  		"namespaces.namespace.metric.avg",
    87  		"100",
    88  	},
    89  	{
    90  		graphiteMetric{
    91  			name:  "metric/avg",
    92  			value: core.MetricValue{IntValue: 100, ValueType: core.ValueInt64},
    93  			labels: map[string]string{
    94  				"hostname": "example",
    95  				"type":     "node",
    96  			},
    97  		},
    98  		"nodes.example.metric.avg",
    99  		"100",
   100  	},
   101  	{
   102  		graphiteMetric{
   103  			name:  "metric/avg",
   104  			value: core.MetricValue{IntValue: 100, ValueType: core.ValueInt64},
   105  			labels: map[string]string{
   106  				"hostname": "example",
   107  				"type":     "cluster",
   108  			},
   109  		},
   110  		"cluster.metric.avg",
   111  		"100",
   112  	},
   113  }
   114  
   115  func TestGraphitePathMetrics(t *testing.T) {
   116  	for _, c := range metricsTestCases {
   117  		m := c.metric.Metric()
   118  		assert.Equal(t, c.path, m.Name)
   119  		assert.Equal(t, c.value, m.Value)
   120  	}
   121  }