Skip to content

Fix dynamic JobId dimension population for AWS/EMR-Serverless in CloudWatch plugin (#104062) #105506

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 7 commits into
base: main
Choose a base branch
from

Conversation

Victorthedev
Copy link
Contributor

@Victorthedev Victorthedev commented May 16, 2025

This commit resolves issue #104062 by enabling dynamic population of JobId dimensions based on ApplicationId for AWS/EMRServerless metrics in the Grafana CloudWatch plugin. It also fixes a TypeScript error in FilterItem.tsx and a Prometheus metric registration panic.

Changes:

  • Backend:
    • Added handleGetDimensionValues in pkg/tsdb/cloudwatch/metric_find_query.go to filter JobId by ApplicationId for AWS/EMRServerless using ListMetrics.
    • Added test in pkg/tsdb/cloudwatch/metric_find_query_test.go for JobId retrieval.
    • Removed datasourceResponseGauge in pkg/infra/httpclient/httpclientprovider/datasource_metrics_middleware.go to fix Prometheus metric conflict panic (see Duplicate Prometheus Metric Registration Panic for plugins_datasource_response_size #105507).
  • Frontend:
    • Modified public/plugins/datasource/cloudwatch/MetricsQueryEditor/MetricsQueryEditor.tsx to pass applicationId to MetricStatEditor.
    • Updated public/plugins/datasource/cloudwatch/shared/MetricStatEditor.tsx to pass applicationId to Dimensions.
    • Updated public/plugins/datasource/cloudwatch/Dimensions/Dimensions.tsx to pass applicationId to FilterItem.
    • Modified public/plugins/datasource/cloudwatch/Dimensions/FilterItem.tsx to include applicationId in getDimensionValues params for JobId queries, using type assertion due to missing applicationId in datasource.ts.

Scope:

  • Limited to AWS/EMRServerless JobId queries and fixing startup panic; no impact on other functionality.

Notes:

Fixes: #104062

What is this feature?

[Add a brief description of what the feature or update does.]

Why do we need this feature?

[Add a description of the problem the feature is trying to solve.]

Who is this feature for?

[Add information on what kind of user the feature is for.]

Which issue(s) does this PR fix?:

Fixes #

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

Serverless in CloudWatch plugin (grafana#104062)

This commit resolves issue grafana#104062 by enabling dynamic population of JobId dimensions based on ApplicationId for AWS/EMRServerless metrics in the Grafana CloudWatch plugin. It also fixes a TypeScript error in FilterItem.tsx and a Prometheus metric registration panic.

**Changes:**
- **Backend**:
  - Added `handleGetDimensionValues` in `pkg/tsdb/cloudwatch/metric_find_query.go` to filter JobId by ApplicationId for AWS/EMRServerless using `ListMetrics`.
  - Added test in `pkg/tsdb/cloudwatch/metric_find_query_test.go` for JobId retrieval.
  - Removed `datasourceResponseGauge` in `pkg/infra/httpclient/httpclientprovider/datasource_metrics_middleware.go` to fix Prometheus metric conflict panic.
- **Frontend**:
  - Modified `public/plugins/datasource/cloudwatch/MetricsQueryEditor/MetricsQueryEditor.tsx` to pass `applicationId` to `MetricStatEditor`.
  - Updated `public/plugins/datasource/cloudwatch/shared/MetricStatEditor.tsx` to pass `applicationId` to `Dimensions`.
  - Updated `public/plugins/datasource/cloudwatch/Dimensions/Dimensions.tsx` to pass `applicationId` to `FilterItem`.
  - Modified `public/plugins/datasource/cloudwatch/Dimensions/FilterItem.tsx` to include `applicationId` in `getDimensionValues` params for JobId queries, using type assertion due to missing `applicationId` in `datasource.ts`.

**Scope:**
- Limited to AWS/EMRServerless JobId queries and fixing startup panic; no impact on other functionality.

**Notes:**
- Type assertion in `FilterItem.tsx` is temporary; apply `datasource.ts` to remove it.
- Metric fix is a workaround; consider upstream Grafana issue for proper resolution.

Fixes: grafana#104062
@Victorthedev Victorthedev requested review from a team as code owners May 16, 2025 01:17
@Victorthedev Victorthedev requested review from kevinwcyu, njvrzm, andresmgot, oshirohugo, s4kh, IfSentient and mustafasencer and removed request for a team May 16, 2025 01:17
@CLAassistant
Copy link

CLAassistant commented May 16, 2025

CLA assistant check
All committers have signed the CLA.

@Victorthedev Victorthedev requested review from dprokop and mdvictor and removed request for a team May 16, 2025 01:17
@github-actions github-actions bot added this to the 12.1.x milestone May 16, 2025
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions!

@github-actions github-actions bot added the stale Issue with no recent activity label Jul 18, 2025
@kevinwcyu kevinwcyu removed the stale Issue with no recent activity label Jul 18, 2025
Copy link
Contributor

@iwysiu iwysiu left a comment

Choose a reason for hiding this comment

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

HI @Victorthedev , thanks for the pr! I was reviewing this, and did you test this? It doesn't seem like the applicationId is getting passed from the frontend to the backend at any point.

Also, could you clean up the pr a bit? it looks like the backend changes don't do anything and there are a bunch of comments and newlines that are removed that we would like to keep.

return result, nil
}

func (e *cloudWatchExecutor) handleGetDimensionValues(ctx context.Context, pluginCtx backend.PluginContext, parameters url.Values) ([]suggestData, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this function getting called?

};

if (namespace === 'AWS/EMRServerless' && filter.key === 'JobId' && applicationId) {
(params as any).applicationId = applicationId; // Type assertion to bypass TS error
Copy link
Contributor

Choose a reason for hiding this comment

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

You could add applicationId to the GetDimensionValuesRequest in resource/types.ts and declare

const params: GetDimensionValuesRequest = {...

above to avoid using the any

} from './types';
import { CloudWatchVariableSupport } from './variables';

export interface DimensionValuesRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is already a GetDimensionValuesRequest in resource/types and I don't think you're using these anywhere

@gabor gabor removed the request for review from a team July 23, 2025 09:54
@kevinwcyu kevinwcyu removed area/alerting Grafana Alerting datasource/Postgres area/backend area/frontend datasource/Azure Azure Monitor Datasource datasource/Tempo type/docs Flags the technical writing team for documentation support; auto adds to org-wide docs project labels Jul 23, 2025
@kevinwcyu kevinwcyu removed this from Alerting Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Next
Development

Successfully merging this pull request may close these issues.

Cloudwatch Plugin: EMRServerless Job level metrics dimensions missing
6 participants