Skip to content

Commit 469f0ba

Browse files
committed
Merge branch 'master' into style-fix
2 parents 4941ab0 + 1b3dccf commit 469f0ba

File tree

8 files changed

+222
-153
lines changed

8 files changed

+222
-153
lines changed

src/app/backend/heapsterclient.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ import (
2929
func CreateHeapsterRESTClient(heapsterHost string, apiclient *client.Client) (
3030
*unversioned.RESTClient, error) {
3131

32-
cfg := client.Config{
33-
Host: heapsterHost,
34-
}
32+
cfg := client.Config{}
3533

3634
if heapsterHost == "" {
3735
bufferProxyHost := bytes.NewBufferString("http://")
3836
bufferProxyHost.WriteString(apiclient.RESTClient.Get().URL().Host)
39-
bufferProxyHost.WriteString("/api/v1/proxy/namespaces/kube-system/services/heapster/")
4037
cfg.Host = bufferProxyHost.String()
38+
cfg.Prefix = "/api/v1/proxy/namespaces/kube-system/services/heapster/api"
39+
} else {
40+
cfg.Host = heapsterHost
4141
}
42-
log.Printf("Creating Heapster REST client for %s", cfg.Host)
42+
log.Printf("Creating Heapster REST client for %s%s", cfg.Host, cfg.Prefix)
4343
clientFactory := new(ClientFactoryImpl)
4444
heapsterClient, err := clientFactory.New(&cfg)
4545
if err != nil {

src/app/backend/replicasetpodsmetrics.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import (
1919

2020
"encoding/json"
2121
"fmt"
22+
"strings"
23+
2224
heapster "k8s.io/heapster/api/v1/types"
2325
"k8s.io/kubernetes/pkg/api"
2426
unversioned "k8s.io/kubernetes/pkg/client/unversioned"
25-
"strings"
2627
)
2728

2829
const (
@@ -86,7 +87,7 @@ func getReplicaSetPodsMetrics(podList *api.PodList, heapsterClient *unversioned.
8687

8788
// Create URL path for metrics.
8889
func createMetricPath(namespace string, podNames []string, metricName string) string {
89-
return fmt.Sprintf("/api/v1/model/namespaces/%s/pod-list/%s/metrics/%s",
90+
return fmt.Sprintf("/model/namespaces/%s/pod-list/%s/metrics/%s",
9091
namespace,
9192
strings.Join(podNames, ","),
9293
metricName)
@@ -95,7 +96,7 @@ func createMetricPath(namespace string, podNames []string, metricName string) st
9596
// Retrieves raw metrics from Heapster.
9697
func getRawMetrics(heapsterClient *unversioned.RESTClient, metricPath string) ([]byte, error) {
9798

98-
resultRaw, err := heapsterClient.Get().RequestURI(metricPath).DoRaw()
99+
resultRaw, err := heapsterClient.Get().Suffix(metricPath).DoRaw()
99100

100101
if err != nil {
101102
return make([]byte, 0), err

src/app/frontend/common/filters/filters_module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import memoryFilter from './memory_filter';
1516
import middleEllipsisFilter from './middleellipsis_filter';
1617
import relativeTimeFilter from './relativetime_filter';
1718

@@ -25,4 +26,5 @@ export default angular
2526
'ngMaterial',
2627
])
2728
.filter('middleEllipsis', middleEllipsisFilter)
29+
.filter('kdMemory', memoryFilter)
2830
.filter('relativeTime', relativeTimeFilter);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2015 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+
/** Base for binary prefixes */
16+
const base = 1024;
17+
18+
/** Names of the suffixes where I-th name is for base^I suffix. */
19+
const powerSuffixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi'];
20+
21+
/**
22+
* Returns filter function that formats memory in bytes.
23+
* @param {function(number): string} numberFilter
24+
* @return {Function}
25+
* @ngInject
26+
*/
27+
export default function memoryFilter(numberFilter) {
28+
/**
29+
* Formats memory in bytes to a binary prefix format, e.g., 789,21 MiB.
30+
* @param {number} value Value to be formatted.
31+
* @return {string}
32+
*/
33+
let formatMemory = function(value) {
34+
let divider = 1;
35+
let power = 0;
36+
37+
while (value / divider > base && power < powerSuffixes.length - 1) {
38+
divider *= base;
39+
power += 1;
40+
}
41+
let formatted = numberFilter(value / divider);
42+
return `${formatted} ${powerSuffixes[power]}B`;
43+
};
44+
45+
return formatMemory;
46+
}

src/app/frontend/replicasetdetail/replicasetdetail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ <h1 flex class="md-title kd-replicasetdetail-app-name">
220220
</span>
221221
</td>
222222
<td class="kd-replicasetdetail-table-cell">
223-
0.4 CPU<!-- TODO(maciaszczykm): Fill with data and plot. -->
223+
{{::pod.metrics.cpuUsage}}
224224
</td>
225225
<td class="kd-replicasetdetail-table-cell">
226-
12 MB<!-- TODO(maciaszczykm): Fill with data and plot. -->
226+
{{::(pod.metrics.memoryUsage | kdMemory)}}
227227
</td>
228228
<td class="kd-replicasetdetail-table-cell">
229229
<span ng-if="::pod.podIP">

src/test/backend/replicasetpodsmetrics_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
package main
1616

1717
import (
18-
heapster "k8s.io/heapster/api/v1/types"
1918
"reflect"
2019
"testing"
20+
21+
heapster "k8s.io/heapster/api/v1/types"
2122
)
2223

2324
func TestCreateMetricPath(t *testing.T) {
@@ -27,9 +28,9 @@ func TestCreateMetricPath(t *testing.T) {
2728
metricName string
2829
expected string
2930
}{
30-
{"", make([]string, 0), "", "/api/v1/model/namespaces//pod-list//metrics/"},
31+
{"", make([]string, 0), "", "/model/namespaces//pod-list//metrics/"},
3132
{"default", []string{"a", "b"}, "cpu-usage",
32-
"/api/v1/model/namespaces/default/pod-list/a,b/metrics/cpu-usage"},
33+
"/model/namespaces/default/pod-list/a,b/metrics/cpu-usage"},
3334
}
3435
for _, c := range cases {
3536
actual := createMetricPath(c.namespace, c.podNames, c.metricName)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2015 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+
import filtersModule from 'common/filters/filters_module';
16+
17+
describe('Memory filter', () => {
18+
/** @type {function(!number):string} */
19+
let memoryFilter;
20+
21+
beforeEach(() => {
22+
angular.mock.module(filtersModule.name);
23+
angular.mock.inject((_kdMemoryFilter_) => { memoryFilter = _kdMemoryFilter_; });
24+
});
25+
26+
it('should format memory', () => {
27+
expect(memoryFilter(0)).toEqual('0 B');
28+
expect(memoryFilter(1)).toEqual('1 B');
29+
expect(memoryFilter(2)).toEqual('2 B');
30+
expect(memoryFilter(1000)).toEqual('1,000 B');
31+
expect(memoryFilter(1024)).toEqual('1,024 B');
32+
expect(memoryFilter(1025)).toEqual('1.001 KiB');
33+
expect(memoryFilter(7896)).toEqual('7.711 KiB');
34+
expect(memoryFilter(109809)).toEqual('107.235 KiB');
35+
expect(memoryFilter(768689899)).toEqual('733.080 MiB');
36+
expect(memoryFilter(768689899789)).toEqual('715.898 GiB');
37+
expect(memoryFilter(76868989978978)).toEqual('69.912 TiB');
38+
expect(memoryFilter(7686898997897878)).toEqual('6.827 PiB');
39+
expect(memoryFilter(768689899789787867898766)).toEqual('682,733,780.435 PiB');
40+
});
41+
});

0 commit comments

Comments
 (0)