Skip to content

Commit

Permalink
fix: metrics issues
Browse files Browse the repository at this point in the history
  • Loading branch information
butschi84 committed Dec 10, 2023
1 parent 3534fec commit 65b4f27
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
10 changes: 6 additions & 4 deletions f2soperator/operation/operator/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ func scaleDeployments() {
for _, function := range functions.Items {
var resultScale int
currentAvailableReplicas, availableReplicasErr := prometheus.ReadCurrentPrometheusMetricValue(&configuration.ActiveConfiguration, fmt.Sprintf("kube_deployment_status_replicas_available{functionname=\"%s\"}", function.Name))
requiredContainers, requiredContainersErr := prometheus.ReadCurrentPrometheusMetricValue(&configuration.ActiveConfiguration, fmt.Sprintf("job:function_containers_required:containers{functionname=\"%s\"}", function.Name))
if availableReplicasErr != nil || requiredContainersErr != nil {
// no invocations / metrics => scale to minimum
logging.Error("there was an error when trying to read metric [kube_deployment_status_replicas_available] or [job:function_containers_required:containers]. setting result scale to 0")
requiredContainers, requiredContainersErr := prometheus.ReadCurrentPrometheusMetricValue(&configuration.ActiveConfiguration, fmt.Sprintf("job:function_containers_required:containers{functionname=\"%s\"} or vector(0)", function.Name))
if availableReplicasErr != nil {
logging.Error("there was an error when trying to read metric [kube_deployment_status_replicas_available]. setting result-scale to 0")
resultScale = 0
} else if requiredContainersErr != nil {
logging.Error("there was an error when trying to read metric [job:function_containers_required:containers]. setting result-scale to 0")
resultScale = 0
} else {
resultScale = int(math.Ceil(requiredContainers))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewForConfig(c *rest.Config, scheme *runtime.Scheme) (*V1Alpha1Client, erro
config.NegotiatedSerializer = serializer.NewCodecFactory(scheme)
config.UserAgent = rest.DefaultKubernetesUserAgent()

logging.Info("Rest Client Group Version:", fmt.Sprintf("%s", config.GroupVersion))
logging.Debug("Rest Client Group Version:", fmt.Sprintf("%s", config.GroupVersion))

client, err := rest.RESTClientFor(&config)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type functionClient struct {

func (c *functionClient) List(opts metav1.ListOptions) (*v1alpha1.FunctionList, error) {
result := v1alpha1.FunctionList{}
logging.Info("get function list for namespace", c.ns)
logging.Info(fmt.Sprintf("get function list for namespace %s", c.ns))
ctx := context.TODO()
err := c.restClient.
Get().
Expand All @@ -36,7 +36,7 @@ func (c *functionClient) List(opts metav1.ListOptions) (*v1alpha1.FunctionList,
//VersionedParams(&opts, scheme.ParameterCodec).
Do(ctx).
Into(&result)
logging.Error(fmt.Sprintf("%s", err))
logging.Error(fmt.Sprintf("could not get function list for namespace %s: %s", c.ns, err.Error()))
return &result, err
}

Expand Down Expand Up @@ -104,6 +104,6 @@ func (c *functionClient) Delete(uid string, opts metav1.DeleteOptions) error {
}
}

logging.Error(fmt.Sprint("function could not be found"))
logging.Error(fmt.Sprint("function with uid %s could not be found", uid))
return fmt.Errorf("function could not be found")
}
9 changes: 9 additions & 0 deletions helm/templates/grafana/grafana-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-config
namespace: f2s
data:
f2s-grafana-config.ini: |
[auth.anonymous]
enabled = true
7 changes: 7 additions & 0 deletions helm/templates/grafana/grafana-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ spec:
- name: grafana-provisioning-dashboards
mountPath: /var/lib/grafana/provisioning/dashboards
readOnly: true
- name: grafana-config
mountPath: /etc/grafana/custom.ini
subPath: f2s-grafana-config.ini
readOnly: true
volumes:
- name: grafana-config
configMap:
name: grafana-config
- name: grafana-storage
emptyDir: {}
- name: grafana-provisioning-datasources
Expand Down

0 comments on commit 65b4f27

Please sign in to comment.