Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add query expressions management by prom-adapter-config #560

Merged
merged 32 commits into from
Dec 13, 2022

Conversation

saikey0379
Copy link
Contributor

@saikey0379 saikey0379 commented Sep 17, 2022

What type of PR is this?

  • Add support for automatic rendering of query expressions
  • More user-friendly query expressions management capabilities
  • Add support for extension-labels

Examples

Make sure you include metrics in your prometheus-adapter-config file

externalRules:
- seriesQuery: 'connection_count'
  metricsQuery: 'sum(<<.Series>>{<<.LabelMatchers>>})'
  resources:
    namespaced: false
  name:
    matches: "^(.*)_count"
    as: "${1}_per_second"

Add args

    command:
    - /craned
    args:
    ...
    - --prometheus-adapter-configmap=crane-system/prometheus-adapter-config/config.yaml
    #- --prometheus-adapter-config=/etc/adapter/config.yaml

Modify ehpa config

Delete annotation for metric-query "metric-query.autoscaling.crane.io: xxx"

Add metric config

  metrics:
  - external:
      metric:
        name: connection_per_second
        selector:
          matchLabels:
            pod_namespace: "default"
            pod_project: "test"
      target:
        averageValue: "30"
        type: AverageValue
    type: External

Test

# kubectl get tsp test -o yaml | grep expression
    expressionQuery:
      expression: sum(connection_count{pod_namespace="default",pod_project="test"})

Extension-labels

Add annotation for extension-labels

apiVersion: autoscaling.crane.io/v1alpha1
kind: EffectiveHorizontalPodAutoscaler
metadata:
  name: test
  namespace: default
  annotations:
    prom-adapter.autoscaling.crane.io/extension-labels: |
      [{"cluster":"prod"}]

Test

# kubectl get tsp test -o yaml | grep expression
    expressionQuery:
      expression: sum(connection_count{cluster="prod",pod_namespace="default",pod_project="test"})

@github-actions
Copy link
Contributor

github-actions bot commented Sep 17, 2022

🎉 Successfully Build Images.
Now Support ARM Platforms.
Comment Post Time: 2022-12-13 15:18
Git Version: 4a9c9c7

Docker Registry

Overview: https://hub.docker.com/u/gocrane

Image Pull Command
crane-agent:pr-560-4a9c9c7 docker pull gocrane/crane-agent:pr-560-4a9c9c7
dashboard:pr-560-4a9c9c7 docker pull gocrane/dashboard:pr-560-4a9c9c7
metric-adapter:pr-560-4a9c9c7 docker pull gocrane/metric-adapter:pr-560-4a9c9c7
craned:pr-560-4a9c9c7 docker pull gocrane/craned:pr-560-4a9c9c7

Quick Deploy - Helm

helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
                   --set craned.image.repository=gocrane/craned \
                   --set craned.image.tag=pr-560-4a9c9c7 \
                   --set metricAdapter.image.repository=gocrane/metric-adapter \
                   --set metricAdapter.image.tag=pr-560-4a9c9c7 \
                   --set craneAgent.image.repository=gocrane/crane-agent \
                   --set craneAgent.image.tag=pr-560-4a9c9c7 \
                   --set cranedDashboard.image.repository=gocrane/dashboard \
                   --set cranedDashboard.image.tag=pr-560-4a9c9c7 crane/crane

Coding Registry

Overview: https://finops.coding.net/public-artifacts/gocrane/crane/packages

Image Pull Command
crane-agent:pr-560-4a9c9c7 docker pull finops-docker.pkg.coding.net/gocrane/crane/crane-agent:pr-560-4a9c9c7
dashboard:pr-560-4a9c9c7 docker pull finops-docker.pkg.coding.net/gocrane/crane/dashboard:pr-560-4a9c9c7
metric-adapter:pr-560-4a9c9c7 docker pull finops-docker.pkg.coding.net/gocrane/crane/metric-adapter:pr-560-4a9c9c7
craned:pr-560-4a9c9c7 docker pull finops-docker.pkg.coding.net/gocrane/crane/craned:pr-560-4a9c9c7

Quick Deploy - Helm

helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
                   --set craned.image.repository=finops-docker.pkg.coding.net/gocrane/crane/craned \
                   --set craned.image.tag=pr-560-4a9c9c7 \
                   --set metricAdapter.image.repository=finops-docker.pkg.coding.net/gocrane/crane/metric-adapter \
                   --set metricAdapter.image.tag=pr-560-4a9c9c7 \
                   --set craneAgent.image.repository=finops-docker.pkg.coding.net/gocrane/crane/crane-agent \
                   --set craneAgent.image.tag=pr-560-4a9c9c7 \
                   --set cranedDashboard.image.repository=finops-docker.pkg.coding.net/gocrane/crane/dashboard \
                   --set cranedDashboard.image.tag=pr-560-4a9c9c7 crane/crane

Ghcr Registry

Overview: https://github.com/orgs/gocrane/packages?repo_name=crane

Image Pull Command
crane-agent:pr-560-4a9c9c7 docker pull ghcr.io/gocrane/crane/crane-agent:pr-560-4a9c9c7
dashboard:pr-560-4a9c9c7 docker pull ghcr.io/gocrane/crane/dashboard:pr-560-4a9c9c7
metric-adapter:pr-560-4a9c9c7 docker pull ghcr.io/gocrane/crane/metric-adapter:pr-560-4a9c9c7
craned:pr-560-4a9c9c7 docker pull ghcr.io/gocrane/crane/craned:pr-560-4a9c9c7

Quick Deploy - Helm

helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
                   --set craned.image.repository=ghcr.io/gocrane/crane/craned \
                   --set craned.image.tag=pr-560-4a9c9c7 \
                   --set metricAdapter.image.repository=ghcr.io/gocrane/crane/metric-adapter \
                   --set metricAdapter.image.tag=pr-560-4a9c9c7 \
                   --set craneAgent.image.repository=ghcr.io/gocrane/crane/crane-agent \
                   --set craneAgent.image.tag=pr-560-4a9c9c7 \
                   --set cranedDashboard.image.repository=ghcr.io/gocrane/crane/dashboard \
                   --set cranedDashboard.image.tag=pr-560-4a9c9c7 crane/crane

@github-actions github-actions bot added deploy documentation Improvements or additions to documentation workflows labels Sep 30, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 30, 2022

🎊 PR Preview c177e23 has been successfully built and deployed to https://gocrane-crane-preview-pr-560.surge.sh

🕐 Build time: 0.011s

🤖 By surge-preview

@github-actions github-actions bot removed deploy documentation Improvements or additions to documentation workflows labels Sep 30, 2022
@github-actions github-actions bot added documentation Improvements or additions to documentation and removed documentation Improvements or additions to documentation labels Oct 17, 2022
@@ -12,7 +12,7 @@ require (
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.26.0
github.com/shirou/gopsutil v3.21.10+incompatible
github.com/spf13/cobra v1.1.3
github.com/spf13/cobra v1.2.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

@@ -91,3 +97,18 @@ func CmpFloat(p1, p2 float64) int32 {
}
return 1
}

func GetFileMd5(file string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostRegMatchesPodStatefulset = `[0-9]+$`
)

func GetPodNameReg(resourceName string, resourceType string) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a Unit test for it


// define MetricRule for expressionQuery, SeriesName for original metric name, MetricName for name converted by prometheus-adapter

type MetricRule struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to move it to another path

)

// controller for configMap of prometheus-adapter
type PromAdapterConfigMapController struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally a controller should be independency. So i suggest you can implement it referring to OOMRecorder's implementation.

ScaleClient scale.ScalesGetter
K8SVersion *version.Version
Config EhpaControllerConfig
MetricRulesResource []utils.MetricRule
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to manage rules in a in depended class .

Copy link
Member

@qmhu qmhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please fix the lints

}

if opts.DataSourcePromConfig.AdapterConfigMap != "" {
// PrometheusAdapterConfigFetcher
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if opts.DataSourcePromConfig.AdapterConfigMap != "" || opts.DataSourcePromConfig.AdapterConfig != "" {
init()
}

@qmhu qmhu merged commit a4088c7 into gocrane:main Dec 13, 2022
@qmhu qmhu linked an issue Dec 14, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QOS recommendations for multi-cluster prometheus summary metrics
2 participants