Skip to content

Commit

Permalink
feature: fix frontends to work with new refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
densumesh authored and skeptrunedev committed Jul 10, 2024
1 parent 996294a commit 9259ea3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
36 changes: 19 additions & 17 deletions frontends/analytics/src/api/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const getLatency = async (
credentials: "include",
method: "POST",
body: JSON.stringify({
latency_graph: transformAnalyticsParams(filters),
...transformAnalyticsParams(filters),
type: "latency_graph",
}),
headers: {
"TR-Dataset": datasetId,
Expand All @@ -54,7 +55,8 @@ export const getRps = async (
credentials: "include",
method: "POST",
body: JSON.stringify({
rps_graph: transformAnalyticsParams(filters),
...transformAnalyticsParams(filters),
type: "rps_graph",
}),
headers: {
"TR-Dataset": datasetId,
Expand Down Expand Up @@ -82,6 +84,7 @@ export const getHeadQueries = async (
head_queries: {
...transformAnalyticsParams(filters),
page,
type: "head_queries",
},
}),
headers: {
Expand Down Expand Up @@ -110,7 +113,8 @@ export const getRAGQueries = async (
credentials: "include",
method: "POST",
body: JSON.stringify({
rag_queries: payload,
...payload,
type: "rag_queries",
}),
headers: {
"TR-Dataset": datasetId,
Expand All @@ -137,7 +141,7 @@ export const getRAGUsage = async (
"Content-Type": "application/json",
},
body: JSON.stringify({
rag_usage: {},
type: "rag_usage",
}),
});

Expand All @@ -159,11 +163,10 @@ export const getLowConfidenceQueries = async (
credentials: "include",
method: "POST",
body: JSON.stringify({
low_confidence_queries: {
...transformAnalyticsParams(filters),
page,
threshold,
},
...transformAnalyticsParams(filters),
page,
threshold,
type: "low_confidence_queries",
}),
headers: {
"TR-Dataset": datasetId,
Expand All @@ -190,10 +193,9 @@ export const getNoResultQueries = async (
credentials: "include",
method: "POST",
body: JSON.stringify({
no_result_queries: {
...transformAnalyticsParams(filters),
page,
},
...transformAnalyticsParams(filters),
page,
type: "no_result_queries",
}),
headers: {
"TR-Dataset": datasetId,
Expand All @@ -219,7 +221,8 @@ export const getQueryCounts = async (
credentials: "include",
method: "POST",
body: JSON.stringify({
count_queries: transformAnalyticsParams(filters),
...transformAnalyticsParams(filters),
type: "count_queries",
}),
headers: {
"TR-Dataset": datasetId,
Expand Down Expand Up @@ -249,9 +252,8 @@ export const getSearchQuery = async (
"Content-Type": "application/json",
},
body: JSON.stringify({
query_details: {
search_id: searchId,
},
search_id: searchId,
type: "search_query",
}),
});

Expand Down
26 changes: 16 additions & 10 deletions frontends/analytics/src/api/trends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import { apiHost } from "../utils/apiHost";
export const getTrendsBubbles = async (
datasetId: string,
): Promise<SearchClusterTopics[]> => {
const response = await fetch(`${apiHost}/analytics/${datasetId}/topics`, {
const response = await fetch(`${apiHost}/analytics/search/clusters`, {
credentials: "include",
method: "POST",
headers: {
"TR-Dataset": datasetId,
"Content-Type": "application/json",
},
body: JSON.stringify({
type: "cluster_topics",
}),
});

if (!response.ok) {
Expand All @@ -32,16 +36,18 @@ export const getQueriesForTopic = async (
datasetId: string,
clusterId: string,
): Promise<SearchQueryEvent[]> => {
const response = await fetch(
`${apiHost}/analytics/${datasetId}/${clusterId}/1`,
{
credentials: "include",
headers: {
"TR-Dataset": datasetId,
"Content-Type": "application/json",
},
const response = await fetch(`${apiHost}/analytics/search/clusters`, {
credentials: "include",
method: "POST",
headers: {
"TR-Dataset": datasetId,
"Content-Type": "application/json",
},
);
body: JSON.stringify({
type: "cluster_queries",
cluster_id: clusterId,
}),
});

if (!response.ok) {
throw new Error(`Failed to fetch trends bubbles: ${response.statusText}`);
Expand Down
1 change: 1 addition & 0 deletions server/src/data/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3765,6 +3765,7 @@ pub enum RecommendationAnalytics {
}

#[derive(Debug, Serialize, Deserialize, ToSchema)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum ClusterAnalytics {
#[schema(title = "ClusterTopics")]
Expand Down
2 changes: 1 addition & 1 deletion server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ pub fn main() -> std::io::Result<()> {
)
.service(
web::resource("/search/clusters")
.route(web::get().to(handlers::analytics_handler::get_cluster_analytics)),
.route(web::post().to(handlers::analytics_handler::get_cluster_analytics)),
)
.service(
web::resource("/rag")
Expand Down
12 changes: 4 additions & 8 deletions server/src/operators/analytics_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ pub async fn get_clusters_query(
filters: Option<ClusterAnalyticsFilter>,
clickhouse_client: &clickhouse::Client,
) -> Result<SearchClusterResponse, ServiceError> {
let mut query_string =
String::from("SELECT ?fields FROM clusters WHERE dataset_id = ? ORDER BY density DESC");
let mut query_string = String::from(
"SELECT ?fields FROM cluster_topics WHERE dataset_id = ? ORDER BY density DESC",
);

if let Some(filters) = filters {
query_string = filters.add_to_query(query_string);
Expand Down Expand Up @@ -70,13 +71,8 @@ pub async fn get_queries_for_cluster_query(
JOIN search_cluster_memberships ON search_queries.id = search_cluster_memberships.search_id
WHERE search_cluster_memberships.cluster_id = ?
AND search_queries.dataset_id = ?
GROUP BY
?fields,
search_cluster_memberships.distance_to_centroid
ORDER BY
search_queries.request_params,
search_queries.query,
search_cluster_memberships.distance_to_centroid ASC
search_cluster_memberships.distance_to_centroid DESC
LIMIT 15
OFFSET ?
",
Expand Down

0 comments on commit 9259ea3

Please sign in to comment.