kruize / autotune

Autonomous Performance Tuning for Kubernetes!
Apache License 2.0
163 stars 54 forks source link

Enhance datasource info retrieval from DB with service name validation #1126

Closed shreyabiradar07 closed 6 months ago

shreyabiradar07 commented 6 months ago

This PR resolves an issue where service name and namespace fields are missing in the /datasources API response when the datasource URL is not null while retrieving datasource info from the database.

for a given datasource object -

"datasource": [
    {
      "name": "prometheus-1",
      "provider": "prometheus",
      "serviceName": "prometheus-k8s",
      "namespace": "monitoring",
      "url": ""
    }
]

list datasources - /datasources API response -

Current response (Incomplete API Response):

{
  "version": "v1.0",
  "datasources": [
    {
      "name": "prometheus-1",
      "provider": "prometheus",
      "serviceName": "",
      "namespace": "",
      "url": "http://prometheus-k8s.monitoring.svc.cluster.local:9090"
    }
  ]
}

Enhanced response after the fix:

{
  "version": "v1.0",
  "datasources": [
    {
      "name": "prometheus-1",
      "provider": "prometheus",
      "serviceName": "prometheus-k8s",
      "namespace": "monitoring",
      "url": "http://prometheus-k8s.monitoring.svc.cluster.local:9090"
    }
  ]
}
msvinaykumar commented 6 months ago

@shreyabiradar07 If a namespace is provided, ensure that the 'dsmetadata' is preselected with the namespace during both post and get operations. You can create another PR for the same if needed

shreyabiradar07 commented 6 months ago

@shreyabiradar07 If a namespace is provided, ensure that the 'dsmetadata' is preselected with the namespace during both post and get operations. You can create another PR for the same if needed

Thanks for the review. Currently, if the service name is an empty string, regardless of the namespace value, both are stored as empty strings in the database. As a result, if the namespace is present in the datasource object, it is not reflected in the API response.