Merge pull request #985 from jimmidyson/cleanup-unused

Cleanup code from gometalinter output
This commit is contained in:
Jimmi Dyson 2015-11-27 22:16:52 +00:00
commit 0dbcb66c07
20 changed files with 27 additions and 213 deletions

View File

@ -160,9 +160,9 @@ func (self *Client) httpGetJsonData(data, postData interface{}, url, infoName st
var err error
if postData != nil {
data, err := json.Marshal(postData)
if err != nil {
return fmt.Errorf("unable to marshal data: %v", err)
data, marshalErr := json.Marshal(postData)
if marshalErr != nil {
return fmt.Errorf("unable to marshal data: %v", marshalErr)
}
resp, err = http.Post(url, "application/json", bytes.NewBuffer(data))
} else {

View File

@ -92,16 +92,16 @@ func (self *Client) httpGetResponse(postData interface{}, url, infoName string)
var err error
if postData != nil {
data, err := json.Marshal(postData)
if err != nil {
return nil, fmt.Errorf("unable to marshal data: %v", err)
data, marshalErr := json.Marshal(postData)
if marshalErr != nil {
return nil, fmt.Errorf("unable to marshal data: %v", marshalErr)
}
resp, err = http.Post(url, "application/json", bytes.NewBuffer(data))
} else {
resp, err = http.Get(url)
}
if err != nil {
return nil, fmt.Errorf("unable to get %q from %q: %v", infoName, url, err)
return nil, fmt.Errorf("unable to post %q to %q: %v", infoName, url, err)
}
if resp == nil {
return nil, fmt.Errorf("received empty response for %q from %q", infoName, url)

View File

@ -15,8 +15,9 @@
package collector
import (
"github.com/google/cadvisor/info/v1"
"time"
"github.com/google/cadvisor/info/v1"
)
type Config struct {

View File

@ -15,8 +15,9 @@
package collector
import (
"github.com/google/cadvisor/info/v1"
"time"
"github.com/google/cadvisor/info/v1"
)
// TODO(vmarmol): Export to a custom metrics type when that is available.

View File

@ -87,8 +87,7 @@ func RootDir() string {
type storageDriver string
const (
devicemapperStorageDriver storageDriver = "devicemapper"
aufsStorageDriver storageDriver = "aufs"
aufsStorageDriver storageDriver = "aufs"
)
type dockerFactory struct {

View File

@ -48,16 +48,6 @@ type dockerContainerHandler struct {
aliases []string
machineInfoFactory info.MachineInfoFactory
// Path to the libcontainer config file.
libcontainerConfigPath string
// Path to the libcontainer state file.
libcontainerStatePath string
// TODO(vmarmol): Remove when we depend on a newer Docker.
// Path to the libcontainer pid file.
libcontainerPidPath string
// Absolute path to the cgroup hierarchies of this container.
// (e.g.: "cpu" -> "/sys/fs/cgroup/cpu/test")
cgroupPaths map[string]string

View File

@ -17,7 +17,6 @@ package libcontainer
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
@ -146,8 +145,6 @@ func isIgnoredDevice(ifName string) bool {
return false
}
const netstatsLine = `%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d`
func scanInterfaceStats(netStatsFile string) ([]info.InterfaceStats, error) {
file, err := os.Open(netStatsFile)
if err != nil {
@ -213,6 +210,7 @@ func setInterfaceStatValues(fields []string, pointers []*uint64) error {
return nil
}
/*
func tcpStatsFromProc(rootFs string, pid int, file string) (info.TcpStat, error) {
tcpStatsFile := path.Join(rootFs, "proc", strconv.Itoa(pid), file)
@ -287,6 +285,7 @@ func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) {
return stats, nil
}
*/
func GetProcesses(cgroupManager cgroups.Manager) ([]int, error) {
pids, err := cgroupManager.GetPids()

View File

@ -115,9 +115,6 @@ type watch struct {
request *Request
// a channel used to send event back to the caller.
eventChannel *EventChannel
// unique identifier of a watch that is used as a key in events' watchers
// map
id int
}
func NewEventChannel(watchId int) *EventChannel {

View File

@ -476,17 +476,6 @@ func timeEq(t1, t2 time.Time, tolerance time.Duration) bool {
return false
}
func durationEq(a, b time.Duration, tolerance time.Duration) bool {
if a > b {
a, b = b, a
}
diff := a - b
if diff <= tolerance {
return true
}
return false
}
const (
// 10ms, i.e. 0.01s
timePrecision time.Duration = 10 * time.Millisecond
@ -522,14 +511,6 @@ func (a *ContainerStats) StatsEq(b *ContainerStats) bool {
return true
}
// Saturate CPU usage to 0.
func calculateCpuUsage(prev, cur uint64) uint64 {
if prev > cur {
return 0
}
return cur - prev
}
// Event contains information general to events such as the time at which they
// occurred, their specific type, and the actual event. Event types are
// differentiated by the EventType field of Event.

View File

@ -33,6 +33,9 @@ func TestHealthzOk(t *testing.T) {
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if string(body) != "ok" {
t.Fatalf("cAdvisor returned unexpected healthz status of %q", body)

View File

@ -443,6 +443,9 @@ func (c *containerData) updateSpec() error {
}
customMetrics, err := c.collectorManager.GetSpec()
if err != nil {
return err
}
if len(customMetrics) > 0 {
spec.HasCustomMetrics = true
spec.CustomMetrics = customMetrics

View File

@ -21,7 +21,6 @@ import (
"fmt"
"os"
"path"
"regexp"
"strconv"
"strings"
"sync"
@ -190,7 +189,6 @@ type manager struct {
quitChannels []chan error
cadvisorContainer string
inHostNamespace bool
dockerContainersRegexp *regexp.Regexp
loadReader cpuload.CpuLoadReader
eventHandler events.EventManager
startupTime time.Time
@ -1195,7 +1193,10 @@ func (m *manager) DockerInfo() (DockerStatus, error) {
}
if val, ok := info["DriverStatus"]; ok {
var driverStatus [][]string
err = json.Unmarshal([]byte(val), &driverStatus)
err := json.Unmarshal([]byte(val), &driverStatus)
if err != nil {
return DockerStatus{}, err
}
out.DriverStatus = make(map[string]string)
for _, v := range driverStatus {
if len(v) == 2 {

View File

@ -144,10 +144,6 @@ func printShares(shares *uint64) string {
return fmt.Sprintf("%d", *shares)
}
func toMegabytes(bytes uint64) float64 {
return float64(bytes) / (1 << 20)
}
// Size after which we consider memory to be "unlimited". This is not
// MaxInt64 due to rounding by the kernel.
const maxMemorySize = uint64(1 << 62)
@ -166,16 +162,6 @@ func printUnit(bytes uint64) string {
return ByteSize(bytes).Unit()
}
func toMemoryPercent(usage uint64, spec *info.ContainerSpec, machine *info.MachineInfo) int {
// Saturate limit to the machine size.
limit := uint64(spec.Memory.Limit)
if limit > uint64(machine.MemoryCapacity) {
limit = uint64(machine.MemoryCapacity)
}
return int((usage * 100) / limit)
}
func serveContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error {
start := time.Now()

View File

@ -36,7 +36,6 @@ var (
const (
errAlreadyExists string = "Error 409: Already Exists"
queryLimit int64 = 200
)
type Client struct {

View File

@ -16,11 +16,12 @@ package redis
import (
"encoding/json"
"sync"
"time"
redis "github.com/garyburd/redigo/redis"
info "github.com/google/cadvisor/info/v1"
storage "github.com/google/cadvisor/storage"
"sync"
"time"
)
type redisStorage struct {
@ -78,7 +79,6 @@ func (self *redisStorage) AddStats(ref info.ContainerReference, stats *info.Cont
b, _ := json.Marshal(detail)
if self.readyToFlush() {
seriesToFlush = b
b = nil
self.lastWrite = time.Now()
}
}()

View File

@ -77,17 +77,6 @@ func TimeEq(t1, t2 time.Time, tolerance time.Duration) bool {
return false
}
func durationEq(a, b time.Duration, tolerance time.Duration) bool {
if a > b {
a, b = b, a
}
diff := a - b
if diff <= tolerance {
return true
}
return false
}
const (
// 10ms, i.e. 0.01s
timePrecision time.Duration = 10 * time.Millisecond

View File

@ -1,44 +0,0 @@
// Copyright 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fs
import (
"io"
"os"
)
type osFS struct{}
func (osFS) Open(name string) (File, error) { return os.Open(name) }
func (osFS) Stat(name string) (os.FileInfo, error) { return os.Stat(name) }
var fs FileSystem = osFS{}
type FileSystem interface {
Open(name string) (File, error)
}
type File interface {
io.ReadWriteCloser
}
// Useful for tests. Not thread safe.
func ChangeFileSystem(filesystem FileSystem) {
fs = filesystem
}
func Open(name string) (File, error) {
return fs.Open(name)
}

View File

@ -1,35 +0,0 @@
// Copyright 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package mockfs
import "bytes"
type FakeFile struct {
bytes.Buffer
Name string
}
func (self *FakeFile) Close() error {
return nil
}
func AddTextFile(mockfs *MockFileSystem, name, content string) *FakeFile {
f := &FakeFile{
Name: name,
Buffer: *bytes.NewBufferString(content),
}
mockfs.EXPECT().Open(name).Return(f, nil).AnyTimes()
return f
}

View File

@ -1,55 +0,0 @@
// Copyright 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Automatically generated by MockGen. DO NOT EDIT!
// Source: github.com/google/cadvisor/utils/fs (interfaces: FileSystem)
package mockfs
import (
gomock "github.com/golang/mock/gomock"
fs "github.com/google/cadvisor/utils/fs"
)
// Mock of FileSystem interface
type MockFileSystem struct {
ctrl *gomock.Controller
recorder *_MockFileSystemRecorder
}
// Recorder for MockFileSystem (not exported)
type _MockFileSystemRecorder struct {
mock *MockFileSystem
}
func NewMockFileSystem(ctrl *gomock.Controller) *MockFileSystem {
mock := &MockFileSystem{ctrl: ctrl}
mock.recorder = &_MockFileSystemRecorder{mock}
return mock
}
func (_m *MockFileSystem) EXPECT() *_MockFileSystemRecorder {
return _m.recorder
}
func (_m *MockFileSystem) Open(_param0 string) (fs.File, error) {
ret := _m.ctrl.Call(_m, "Open", _param0)
ret0, _ := ret[0].(fs.File)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockFileSystemRecorder) Open(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Open", arg0)
}

View File

@ -155,7 +155,6 @@ func (self *OomParser) StreamOoms(outStream chan *OomInstance) {
}
line = <-lineChannel
}
in_oom_kernel_log = false
outStream <- oomCurrentInstance
}
}