Skip to content

Commit

Permalink
Logs AI query builder (#8753)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpennyNDaJets committed Jun 19, 2024
1 parent 0b96dd2 commit db025d3
Show file tree
Hide file tree
Showing 13 changed files with 1,004 additions and 47 deletions.
8 changes: 6 additions & 2 deletions backend/private-graph/graph/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8775,8 +8775,12 @@ And specifically, for the %s product, you can refer to the following documentati
response: fmt.Sprintf(`{"query":"level=error","date_range":{"start_date":"%s","end_date":"%s"}}`, sevenDaysBack, yesterdayAt2PM),
},
{
request: "All the traces from the private graph service",
response: `{"query":"service_name=private-graph","date_range":{"start_date":"","end_date":""}}`,
request: "All the traces from the private graph or public graph service",
response: `{"query":"service_name=private-graph OR service_name=public-graph","date_range":{"start_date":"","end_date":""}}`,
},
{
request: "Give me all the logs where the environment is production and the session is not null",
response: `{"query":"environment=production AND secure_session_id EXISTS","date_range":{"start_date":"","end_date":""}}`,
},
}

Expand Down
133 changes: 133 additions & 0 deletions frontend/src/__generated/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// src/components/Search/SearchForm/AiSearch/style.css.ts
var combobox = "_1k082jh4 mt0ih238 mt0ih23s mt0ih24c mt0ih24w";
var comboboxError = "_1k082jh5";
var comboboxGroup = "_1k082jhb mt0ih237 mt0ih23r";
var comboboxItem = "_1k082jh9";
var comboboxPopover = "_1k082jh7";
var comboboxResults = "_14ud0dc1";
var comboboxTagsContainer = "_1k082jhd";
var comboboxWithTags = "_1k082jh6";
var container = "_1k082jh0";
var containerError = "_1k082jh1";
var searchIcon = "_1k082jh2";
var toggle = "_1k082jhc";
export {
combobox,
comboboxError,
comboboxGroup,
comboboxItem,
comboboxPopover,
comboboxResults,
comboboxTagsContainer,
comboboxWithTags,
container,
containerError,
searchIcon,
toggle
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var comboboxTagsContainer = "_10xh0c25";
var errorToken = "_10xh0c28";
var searchIcon = "_10xh0c20";
var searchIconWithActions = "_10xh0c21";
var toggle = "_10xh0c2i";
var token = "_10xh0c27";
export {
combobox,
Expand All @@ -31,5 +32,6 @@ export {
errorToken,
searchIcon,
searchIconWithActions,
toggle,
token
};
38 changes: 38 additions & 0 deletions frontend/src/components/Search/SearchContext.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApolloError } from '@apollo/client'
import { createContext } from '@util/context/context'
import { useState } from 'react'
import { StringParam, useQueryParam } from 'use-query-params'
Expand All @@ -15,6 +16,14 @@ import { useSearchTime } from '@/hooks/useSearchTime'
export const SORT_COLUMN = 'sort_column'
export const SORT_DIRECTION = 'sort_direction'

export type AiSuggestion = {
query: string
dateRange: {
startDate?: Date
endDate?: Date
}
}

interface SearchContext extends Partial<ReturnType<typeof useSearchTime>> {
disabled: boolean
loading: boolean
Expand All @@ -32,6 +41,14 @@ interface SearchContext extends Partial<ReturnType<typeof useSearchTime>> {
resetMoreResults: () => void
histogramBucketSize?: DateHistogramBucketSize
pollingExpired: boolean
aiMode: boolean
setAiMode: (aiMode: boolean) => void
aiQuery: string
setAiQuery: (aiQuery: string) => void
onAiSubmit: (aiQuery: string) => void
aiSuggestion?: AiSuggestion
aiSuggestionLoading?: boolean
aiSuggestionError?: ApolloError
}

export const [useSearchContext, SearchContextProvider] =
Expand All @@ -51,6 +68,12 @@ interface Props extends Partial<ReturnType<typeof useSearchTime>> {
moreResults?: SearchContext['moreResults']
resetMoreResults?: SearchContext['resetMoreResults']
pollingExpired?: SearchContext['pollingExpired']
aiMode?: SearchContext['aiMode']
setAiMode?: SearchContext['setAiMode']
onAiSubmit?: SearchContext['onAiSubmit']
aiSuggestion?: SearchContext['aiSuggestion']
aiSuggestionLoading?: SearchContext['aiSuggestionLoading']
aiSuggestionError?: SearchContext['aiSuggestionError']
}

export const SearchContext: React.FC<Props> = ({
Expand All @@ -67,10 +90,17 @@ export const SearchContext: React.FC<Props> = ({
resetMoreResults = () => null,
setPage = () => null,
pollingExpired = false,
aiMode = false,
setAiMode = () => null,
onAiSubmit = () => null,
aiSuggestion,
aiSuggestionLoading,
aiSuggestionError,
...searchTimeContext
}) => {
const [queryParam] = useQueryParam('query', StringParam)
const [query, setQuery] = useState(queryParam ?? initialQuery)
const [aiQuery, setAiQuery] = useState('')
const { queryParts, tokens } = parseSearch(query)
const tokenGroups = buildTokenGroups(tokens)

Expand All @@ -93,6 +123,14 @@ export const SearchContext: React.FC<Props> = ({
setPage,
resetMoreResults,
pollingExpired,
aiMode,
aiQuery,
setAiQuery,
setAiMode,
onAiSubmit,
aiSuggestion,
aiSuggestionLoading,
aiSuggestionError,
...searchTimeContext,
}}
>
Expand Down
Loading

0 comments on commit db025d3

Please sign in to comment.