Issue:
Bug: feat(analytics): Revert api_event metrics and filters back to merchant_id authentication



`api_event_metrics` and `api_event_filters` APIs were modified to authenticate through AuthInfo where there are MerchantLevel, ProfileLevel and OrgLevel authentication. (https://github.com/juspay/hyperswitch/pull/5729)

But ApiEvents table is not yet populated with organization_id and profile_id, hence should be reverted back.

Pull request description:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [x] Bugfix
- [ ] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
Previously modified api_event_metrics and api_event_filters to authenticate through AuthInfo where there are MerchantLevel, ProfileLevel and OrgLevel authentication. ([https://github.com/juspay/hyperswitch/pull/5729](https://github.com/juspay/hyperswitch/pull/5729))

But ApiEvents table is not populated with `organization_id` and `profile_id`, hence reverting back.

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->
Fix the issues on sandbox analytics related to api_events.

## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
Spoke with dashboard team and removed the following api endpoints:
- /analytics/v1/profile/metrics/api_events
- /analytics/v1/profile/filters/api_events
- /analytics/v1/org/metrics/api_events
- /analytics/v1/org/filters/api_events

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible


Testing:

Spoke with dashboard team and removed the following api endpoints:
- /analytics/v1/profile/metrics/api_events
- /analytics/v1/profile/filters/api_events
- /analytics/v1/org/metrics/api_events
- /analytics/v1/org/filters/api_events

Patch:
diff --git a/crates/analytics/src/api_event/core.rs b/crates/analytics/src/api_event/core.rs
index f3a7b154b90..305de7e69c8 100644
--- a/crates/analytics/src/api_event/core.rs
+++ b/crates/analytics/src/api_event/core.rs
@@ -21,7 +21,6 @@ use super::{
     metrics::ApiEventMetricRow,
 };
 use crate::{
-    enums::AuthInfo,
     errors::{AnalyticsError, AnalyticsResult},
     metrics,
     types::FiltersError,
@@ -52,7 +51,7 @@ pub async fn api_events_core(
 pub async fn get_filters(
     pool: &AnalyticsProvider,
     req: GetApiEventFiltersRequest,
-    auth: &AuthInfo,
+    merchant_id: &common_utils::id_type::MerchantId,
 ) -> AnalyticsResult<ApiEventFiltersResponse> {
     use api_models::analytics::{api_event::ApiEventDimensions, ApiEventFilterValue};
 
@@ -69,7 +68,8 @@ pub async fn get_filters(
             AnalyticsProvider::Clickhouse(ckh_pool)
             | AnalyticsProvider::CombinedSqlx(_, ckh_pool)
             | AnalyticsProvider::CombinedCkh(_, ckh_pool) => {
-                get_api_event_filter_for_dimension(dim, auth, &req.time_range, ckh_pool).await
+                get_api_event_filter_for_dimension(dim, merchant_id, &req.time_range, ckh_pool)
+                    .await
             }
         }
         .switch()?
@@ -92,7 +92,7 @@ pub async fn get_filters(
 #[instrument(skip_all)]
 pub async fn get_api_event_metrics(
     pool: &AnalyticsProvider,
-    auth: &AuthInfo,
+    merchant_id: &common_utils::id_type::MerchantId,
     req: GetApiEventMetricRequest,
 ) -> AnalyticsResult<MetricsResponse<ApiMetricsBucketResponse>> {
     let mut metrics_accumulator: HashMap<ApiEventMetricsBucketIdentifier, ApiEventMetricRow> =
@@ -109,14 +109,14 @@ pub async fn get_api_event_metrics(
 
         // TODO: lifetime issues with joinset,
         // can be optimized away if joinset lifetime requirements are relaxed
-        let auth_scoped = auth.to_owned();
+        let merchant_id_scoped = merchant_id.to_owned();
         set.spawn(
             async move {
                 let data = pool
                     .get_api_event_metrics(
                         &metric_type,
                         &req.group_by_names.clone(),
-                        &auth_scoped,
+                        &merchant_id_scoped,
                         &req.filters,
                         &req.time_series.map(|t| t.granularity),
                         &req.time_range,
diff --git a/crates/analytics/src/api_event/filters.rs b/crates/analytics/src/api_event/filters.rs
index 5c8136805c9..62fd8789018 100644
--- a/crates/analytics/src/api_event/filters.rs
+++ b/crates/analytics/src/api_event/filters.rs
@@ -4,7 +4,6 @@ use error_stack::ResultExt;
 use time::PrimitiveDateTime;
 
 use crate::{
-    enums::AuthInfo,
     query::{Aggregate, GroupByClause, QueryBuilder, QueryFilter, ToSql, Window},
     types::{AnalyticsCollection, AnalyticsDataSource, FiltersError, FiltersResult, LoadRow},
 };
@@ -13,7 +12,7 @@ pub trait ApiEventFilterAnalytics: LoadRow<ApiEventFilter> {}
 
 pub async fn get_api_event_filter_for_dimension<T>(
     dimension: ApiEventDimensions,
-    auth: &AuthInfo,
+    merchant_id: &common_utils::id_type::MerchantId,
     time_range: &TimeRange,
     pool: &T,
 ) -> FiltersResult<Vec<ApiEventFilter>>
@@ -33,7 +32,9 @@ where
         .attach_printable("Error filtering time range")
         .switch()?;
 
-    auth.set_filter_clause(&mut query_builder).switch()?;
+    query_builder
+        .add_filter_clause("merchant_id", merchant_id)
+        .switch()?;
 
     query_builder.set_distinct();
 
diff --git a/crates/analytics/src/api_event/metrics.rs b/crates/analytics/src/api_event/metrics.rs
index 48e95b6b5cd..ac29ec15169 100644
--- a/crates/analytics/src/api_event/metrics.rs
+++ b/crates/analytics/src/api_event/metrics.rs
@@ -7,7 +7,6 @@ use api_models::analytics::{
 use time::PrimitiveDateTime;
 
 use crate::{
-    enums::AuthInfo,
     query::{Aggregate, GroupByClause, ToSql, Window},
     types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, MetricsResult},
 };
@@ -44,7 +43,7 @@ where
     async fn load_metrics(
         &self,
         dimensions: &[ApiEventDimensions],
-        auth: &AuthInfo,
+        merchant_id: &common_utils::id_type::MerchantId,
         filters: &ApiEventFilters,
         granularity: &Option<Granularity>,
         time_range: &TimeRange,
@@ -65,7 +64,7 @@ where
     async fn load_metrics(
         &self,
         dimensions: &[ApiEventDimensions],
-        auth: &AuthInfo,
+        merchant_id: &common_utils::id_type::MerchantId,
         filters: &ApiEventFilters,
         granularity: &Option<Granularity>,
         time_range: &TimeRange,
@@ -74,17 +73,38 @@ where
         match self {
             Self::Latency => {
                 MaxLatency
-                    .load_metrics(dimensions, auth, filters, granularity, time_range, pool)
+                    .load_metrics(
+                        dimensions,
+                        merchant_id,
+                        filters,
+                        granularity,
+                        time_range,
+                        pool,
+                    )
                     .await
             }
             Self::ApiCount => {
                 ApiCount
-                    .load_metrics(dimensions, auth, filters, granularity, time_range, pool)
+                    .load_metrics(
+                        dimensions,
+                        merchant_id,
+                        filters,
+                        granularity,
+                        time_range,
+                        pool,
+                    )
                     .await
             }
             Self::StatusCodeCount => {
                 StatusCodeCount
-                    .load_metrics(dimensions, auth, filters, granularity, time_range, pool)
+                    .load_metrics(
+                        dimensions,
+                        merchant_id,
+                        filters,
+                        granularity,
+                        time_range,
+                        pool,
+                    )
                     .await
             }
         }
diff --git a/crates/analytics/src/api_event/metrics/api_count.rs b/crates/analytics/src/api_event/metrics/api_count.rs
index 3973870a455..f00c01bbf38 100644
--- a/crates/analytics/src/api_event/metrics/api_count.rs
+++ b/crates/analytics/src/api_event/metrics/api_count.rs
@@ -10,7 +10,6 @@ use time::PrimitiveDateTime;
 
 use super::ApiEventMetricRow;
 use crate::{
-    enums::AuthInfo,
     query::{Aggregate, GroupByClause, QueryBuilder, QueryFilter, SeriesBucket, ToSql, Window},
     types::{AnalyticsCollection, AnalyticsDataSource, MetricsError, MetricsResult},
 };
@@ -31,7 +30,7 @@ where
     async fn load_metrics(
         &self,
         _dimensions: &[ApiEventDimensions],
-        auth: &AuthInfo,
+        merchant_id: &common_utils::id_type::MerchantId,
         filters: &ApiEventFilters,
         granularity: &Option<Granularity>,
         time_range: &TimeRange,
@@ -70,7 +69,9 @@ where
                 .switch()?;
         }
 
-        auth.set_filter_clause(&mut query_builder).switch()?;
+        query_builder
+            .add_filter_clause("merchant_id", merchant_id)
+            .switch()?;
 
         time_range
             .set_filter_clause(&mut query_builder)
diff --git a/crates/analytics/src/api_event/metrics/latency.rs b/crates/analytics/src/api_event/metrics/latency.rs
index c9a62abe676..5d71da2a0aa 100644
--- a/crates/analytics/src/api_event/metrics/latency.rs
+++ b/crates/analytics/src/api_event/metrics/latency.rs
@@ -10,7 +10,6 @@ use time::PrimitiveDateTime;
 
 use super::ApiEventMetricRow;
 use crate::{
-    enums::AuthInfo,
     query::{
         Aggregate, FilterTypes, GroupByClause, QueryBuilder, QueryFilter, SeriesBucket, ToSql,
         Window,
@@ -34,7 +33,7 @@ where
     async fn load_metrics(
         &self,
         _dimensions: &[ApiEventDimensions],
-        auth: &AuthInfo,
+        merchant_id: &common_utils::id_type::MerchantId,
         filters: &ApiEventFilters,
         granularity: &Option<Granularity>,
         time_range: &TimeRange,
@@ -77,7 +76,9 @@ where
 
         filters.set_filter_clause(&mut query_builder).switch()?;
 
-        auth.set_filter_clause(&mut query_builder).switch()?;
+        query_builder
+            .add_filter_clause("merchant_id", merchant_id)
+            .switch()?;
 
         time_range
             .set_filter_clause(&mut query_builder)
diff --git a/crates/analytics/src/api_event/metrics/status_code_count.rs b/crates/analytics/src/api_event/metrics/status_code_count.rs
index 190f38999c9..b4fff367b62 100644
--- a/crates/analytics/src/api_event/metrics/status_code_count.rs
+++ b/crates/analytics/src/api_event/metrics/status_code_count.rs
@@ -10,7 +10,6 @@ use time::PrimitiveDateTime;
 
 use super::ApiEventMetricRow;
 use crate::{
-    enums::AuthInfo,
     query::{Aggregate, GroupByClause, QueryBuilder, QueryFilter, SeriesBucket, ToSql, Window},
     types::{AnalyticsCollection, AnalyticsDataSource, MetricsError, MetricsResult},
 };
@@ -31,7 +30,7 @@ where
     async fn load_metrics(
         &self,
         _dimensions: &[ApiEventDimensions],
-        auth: &AuthInfo,
+        merchant_id: &common_utils::id_type::MerchantId,
         filters: &ApiEventFilters,
         granularity: &Option<Granularity>,
         time_range: &TimeRange,
@@ -48,7 +47,9 @@ where
 
         filters.set_filter_clause(&mut query_builder).switch()?;
 
-        auth.set_filter_clause(&mut query_builder).switch()?;
+        query_builder
+            .add_filter_clause("merchant_id", merchant_id)
+            .switch()?;
 
         time_range
             .set_filter_clause(&mut query_builder)
diff --git a/crates/analytics/src/lib.rs b/crates/analytics/src/lib.rs
index 66005a61b75..d5cb3c718df 100644
--- a/crates/analytics/src/lib.rs
+++ b/crates/analytics/src/lib.rs
@@ -828,7 +828,7 @@ impl AnalyticsProvider {
         &self,
         metric: &ApiEventMetrics,
         dimensions: &[ApiEventDimensions],
-        auth: &AuthInfo,
+        merchant_id: &common_utils::id_type::MerchantId,
         filters: &ApiEventFilters,
         granularity: &Option<Granularity>,
         time_range: &TimeRange,
@@ -840,7 +840,14 @@ impl AnalyticsProvider {
             | Self::CombinedSqlx(_, ckh_pool) => {
                 // Since API events are ckh only use ckh here
                 metric
-                    .load_metrics(dimensions, auth, filters, granularity, time_range, ckh_pool)
+                    .load_metrics(
+                        dimensions,
+                        merchant_id,
+                        filters,
+                        granularity,
+                        time_range,
+                        ckh_pool,
+                    )
                     .await
             }
         }
diff --git a/crates/router/src/analytics.rs b/crates/router/src/analytics.rs
index 7c4d1acc6bf..879db9a5a67 100644
--- a/crates/router/src/analytics.rs
+++ b/crates/router/src/analytics.rs
@@ -215,14 +215,6 @@ pub mod routes {
                                     web::resource("filters/disputes")
                                         .route(web::post().to(get_org_dispute_filters)),
                                 )
-                                .service(
-                                    web::resource("filters/api_events")
-                                        .route(web::post().to(get_org_api_event_filters)),
-                                )
-                                .service(
-                                    web::resource("metrics/api_events")
-                                        .route(web::post().to(get_org_api_events_metrics)),
-                                )
                                 .service(
                                     web::resource("report/dispute")
                                         .route(web::post().to(generate_org_dispute_report)),
@@ -257,14 +249,6 @@ pub mod routes {
                                     web::resource("filters/refunds")
                                         .route(web::post().to(get_profile_refund_filters)),
                                 )
-                                .service(
-                                    web::resource("metrics/api_events")
-                                        .route(web::post().to(get_profile_api_events_metrics)),
-                                )
-                                .service(
-                                    web::resource("filters/api_events")
-                                        .route(web::post().to(get_profile_api_event_filters)),
-                                )
                                 .service(
                                     web::resource("metrics/disputes")
                                         .route(web::post().to(get_profile_dispute_metrics)),
@@ -1757,100 +1741,13 @@ pub mod routes {
             &req,
             payload,
             |state, auth: AuthenticationData, req, _| async move {
-                let org_id = auth.merchant_account.get_org_id();
-                let merchant_id = auth.merchant_account.get_id();
-                let auth: AuthInfo = AuthInfo::MerchantLevel {
-                    org_id: org_id.clone(),
-                    merchant_ids: vec![merchant_id.clone()],
-                };
-                analytics::api_event::get_api_event_metrics(&state.pool, &auth, req)
-                    .await
-                    .map(ApplicationResponse::Json)
-            },
-            &auth::JWTAuth {
-                permission: Permission::Analytics,
-                minimum_entity_level: EntityType::Merchant,
-            },
-            api_locking::LockAction::NotApplicable,
-        ))
-        .await
-    }
-
-    /// # Panics
-    ///
-    /// Panics if `json_payload` array does not contain one `GetApiEventMetricRequest` element.
-    pub async fn get_org_api_events_metrics(
-        state: web::Data<AppState>,
-        req: actix_web::HttpRequest,
-        json_payload: web::Json<[GetApiEventMetricRequest; 1]>,
-    ) -> impl Responder {
-        // safety: This shouldn't panic owing to the data type
-        #[allow(clippy::expect_used)]
-        let payload = json_payload
-            .into_inner()
-            .to_vec()
-            .pop()
-            .expect("Couldn't get GetApiEventMetricRequest");
-        let flow = AnalyticsFlow::GetApiEventMetrics;
-        Box::pin(api::server_wrap(
-            flow,
-            state.clone(),
-            &req,
-            payload,
-            |state, auth: AuthenticationData, req, _| async move {
-                let org_id = auth.merchant_account.get_org_id();
-                let auth: AuthInfo = AuthInfo::OrgLevel {
-                    org_id: org_id.clone(),
-                };
-                analytics::api_event::get_api_event_metrics(&state.pool, &auth, req)
-                    .await
-                    .map(ApplicationResponse::Json)
-            },
-            &auth::JWTAuth {
-                permission: Permission::Analytics,
-                minimum_entity_level: EntityType::Merchant,
-            },
-            api_locking::LockAction::NotApplicable,
-        ))
-        .await
-    }
-
-    /// # Panics
-    ///
-    /// Panics if `json_payload` array does not contain one `GetApiEventMetricRequest` element.
-    pub async fn get_profile_api_events_metrics(
-        state: web::Data<AppState>,
-        req: actix_web::HttpRequest,
-        json_payload: web::Json<[GetApiEventMetricRequest; 1]>,
-    ) -> impl Responder {
-        // safety: This shouldn't panic owing to the data type
-        #[allow(clippy::expect_used)]
-        let payload = json_payload
-            .into_inner()
-            .to_vec()
-            .pop()
-            .expect("Couldn't get GetApiEventMetricRequest");
-        let flow = AnalyticsFlow::GetApiEventMetrics;
-        Box::pin(api::server_wrap(
-            flow,
-            state.clone(),
-            &req,
-            payload,
-            |state, auth: AuthenticationData, req, _| async move {
-                let org_id = auth.merchant_account.get_org_id();
-                let merchant_id = auth.merchant_account.get_id();
-                let profile_id = auth
-                    .profile_id
-                    .ok_or(report!(UserErrors::JwtProfileIdMissing))
-                    .change_context(AnalyticsError::AccessForbiddenError)?;
-                let auth: AuthInfo = AuthInfo::ProfileLevel {
-                    org_id: org_id.clone(),
-                    merchant_id: merchant_id.clone(),
-                    profile_ids: vec![profile_id.clone()],
-                };
-                analytics::api_event::get_api_event_metrics(&state.pool, &auth, req)
-                    .await
-                    .map(ApplicationResponse::Json)
+                analytics::api_event::get_api_event_metrics(
+                    &state.pool,
+                    auth.merchant_account.get_id(),
+                    req,
+                )
+                .await
+                .map(ApplicationResponse::Json)
             },
             &auth::JWTAuth {
                 permission: Permission::Analytics,
@@ -1873,78 +1770,7 @@ pub mod routes {
             &req,
             json_payload.into_inner(),
             |state, auth: AuthenticationData, req, _| async move {
-                let org_id = auth.merchant_account.get_org_id();
-                let merchant_id = auth.merchant_account.get_id();
-                let auth: AuthInfo = AuthInfo::MerchantLevel {
-                    org_id: org_id.clone(),
-                    merchant_ids: vec![merchant_id.clone()],
-                };
-                analytics::api_event::get_filters(&state.pool, req, &auth)
-                    .await
-                    .map(ApplicationResponse::Json)
-            },
-            &auth::JWTAuth {
-                permission: Permission::Analytics,
-                minimum_entity_level: EntityType::Merchant,
-            },
-            api_locking::LockAction::NotApplicable,
-        ))
-        .await
-    }
-
-    pub async fn get_org_api_event_filters(
-        state: web::Data<AppState>,
-        req: actix_web::HttpRequest,
-        json_payload: web::Json<GetApiEventFiltersRequest>,
-    ) -> impl Responder {
-        let flow = AnalyticsFlow::GetApiEventFilters;
-        Box::pin(api::server_wrap(
-            flow,
-            state.clone(),
-            &req,
-            json_payload.into_inner(),
-            |state, auth: AuthenticationData, req, _| async move {
-                let org_id = auth.merchant_account.get_org_id();
-                let auth: AuthInfo = AuthInfo::OrgLevel {
-                    org_id: org_id.clone(),
-                };
-                analytics::api_event::get_filters(&state.pool, req, &auth)
-                    .await
-                    .map(ApplicationResponse::Json)
-            },
-            &auth::JWTAuth {
-                permission: Permission::Analytics,
-                minimum_entity_level: EntityType::Merchant,
-            },
-            api_locking::LockAction::NotApplicable,
-        ))
-        .await
-    }
-
-    pub async fn get_profile_api_event_filters(
-        state: web::Data<AppState>,
-        req: actix_web::HttpRequest,
-        json_payload: web::Json<GetApiEventFiltersRequest>,
-    ) -> impl Responder {
-        let flow = AnalyticsFlow::GetApiEventFilters;
-        Box::pin(api::server_wrap(
-            flow,
-            state.clone(),
-            &req,
-            json_payload.into_inner(),
-            |state, auth: AuthenticationData, req, _| async move {
-                let org_id = auth.merchant_account.get_org_id();
-                let merchant_id = auth.merchant_account.get_id();
-                let profile_id = auth
-                    .profile_id
-                    .ok_or(report!(UserErrors::JwtProfileIdMissing))
-                    .change_context(AnalyticsError::AccessForbiddenError)?;
-                let auth: AuthInfo = AuthInfo::ProfileLevel {
-                    org_id: org_id.clone(),
-                    merchant_id: merchant_id.clone(),
-                    profile_ids: vec![profile_id.clone()],
-                };
-                analytics::api_event::get_filters(&state.pool, req, &auth)
+                analytics::api_event::get_filters(&state.pool, req, auth.merchant_account.get_id())
                     .await
                     .map(ApplicationResponse::Json)
             },