Skip to content

Commit

Permalink
fix more linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristina Pathak committed Sep 20, 2022
1 parent 244541b commit 7f760cf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions cmd/otel-allocator/allocation/consistent_hashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestCanSetSingleTarget(t *testing.T) {
cols := makeNCollectors(3, 0, 0)
cols := makeNCollectors(3, 0)
c := newConsistentHashingAllocator(logger)
c.SetCollectors(cols)
c.SetTargets(makeNNewTargets(1, 3, 0))
Expand All @@ -35,7 +35,7 @@ func TestCanSetSingleTarget(t *testing.T) {
func TestRelativelyEvenDistribution(t *testing.T) {
numCols := 15
numItems := 10000
cols := makeNCollectors(numCols, 0, 0)
cols := makeNCollectors(numCols, 0)
var expectedPerCollector = float64(numItems / numCols)
expectedDelta := (expectedPerCollector * 1.5) - expectedPerCollector
c := newConsistentHashingAllocator(logger)
Expand All @@ -52,15 +52,15 @@ func TestRelativelyEvenDistribution(t *testing.T) {
}

func TestFullReallocation(t *testing.T) {
cols := makeNCollectors(10, 0, 0)
cols := makeNCollectors(10, 0)
c := newConsistentHashingAllocator(logger)
c.SetCollectors(cols)
c.SetTargets(makeNNewTargets(10000, 10, 0))
actualTargetItems := c.TargetItems()
assert.Len(t, actualTargetItems, 10000)
actualCollectors := c.Collectors()
assert.Len(t, actualCollectors, 10)
newCols := makeNCollectors(10, 0, 10)
newCols := makeNCollectors(10, 10)
c.SetCollectors(newCols)
updatedTargetItems := c.TargetItems()
assert.Len(t, updatedTargetItems, 10000)
Expand All @@ -77,15 +77,15 @@ func TestNumRemapped(t *testing.T) {
numInitialCols := 15
numFinalCols := 16
expectedDelta := float64((numFinalCols - numInitialCols) * (numItems / numFinalCols))
cols := makeNCollectors(numInitialCols, 0, 0)
cols := makeNCollectors(numInitialCols, 0)
c := newConsistentHashingAllocator(logger)
c.SetCollectors(cols)
c.SetTargets(makeNNewTargets(numItems, numInitialCols, 0))
actualTargetItems := c.TargetItems()
assert.Len(t, actualTargetItems, numItems)
actualCollectors := c.Collectors()
assert.Len(t, actualCollectors, numInitialCols)
newCols := makeNCollectors(numFinalCols, 0, 0)
newCols := makeNCollectors(numFinalCols, 0)
c.SetCollectors(newCols)
updatedTargetItems := c.TargetItems()
assert.Len(t, updatedTargetItems, numItems)
Expand Down
18 changes: 9 additions & 9 deletions cmd/otel-allocator/allocation/least_weighted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func makeNNewTargets(n int, numCollectors int, startingIndex int) map[string]*Ta
return toReturn
}

func makeNCollectors(n int, targetsForEach int, startingIndex int) map[string]*Collector {
func makeNCollectors(n int, startingIndex int) map[string]*Collector {
toReturn := map[string]*Collector{}
for i := startingIndex; i < n+startingIndex; i++ {
collector := fmt.Sprintf("collector-%d", i)
toReturn[collector] = &Collector{
Name: collector,
NumTargets: targetsForEach,
NumTargets: 0,
}
}
return toReturn
Expand All @@ -65,7 +65,7 @@ func makeNCollectors(n int, targetsForEach int, startingIndex int) map[string]*C
func TestSetCollectors(t *testing.T) {
s, _ := New("least-weighted", logger)

cols := makeNCollectors(3, 0, 0)
cols := makeNCollectors(3, 0)
s.SetCollectors(cols)

expectedColLen := len(cols)
Expand All @@ -81,7 +81,7 @@ func TestAddingAndRemovingTargets(t *testing.T) {
// prepare allocator with initial targets and collectors
s, _ := New("least-weighted", logger)

cols := makeNCollectors(3, 0, 0)
cols := makeNCollectors(3, 0)
s.SetCollectors(cols)

initTargets := makeNNewTargets(6, 3, 0)
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestAllocationCollision(t *testing.T) {
// prepare allocator with initial targets and collectors
s, _ := New("least-weighted", logger)

cols := makeNCollectors(3, 0, 0)
cols := makeNCollectors(3, 0)
s.SetCollectors(cols)
firstLabels := model.LabelSet{
"test": "test1",
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestAllocationCollision(t *testing.T) {
func TestNoCollectorReassignment(t *testing.T) {
s, _ := New("least-weighted", logger)

cols := makeNCollectors(3, 0, 0)
cols := makeNCollectors(3, 0)
s.SetCollectors(cols)

expectedColLen := len(cols)
Expand All @@ -170,7 +170,7 @@ func TestNoCollectorReassignment(t *testing.T) {
assert.Len(t, targetItems, expectedTargetLen)

// assign new set of collectors with the same names
newCols := makeNCollectors(3, 0, 0)
newCols := makeNCollectors(3, 0)
s.SetCollectors(newCols)

newTargetItems := s.TargetItems()
Expand All @@ -181,7 +181,7 @@ func TestNoCollectorReassignment(t *testing.T) {
func TestSmartCollectorReassignment(t *testing.T) {
s, _ := New("least-weighted", logger)

cols := makeNCollectors(4, 0, 0)
cols := makeNCollectors(4, 0)
s.SetCollectors(cols)

expectedColLen := len(cols)
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestCollectorBalanceWhenAddingAndRemovingAtRandom(t *testing.T) {
// prepare allocator with 3 collectors and 'random' amount of targets
s, _ := New("least-weighted", logger)

cols := makeNCollectors(3, 0, 0)
cols := makeNCollectors(3, 0)
s.SetCollectors(cols)

targets := makeNNewTargets(27, 3, 0)
Expand Down
17 changes: 9 additions & 8 deletions cmd/otel-allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

gokitlog "github.com/go-kit/log"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -174,7 +175,7 @@ func newServer(log logr.Logger, allocator allocation.Allocator, discoveryManager
router.HandleFunc("/jobs", s.JobHandler).Methods("GET")
router.HandleFunc("/jobs/{job_id}/targets", s.TargetsHandler).Methods("GET")
router.Path("/metrics").Handler(promhttp.Handler())
s.server = &http.Server{Addr: *listenAddr, Handler: router}
s.server = &http.Server{Addr: *listenAddr, Handler: router, ReadHeaderTimeout: 90 * time.Second}
return s, nil
}

Expand Down Expand Up @@ -214,7 +215,7 @@ func (s *server) JobHandler(w http.ResponseWriter, r *http.Request) {
for _, v := range s.allocator.TargetItems() {
displayData[v.JobName] = allocation.LinkJSON{Link: v.Link.Link}
}
jsonHandler(s.logger, w, r, displayData)
jsonHandler(s.logger, w, displayData)
}

// PrometheusMiddleware implements mux.MiddlewareFunc.
Expand All @@ -238,30 +239,30 @@ func (s *server) TargetsHandler(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
jobId, err := url.QueryUnescape(params["job_id"])
if err != nil {
errorHandler(err, w, r)
errorHandler(w)
return
}

if len(q) == 0 {
displayData := allocation.GetAllTargetsByJob(jobId, compareMap, s.allocator)
jsonHandler(s.logger, w, r, displayData)
jsonHandler(s.logger, w, displayData)

} else {
tgs := allocation.GetAllTargetsByCollectorAndJob(q[0], jobId, compareMap, s.allocator)
// Displays empty list if nothing matches
if len(tgs) == 0 {
jsonHandler(s.logger, w, r, []interface{}{})
jsonHandler(s.logger, w, []interface{}{})
return
}
jsonHandler(s.logger, w, r, tgs)
jsonHandler(s.logger, w, tgs)
}
}

func errorHandler(err error, w http.ResponseWriter, r *http.Request) {
func errorHandler(w http.ResponseWriter) {
w.WriteHeader(500)
}

func jsonHandler(logger logr.Logger, w http.ResponseWriter, r *http.Request, data interface{}) {
func jsonHandler(logger logr.Logger, w http.ResponseWriter, data interface{}) {
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(data)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/otel-allocator/watcher/promOperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
allocatorconfig "github.com/open-telemetry/opentelemetry-operator/cmd/otel-allocator/config"

"github.com/go-kit/log"
"github.com/go-logr/logr"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/prometheus-operator/prometheus-operator/pkg/assets"
monitoringclient "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
Expand All @@ -34,7 +33,7 @@ import (
"k8s.io/client-go/tools/cache"
)

func newCRDMonitorWatcher(logger logr.Logger, config allocatorconfig.CLIConfig) (*PrometheusCRWatcher, error) {
func newCRDMonitorWatcher(config allocatorconfig.CLIConfig) (*PrometheusCRWatcher, error) {
mClient, err := monitoringclient.NewForConfig(config.ClusterConfig)
if err != nil {
return nil, err
Expand Down

0 comments on commit 7f760cf

Please sign in to comment.