Skip to content

Commit

Permalink
Release 1.0.1 (#15)
Browse files Browse the repository at this point in the history
* Remove trailing commas task string (#11)

removed trailing commas from Task#String()

* validated prom endpoint + updated test code. (#13)

validated prom endpoint + updated test code.

WithPrometheusEndpoint(...) Option also validates the endpoint.
This ensures that the datafetcher has a valid endpoint to work with.

Updated workflow to now test with docker-compose installation

* Badges (#14)

added badges for godoc and workflow status
  • Loading branch information
pradykaushik authored Jul 1, 2020
1 parent 0651ba5 commit 9ba66ca
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Task-Ranker
name: Build and Test

on:
push:
Expand Down Expand Up @@ -34,4 +34,8 @@ jobs:
run: go build -v .

- name: Test
run: go test -v ./...
run: |
./create_test_env
sleep 3s
go test -v ./...
./tear_down_test_env
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Task Ranker
# Task Ranker
[![GoDoc](https://godoc.org/github.com/pradykaushik/task-ranker?status.svg)](https://godoc.org/github.com/pradykaushik/task-ranker)
![Build](https://github.com/pradykaushik/task-ranker/workflows/Build%20and%20Test/badge.svg)

Rank tasks running as docker containers in a cluster.

Task Ranker runs as a cron job on a specified schedule. Each time the task ranker is run,
Expand Down
6 changes: 6 additions & 0 deletions datafetcher/prometheus/dataFetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/prometheus/client_golang/api"
"github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
"net/http"
"time"
)

Expand Down Expand Up @@ -59,6 +60,11 @@ func WithPrometheusEndpoint(endpoint string) Option {
if endpoint == "" {
return errors.New("invalid endpoint")
}
// Validating the prometheus endpoint.
_, err := http.Get(endpoint + "/metrics")
if err != nil {
return errors.Wrap(err, "invalid endpoint for prometheus server")
}
f.endpoint = endpoint
return nil
}
Expand Down
8 changes: 1 addition & 7 deletions entities/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,5 @@ func (t Task) GetHostname() string {
}

func (t Task) String() string {
var buf bytes.Buffer
buf.WriteString("[")
buf.WriteString(fmt.Sprintf("TaskID = %s,", t.ID))
buf.WriteString(fmt.Sprintf("Hostname = %s,", t.Hostname))
buf.WriteString(fmt.Sprintf("Weight = %f,", t.Weight))
buf.WriteString("]")
return buf.String()
return fmt.Sprintf("[TaskID = %s, Hostname = %s, Weight = %f]", t.ID, t.Hostname, t.Weight)
}
3 changes: 3 additions & 0 deletions ranker_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func initTaskRanker(strategy string) (*TaskRanker, error) {

prometheusDataFetcher, err = prometheus.NewDataFetcher(
prometheus.WithPrometheusEndpoint("http://localhost:9090"))
if err != nil {
return nil, err
}

dummyReceiver = new(dummyTaskRanksReceiver)
tRanker, err = New(
Expand Down

0 comments on commit 9ba66ca

Please sign in to comment.