Skip to content

feat(web.hosting): add chart for hosting database #17706

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ghyenne
Copy link
Contributor

@ghyenne ghyenne commented Jun 18, 2025

Description

Ticket Reference: #MANAGER-17885

Additional Information

@StephaneRavet
Copy link

🟠 Assessment: Review of PR #17706 – “feat(web.hosting): add chart for hosting database”


✅ Strengths

✔️ Clean architecture – Good separation into components: constants, service, controller, template.
✔️ Well-designed chart integration using ChartFactory and chartjs-plugin-datasource-prometheus for optimized performance.
✔️ Data normalization hook (dataSetHook) ensures safety for null values from Prometheus.
✔️ Typed internationalization – Proper use of $translate.instant with integration of i18n labels.
✔️ UX performance – Chart animation disabled (duration: 0), smooth zooming, responsive behavior.


⚠️ Suggested Improvements

1. Network error handling

  • 📛 The .then(response => response.json()...) chain lacks error handling for JSON or failed network calls.

2. Controller responsibility

  • ⚠️ The controller contains too much PromQL logic and formatting. Suggested improvements:
    • Move PromQL query and URL construction to a dedicated service.
    • Feed ChartFactory with a simple array of { timestamp, value } or datasets, keeping the controller focused on orchestration.

3. Chart update on period/aggregateMode changes

  • ⚠️ Currently, initDatabaseChart() is only called once during initialization.
    → If the user changes period or aggregateMode, the chart does not update.
    🔁 Add $watch listeners to these variables to re-trigger initDatabaseChart() dynamically.

ℹ️ Secondary Remarks

  • Code comments: Consider adding TODO or JSDoc to document what DatabaseStatistics.getDatabaseMetricsToken() returns.

🛠️ Refactor Example for PromQL Request

async initDatabaseChart() {
  try {
    this.loadingDatabaseGraph = true;
    const { endpoint, token } = await this.DatabaseStatistics.getDatabaseMetricsToken(...);
    const query =
      this.aggregateMode.label === 'ALL'
        ? `sum(sharedsql_queries_allowed_denied{database="${dbName}"})`
        : `sharedsql_queries_allowed_denied{database="${dbName}"}`;
    const url = `${endpoint}/prometheus/api/v1/query_range?query=${encodeURIComponent(query)}...`;
    const response = await fetch(url, {
      headers: { authorization: `bearer ${token}`, 'content-type': 'application/x-www-form-urlencoded' },
    });
    if (!response.ok) throw new Error(response.statusText);
    const json = await response.json();
    // Add a safety check for json.data here
    const datasets = json.data;
    this.renderChart(datasets);
  } catch (error) {
    this.$translate.instant('hosting_tab_STATISTICS_none');
    // Show user-friendly error message
  } finally {
    this.loadingDatabaseGraph = false;
  }
}

ref: #MANAGER-17885

Signed-off-by: Guillaume Hyenne <guillaume.hyenne@ovhcloud.com>
@ghyenne ghyenne force-pushed the feat/MANAGER-17885 branch from c17008e to 83db47c Compare June 19, 2025 10:19
@ghyenne
Copy link
Contributor Author

ghyenne commented Jun 19, 2025

For the recommendation of #17706 (comment).
In fact i made same that another component in same page for to be consistent. There is a refresh, as opposed to what the AI says (data-ng-change).

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

Successfully merging this pull request may close these issues.

3 participants