Przeglądaj źródła

ComputeCostData: don't return on prometheus errors

This will let cost-model run as only an exporter (without depending
on a Prometheus to query from). It will output allocation data
that is only comprised of _requests_ for CPU and memory. This is
possible because of the recent change to ComputeCostData that
removes the dependency on Prometheus for CPU and memory requests.

Refactored docs; instructions for exporter-only
Michael Dresser 5 lat temu
rodzic
commit
0bf4335e86
5 zmienionych plików z 30 dodań i 20 usunięć
  1. 1 4
      CONTRIBUTING.md
  2. 23 0
      INSTALL.md
  3. 2 0
      README.md
  4. 0 14
      deploying-as-a-pod.md
  5. 4 2
      pkg/costmodel/costmodel.go

+ 1 - 4
CONTRIBUTING.md

@@ -13,10 +13,7 @@ Follow these steps to build from source and deploy:
 
 1. `docker build --rm -f "Dockerfile" -t <repo>/kubecost-cost-model:<tag> .`
 2. Edit the [pulled image](https://github.com/kubecost/cost-model/blob/master/kubernetes/deployment.yaml#L25) in the deployment.yaml to <repo>/kubecost-cost-model:<tag>
-3. Set [this environment variable](https://github.com/kubecost/cost-model/blob/master/kubernetes/deployment.yaml#L33) to the address of your prometheus server
-4. `kubectl create namespace cost-model`
-5. `kubectl apply -f kubernetes/ --namespace cost-model`
-6. `kubectl port-forward --namespace cost-model service/cost-model 9003`
+3. Follow the [install instructions](INSTALL.MD)
 
 To test, build the cost-model docker container and then push it to a Kubernetes cluster with a running Prometheus.
 

+ 23 - 0
INSTALL.md

@@ -0,0 +1,23 @@
+# Installation
+
+> If you want Kubecost's full functionality, consider following our standard [installation instructions](https:/docs.kubecost.com/install). This is the fastest way to see Kubecost's potential with more performant queries and a featureful UI. The following instructions are for deployments of _only_ the cost-model repository.
+
+Kubecost's open source `cost-model` can be deployed in two different ways: as only a Prometheus exporter or as both a Prometheus exporter and consumer.
+
+## Standard Install
+
+The standard installation requires Prometheus and [kube-state-metrics](https://github.com/kubernetes/kube-state-metrics) to be running.
+
+> If you wish to deploy in a namespace other than `cost-model`, be sure to change the namespace in the `apply` command _and_ edit the `ClusterRoleBinding` to bind the service in your chosen namespace.
+
+1. Set [this environment variable](https://github.com/kubecost/cost-model/blob/master/kubernetes/deployment.yaml#L33) to the address of your prometheus server
+2. `kubectl create namespace cost-model`
+3. `kubectl apply -f kubernetes/ --namespace cost-model`
+
+
+Access the deployment by running `kubectl port-forward --namespace cost-model service/cost-model 9003`. You will have [http://localhost:9003/metrics](http://localhost:9003/metrics) which contains the exported Prometheus metrics as well as the rest of the API available in places like [http://localhost:9003/costDataModel?timeWindow=1d](http://localhost:9003/costDataModel?timeWindow=1d).
+
+
+## Exporter Only (no Prometheus dependency)
+
+Follow the Standard Install instructions, but skip setting the environment variable. In this configuration, `container_allocation...` metrics will ONLY contain requests, not usage, because usage information requires a configured Prometheus. Additionally, the API provided as part of `cost-model` will not function correctly because it relies on Prometheus.

+ 2 - 0
README.md

@@ -25,6 +25,8 @@ Here is a summary of features enabled by this cost model:
 You can deploy Kubecost on any Kubernetes 1.8+ cluster in a matter of minutes, if not seconds. 
 Visit the Kubecost docs for [recommended install options](https://docs.kubecost.com/install). Compared to building from source, installing from Helm is faster and includes all necessary dependencies. 
 
+If you prefer to install _only_ the open source code (or want to use `cost-model` as just a metric exporter), see [`INSTALL.md`](INSTALL.md) for instructions.
+
 ## Contributing
 
 We :heart: pull requests! See [`CONTRIBUTING.md`](CONTRIBUTING.md) for information on buiding the project from source

+ 0 - 14
deploying-as-a-pod.md

@@ -1,14 +0,0 @@
-## Deploying as a pod
-
-See this page for all [Kubecost install options](http://docs.kubecost.com/install).
-
-If you would like to deploy the cost model (w/o dashboards) directly a pod on your cluster, complete the steps listed below. 
-
-1. Set [this environment variable](https://github.com/kubecost/cost-model/blob/c211fbc1244a9da9667c7180a9e4c7f988d7978a/kubernetes/deployment.yaml#L33) to the address of your prometheus server
-2. `kubectl create namespace cost-model`
-3. `kubectl apply -f kubernetes/ --namespace cost-model`
-4. `kubectl port-forward --namespace cost-model service/cost-model 9003`
-
-To test that the server is running, you can hit [http://localhost:9003/costDataModel?timeWindow=1d](http://localhost:9003/costDataModel?timeWindow=1d)
-
-**Note:** This approach provides less functionality compared to other install options referenced above. Also, Prometheus and kube-state-metrics are external dependencies for this installation path.

+ 4 - 2
pkg/costmodel/costmodel.go

@@ -297,14 +297,16 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, cp costAnalyze
 		}
 
 		// ErrorCollection is an collection of errors wrapped in a single error implementation
-		return nil, ctx.ErrorCollection()
+		// We opt to not return an error for the sake of running as a pure exporter.
+		log.Warningf("ComputeCostData: continuing despite prometheus errors: %s", ctx.ErrorCollection().Error())
 	}
 
 	defer measureTime(time.Now(), profileThreshold, "ComputeCostData: Processing Query Data")
 
 	normalizationValue, err := getNormalization(resNormalization)
 	if err != nil {
-		return nil, fmt.Errorf("Error parsing normalization values from %s: %s", queryNormalization, err.Error())
+		// We opt to not return an error for the sake of running as a pure exporter.
+		log.Warningf("ComputeCostData: continuing despite error parsing normalization values from %s: %s", queryNormalization, err.Error())
 	}
 
 	nodes, err := cm.GetNodeCost(cp)