@@ -14,6 +14,24 @@ export interface IngestConfig {
1414export default function useIngest ( ) {
1515 const codeRunStore = useCodeRunStore ( )
1616
17+ const getPlaceholderByContentType = ( contentType : string ) : string => {
18+ if ( contentType === 'application/json' ) {
19+ return `[
20+ {"message": "hello world", "time": "2024-07-12T16:18:53.048"},
21+ {"message": "hello greptime", "time": "2024-07-12T16:18:53.048"}
22+ ]`
23+ }
24+
25+ if ( contentType === 'application/x-ndjson' ) {
26+ return `{"message": "hello world", "time": "2024-07-12T16:18:53.048"}
27+ {"message": "hello greptime", "time": "2024-07-12T16:18:53.048"}`
28+ }
29+
30+ // text/plain
31+ return `hello world 2024-07-12T16:18:53.048
32+ hello greptime 2024-07-12T16:18:53.048`
33+ }
34+
1735 const getInfluxdbInputConfig = ( precision : Ref < string > ) : IngestConfig => ( {
1836 type : 'influxdb' ,
1937 tabKey : 'influxdb-input' ,
@@ -29,19 +47,6 @@ export default function useIngest() {
2947 } ,
3048 } )
3149
32- const getLogIngestionInputConfig = ( pipeline : Ref < string > ) : IngestConfig => ( {
33- type : 'log-ingestion' ,
34- tabKey : 'log-ingestion-input' ,
35- submitLabel : 'Process' ,
36- placeholder : 'Enter your log data here...' ,
37- hasDoc : false ,
38- successMessage : 'Log processed successfully' ,
39- submitHandler : async ( content : string ) => { } ,
40- get params ( ) {
41- return { pipeline : pipeline . value }
42- } ,
43- } )
44-
4550 const getInfluxdbUploadConfig = ( precision : Ref < string > ) : IngestConfig => ( {
4651 type : 'influxdb' ,
4752 tabKey : 'influxdb-upload' ,
@@ -56,15 +61,45 @@ export default function useIngest() {
5661 } ,
5762 } )
5863
59- const getLogIngestionUploadConfig = ( pipeline : Ref < string > ) : IngestConfig => ( {
64+ const getLogIngestionInputConfig = (
65+ pipeline : Ref < string > ,
66+ table : Ref < string > ,
67+ contentType : Ref < string >
68+ ) : IngestConfig => ( {
69+ type : 'log-ingestion' ,
70+ tabKey : 'log-ingestion-input' ,
71+ submitLabel : 'Write' ,
72+ get placeholder ( ) {
73+ return getPlaceholderByContentType ( contentType . value )
74+ } ,
75+ hasDoc : false ,
76+ successMessage : 'Data written successfully' ,
77+ submitHandler : async ( content : string ) => {
78+ return codeRunStore . processLogs ( content , table . value , pipeline . value , contentType . value )
79+ } ,
80+ get params ( ) {
81+ return { pipeline : pipeline . value , table : table . value , contentType : contentType . value }
82+ } ,
83+ } )
84+
85+ const getLogIngestionUploadConfig = (
86+ pipeline : Ref < string > ,
87+ table : Ref < string > ,
88+ contentType : Ref < string >
89+ ) : IngestConfig => ( {
6090 type : 'log-ingestion' ,
6191 tabKey : 'log-ingestion-upload' ,
62- submitLabel : 'Process' ,
92+ submitLabel : 'Write' ,
93+ get placeholder ( ) {
94+ return getPlaceholderByContentType ( contentType . value )
95+ } ,
6396 hasDoc : false ,
64- successMessage : 'Log processed successfully' ,
65- submitHandler : async ( content : string ) => { } ,
97+ successMessage : 'Data written successfully' ,
98+ submitHandler : async ( content : string ) => {
99+ return codeRunStore . processLogs ( content , table . value , pipeline . value , contentType . value )
100+ } ,
66101 get params ( ) {
67- return { pipeline : pipeline . value }
102+ return { pipeline : pipeline . value , table : table . value , contentType : contentType . value }
68103 } ,
69104 } )
70105
0 commit comments