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

Added Prometheus Handler #9654

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

panoskyriakis
Copy link

Description

Added a handler to fetch data from Prometheus server. Per discussion here.

Fixes #issue_number

Type of change

  • ⚡ New feature (non-breaking change which adds functionality)

Verification Process

The README contains instructions on how to run unit and e2e tests.

Checklist:

  • My code follows the style guidelines(PEP 8) of MindsDB.
  • I have appropriately commented on my code, especially in complex areas.
  • Necessary documentation updates are either made or tracked in issues.
  • Relevant unit and integration tests are updated or added.

@mindsdbadmin
Copy link
Contributor

mindsdbadmin commented Aug 28, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@panoskyriakis
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@panoskyriakis
Copy link
Author

@ZoranPandovski could you have a look at this and the failed checks?

Copy link
Contributor

@MinuraPunchihewa MinuraPunchihewa left a comment

Choose a reason for hiding this comment

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

Hey @panoskyriakis,
Overall, this looks good to me. I left a few minor comments to be addressed in the docs.
Quick question; I am not to familiar with Prometheus, but do you think it would be better to implement this as an APIHandler?

To setup a connection to Prometheus host, run the following SQL in the MindsDB interface:

```sql
CREATE DATABASE prometheus_sourxe
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a small type here in the name of the data source. It should be prometheus_source.

@panoskyriakis
Copy link
Author

Hey @panoskyriakis, Overall, this looks good to me. I left a few minor comments to be addressed in the docs. Quick question; I am not to familiar with Prometheus, but do you think it would be better to implement this as an APIHandler?

@MinuraPunchihewa I think Prometheus is much closer to a database than an API. I used the ElasticSearch handler as a prototype which is quite similar to this one and is implemented as a DBHandler. Hope that works :)

Copy link
Contributor

@MinuraPunchihewa MinuraPunchihewa left a comment

Choose a reason for hiding this comment

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

Hey @panoskyriakis,
Apologies for the delay in taking a look at this. I left some minor comments. I think we should be ready to merge once these are done.

if not isinstance(query, Select):
raise ValueError("Only select queries are supported")

select_query = cast(Select, query)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? Based on your condition above, only SELECT queries will be allowed to get to this point, yes?

raise ValueError("Only select queries are supported")

select_query = cast(Select, query)
from_table = select_query.from_table
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The from_table variable does not seem to be used; should we maybe use in the subsequent lines rather than calling select_query.from_table again?

Comment on lines +195 to +205
conditions = extract_comparison_conditions(select_query.where)
conditions = convert_conditions_to_promql(conditions)

select_statement_parser = SELECTQueryParser(
query,
select_query.from_table,
self.get_columns(select_query.from_table)
)

# TODO: use the orderbys returned by this parser
_, _, _, result_limit = select_statement_parser.parse_query()
Copy link
Contributor

Choose a reason for hiding this comment

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

It is possible to retrieve the conditions of the query when calling parse_query() of the SELECTQueryParser. I think it would be cleaner to do so, rather than calling extract_comparison_conditions again.

Before proceeding, ensure the following prerequisites are met:

1. Install MindsDB locally via [Docker](/setup/self-hosted/docker) or [Docker Desktop](/setup/self-hosted/docker-desktop).
2. Install ```prometheus-api-client``` the only requirement of the Prometheus handler:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we replace the second step here with a sentence similar to what is given here? I think it would be best to point out all of the options available to install the dependencies for the integration.

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

Successfully merging this pull request may close these issues.

4 participants