original_docstring: Execute a PromQL query against the Prometheus server.
  
          Args:
              query (str): the PromQL query
              step (str): the step size for the range query. The Datasource will
                  execute a `range query
                  <https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries>`_
                  over the report window and capture all time series data
                  within the report boundaries. The step size indicates the
                  query resolution. A lower value provides more granularity
                  but at the cost of a more expensive query and more data
                  points to analyze. If your report window is significantly
                  short, it may make sense to reduce this.
  
          Returns:
              pandas.DataFrame: a table of time series results.
  
                  The timeseries value will be in a ``time`` column; any labels
                  associated with the metric will be added as additional columns.
          
docstring: Execute a PromQL query against the Prometheus server.
docstring_tokens: Execute a PromQL query against the Prometheus server .
code: def query(self, query: str, step="1h") -> pd.DataFrame:
          """Execute a PromQL query against the Prometheus server.
  
          Args:
              query (str): the PromQL query
              step (str): the step size for the range query. The Datasource will
                  execute a `range query
                  <https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries>`_
                  over the report window and capture all time series data
                  within the report boundaries. The step size indicates the
                  query resolution. A lower value provides more granularity
                  but at the cost of a more expensive query and more data
                  points to analyze. If your report window is significantly
                  short, it may make sense to reduce this.
  
          Returns:
              pandas.DataFrame: a table of time series results.
  
                  The timeseries value will be in a ``time`` column; any labels
                  associated with the metric will be added as additional columns.
          """
          if self.basic_auth:
              auth = requests.auth.HTTPBasicAuth(
                  self.basic_auth["username"], self.basic_auth["password"]
              )
          else:
              auth = None
  
          res = requests.get(
              f"{self.host}/api/v1/query_range",
              params=dict(
                  start=self.report.start_date.timestamp(),
                  end=self.report.end_date.timestamp(),
                  step=step,
                  query=query.strip(),
              ),
              auth=auth,
          )
          res.raise_for_status()
          json = res.json()
  
          if json.get("status") != "success":
              raise ValueError("Got error response from Prometheus server")
  
          result = json.get("data", {}).get("result", [])
  
          df = pd.DataFrame()
  
          for metric in result:
              mdf = pd.DataFrame(metric["values"], columns=["time", "value"])
              mdf["time"] = pd.to_datetime(mdf["time"], unit="s")
              mdf = mdf.assign(**metric["metric"])
              mdf = mdf.astype({"value": "float"})
              df = df.append(mdf)
  
          return df
code_tokens: def query ( self , query : str , step = "1h" ) -> pd . DataFrame : if self . basic_auth : auth = requests . auth . HTTPBasicAuth ( self . basic_auth [ "username" ] , self . basic_auth [ "password" ] ) else : auth = None res = requests . get ( f"{self.host}/api/v1/query_range" , params = dict ( start = self . report . start_date . timestamp ( ) , end = self . report . end_date . timestamp ( ) , step = step , query = query . strip ( ) , ) , auth = auth , ) res . raise_for_status ( ) json = res . json ( ) if json . get ( "status" ) != "success" : raise ValueError ( "Got error response from Prometheus server" ) result = json . get ( "data" , { } ) . get ( "result" , [ ] ) df = pd . DataFrame ( ) for metric in result : mdf = pd . DataFrame ( metric [ "values" ] , columns = [ "time" , "value" ] ) mdf [ "time" ] = pd . to_datetime ( mdf [ "time" ] , unit = "s" ) mdf = mdf . assign ( ** metric [ "metric" ] ) mdf = mdf . astype ( { "value" : "float" } ) df = df . append ( mdf ) return df
short_docstring: Execute a PromQL query against the Prometheus server.
short_docstring_tokens: Execute a PromQL query against the Prometheus server .
comment: """Execute a PromQL query against the Prometheus server.
  
          Args:
              query (str): the PromQL query
              step (str): the step size for the range query. The Datasource will
                  execute a `range query
                  <https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries>`_
                  over the report window and capture all time series data
                  within the report boundaries. The step size indicates the
                  query resolution. A lower value provides more granularity
                  but at the cost of a more expensive query and more data
                  points to analyze. If your report window is significantly
                  short, it may make sense to reduce this.
  
          Returns:
              pandas.DataFrame: a table of time series results.
  
                  The timeseries value will be in a ``time`` column; any labels
                  associated with the metric will be added as additional columns.
          """