Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Refactor code, move metricsprovider to internal

Signed-off-by: Abdul Qadeer <aqadeer@paypal.com>
  • Loading branch information
Abdul Qadeer committed Feb 22, 2021
1 parent c9a01d4 commit dd7c0c0
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 407 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,13 @@ GET /watcher

This will return metrics for all nodes. A query parameter to filter by host can be added with `host`.

## Third Party Client Configuration
- To use the Kubernetes metric server client, please configure environment varirables `METRIC_CLIENT=k8s` and your `KUBE_CONFIG` to your
kubernetes client configuration file path if running out of cluster.

- To use the prometheus client, please configure environment variables as `METRIC_CLIENT=prometheus`, and configure
`METRIC_HOST` and `METRIC_AUTH_TOKEN` to your Prometheus endpoint and token. Please ignore `PROM_TOKEN` as empty string if no authentication
is needed to access the Prometheus APIs. When using the prometheus in a cluster, the default endpoint is
`http://prometheus-k8s.monitoring.svc.cluster.local:9090`. You need to configure `PROM_HOST` if your Prometheus endpoint is different.

- To use the signalFx client, please configure environment variables as `METRIC_CLIENT=signalfx`, and configure
`METRIC_HOST` and `METRIC_AUTH_TOKEN` to your signalFx endpoint and token. Please ignore `METRIC_AUTH_TOKEN` as empty string if no authentication
is needed to access the signalFx APIs.
## Metrics Provider Configuration
- By default Kubernetes Metrics Server client is configured. Set `KUBE_CONFIG` env var to your kubernetes client configuration file path if running out of cluster.

- To use the Prometheus client, please configure environment variables `METRICS_PROVIDER_NAME`, `METRICS_PROVIDER_ADDRESS` and `METRICS_PROVIDER_TOKEN` to `Prometheus`, Prometheus address and auth token. Please do not set `METRICS_PROVIDER_TOKEN` if no authentication
is needed to access the Prometheus APIs. Default value of address set is `http://prometheus-k8s:9090` for Prometheus client.

- To use the SignalFx client, please configure `METRICS_PROVIDER_NAME`, `METRICS_PROVIDER_ADDRESS` and `METRICS_PROVIDER_TOKEN` to `SignalFx`, SignalFx address and auth token respectively. Default value of address set is `https://api.signalfx.com` for Prometheus client.

## Deploy `load-watcher` as a service
To deploy `load-watcher` as a monitoring service in your Kubernetes cluster, you can run the following.
Expand Down
39 changes: 0 additions & 39 deletions load-watcher-client.go

This file was deleted.

23 changes: 12 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ limitations under the License.
package main

import (
"log"

"github.com/paypal/load-watcher/pkg/client"
"github.com/paypal/load-watcher/pkg/utils"
"github.com/paypal/load-watcher/pkg/watcher"
"github.com/paypal/load-watcher/pkg/watcher/api"
log "github.com/sirupsen/logrus"
)


func main() {
utils.InitEnvVars()
cl, err := client.NewFetcherClient(utils.MetricProviderType, utils.MetricEndpoint, utils.MetricAuthToken)
client, err := api.NewLibraryClient(watcher.EnvMetricProviderOpts)
if err != nil {
log.Fatalf("unable to create new client: %v", err)
log.Fatalf("unable to create client: %v", err)
}
w := watcher.NewWatcher(cl.Fetcher)
w.StartWatching()
metrics, err := client.GetLatestWatcherMetrics()
if err != nil {
log.Errorf("unable to get watcher metrics: %v", err)
}
log.Infof("received metrics: %v", metrics)

// Keep the watcher server up
select {}
}
}
6 changes: 2 additions & 4 deletions manifests/load-watcher-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
- name: watcher
image: chenw/load-watcher:latest
env:
- name: METRIC_CLIENT
- name: METRICS_PROVIDER_NAME
value: prometheus
ports:
- containerPort: 2020
Expand All @@ -34,12 +34,10 @@ metadata:
labels:
app: load-watcher
spec:
externalTrafficPolicy: Local
ports:
- name: http
port: 2020
protocol: TCP
targetPort: 2020
selector:
app: load-watcher
type: LoadBalancer
app: load-watcher
13 changes: 0 additions & 13 deletions pkg/client/client.go

This file was deleted.

42 changes: 0 additions & 42 deletions pkg/client/fetcher.go

This file was deleted.

109 changes: 0 additions & 109 deletions pkg/client/loadwatcher.go

This file was deleted.

62 changes: 0 additions & 62 deletions pkg/utils/utils.go

This file was deleted.

18 changes: 8 additions & 10 deletions pkg/watcher/fetcher.go → pkg/watcher/api/api.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 PayPal
Copyright 2021 PayPal
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,14 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package watcher
package api

// Interface to be implemented by any metrics provider client to interact with Watcher
type FetcherClient interface {
// Return the client name
Name() string
// Fetch metrics for given host
FetchHostMetrics(host string, window *Window) ([]Metric, error)
// Fetch metrics for all hosts
FetchAllHostsMetrics(window *Window) (map[string][]Metric, error)
import "github.com/paypal/load-watcher/pkg/watcher"

// Watcher Client API
type Client interface {
// Returns latest metrics present in load Watcher cache
GetLatestWatcherMetrics() (*watcher.WatcherMetrics, error)
}
Loading

0 comments on commit dd7c0c0

Please # to comment.