powerapi icon indicating copy to clipboard operation
powerapi copied to clipboard

K8S export on influxDB fields

Open tibosmn opened this issue 1 year ago • 0 comments

When exporting values to InfluxDB while using the K8SPreProcessor, the field 'k8s' is added, but it contains a dictionary as a string, which makes database operations impractical:

image

I would suggest to add the dictionary keys into individual InfluxDB fields to obtain this:

image

The quick and dirty fix used to obtain this image is this following code at the end of PowerReport.gen_tag function:

  if "k8s" in self.metadata:
      tags.pop('k8s')
      # logging.getLogger().info('gen_tag k8s')
      for key, value in self.metadata["k8s"].items():

          if not isinstance(value, dict):
              tags[key] = value
          else:
              for subkey, subvalue in self.metadata["k8s"].items():
                  tags[subkey] = subvalue

This solution however is not sufficient in my regard, as it only work for the 'k8s' tag, and is not generic for any PreProcessor added in the future. Furthermore, it only goes to one level of sub-dict, which might not be sufficient for all edge-cases. As such I don't create a pull request with this piece of code, as you might want to update the architecture more in depth

tibosmn avatar Aug 30 '24 06:08 tibosmn