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

example: datadog_api_client.v2 query_timeseries_data does not work #2240

Open
bellondr opened this issue Nov 3, 2024 · 1 comment
Open
Labels

Comments

@bellondr
Copy link

bellondr commented Nov 3, 2024

Describe the bug
A clear and concise description of what the bug is.
when I run test in
https://github.com/DataDog/datadog-api-client-python/blob/master/examples/v2/metrics/QueryTimeseriesData.py

"""
Query timeseries data across multiple products returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.metrics_api import MetricsApi
from datadog_api_client.v2.model.formula_limit import FormulaLimit
from datadog_api_client.v2.model.metrics_data_source import MetricsDataSource
from datadog_api_client.v2.model.metrics_timeseries_query import MetricsTimeseriesQuery
from datadog_api_client.v2.model.query_formula import QueryFormula
from datadog_api_client.v2.model.query_sort_order import QuerySortOrder
from datadog_api_client.v2.model.timeseries_formula_query_request import TimeseriesFormulaQueryRequest
from datadog_api_client.v2.model.timeseries_formula_request import TimeseriesFormulaRequest
from datadog_api_client.v2.model.timeseries_formula_request_attributes import TimeseriesFormulaRequestAttributes
from datadog_api_client.v2.model.timeseries_formula_request_queries import TimeseriesFormulaRequestQueries
from datadog_api_client.v2.model.timeseries_formula_request_type import TimeseriesFormulaRequestType


body = TimeseriesFormulaQueryRequest(
    data=TimeseriesFormulaRequest(
        attributes=TimeseriesFormulaRequestAttributes(
            formulas=[
                QueryFormula(
                    formula="a+b",
                    limit=FormulaLimit(
                        count=10,
                        order=QuerySortOrder.DESC,
                    ),
                ),
            ],
            _from=1730518188595,
            interval=5000,
            queries=TimeseriesFormulaRequestQueries(
                [
                    MetricsTimeseriesQuery(
                        data_source=MetricsDataSource.METRICS,
                        query="avg:system.cpu.user{*}",
                    ),
                ]
            ),
            to=1730604588595,
        ),
        type=TimeseriesFormulaRequestType.TIMESERIES_REQUEST,
    ),
)

API_KEY= 'XXX'
APP_KEY = 'XXX'
configuration = Configuration()
configuration.api_key["apiKeyAuth"] = API_KEY
configuration.api_key["appKeyAuth"] = APP_KEY
configuration.unstable_operations["query_timeseries_data"] = True
with ApiClient(configuration) as api_client:
    api_instance = MetricsApi(api_client)
    response = api_instance.query_timeseries_data(body=body)

    print(response)

return error: {'errors': ['Invalid query input']}

Label the issue properly.

  • Add severity/ label.
  • Add documentation label if this issue is related to documentation changes.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment and Versions (please complete the following information):
A clear and precise description of your setup:

  • version for this project in use.
  • services, libraries, languages and tools list and versions.

Additional context
Add any other context about the problem here.

@wycmiko
Copy link

wycmiko commented Nov 15, 2024

I faced the similar issue while concating a list and pass it :

metric_query_list = []
        for metric_query in metric_queries_list:
            metric_query_list.append(MetricsTimeseriesQuery(
                data_source=MetricsDataSource.METRICS,
                query=metric_query['query'],
                name=metric_query['name'],
            ))

TimeseriesFormulaQueryRequest(
            data=TimeseriesFormulaRequest(
                attributes=TimeseriesFormulaRequestAttributes(
                    formulas=[
                        QueryFormula(
                            formula=fo_expr,
                            limit=FormulaLimit(
                                count=10,
                                order=QuerySortOrder.DESC,
                            ),
                        )
                    ],
                    _from=start_time_ms,
                    interval=864000000,
                    queries=TimeseriesFormulaRequestQueries(metric_query_list), # this line can not correct handle
                    to=current_time_ms,
                ),
                type=TimeseriesFormulaRequestType.TIMESERIES_REQUEST,
            ),
        )

If use code above and submitting the query will get empty response.

If I hard code the list will get the correct response(all query conditions are the same):

      queries=TimeseriesFormulaRequestQueries(
                [
                    MetricsTimeseriesQuery(
                        data_source=MetricsDataSource.METRICS,
                        query="sum:langflow_rag_infer_api_total{http_return_code:200} by {xxx}.as_count().rollup(sum, 60)",
                        name="query3",
                    ),
                    MetricsTimeseriesQuery(
                        data_source=MetricsDataSource.METRICS,
                        query="sum:langflow_rag_infer_api_total{*} by {xxx}.as_count().rollup(sum, 60)",
                        name="query4",
                    ),
                    MetricsTimeseriesQuery(
                        data_source=MetricsDataSource.METRICS,
                        query="sum:langflow_infer_api_total{$xxx, http_return_code:200} by {xxx}.as_count().rollup(sum, 60)",
                        name="query1",
                    ),
                    MetricsTimeseriesQuery(
                        data_source=MetricsDataSource.METRICS,
                        query="sum:xxx{$xxx} by {byoa_app}.as_count().rollup(sum, 60)",
                        name="query2",
                    ),
                ]
            ),

python client version: 2.30.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants