github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/server/ingest/entryHandlers.go (about)

     1  /*
     2  Copyright 2023.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package ingestserver
    18  
    19  import (
    20  	"github.com/siglens/siglens/pkg/config"
    21  	esutils "github.com/siglens/siglens/pkg/es/utils"
    22  	eswriter "github.com/siglens/siglens/pkg/es/writer"
    23  	"github.com/siglens/siglens/pkg/health"
    24  	"github.com/siglens/siglens/pkg/hooks"
    25  	influxwriter "github.com/siglens/siglens/pkg/influx/writer"
    26  	"github.com/siglens/siglens/pkg/instrumentation"
    27  	"github.com/siglens/siglens/pkg/integrations/loki"
    28  	otsdbwriter "github.com/siglens/siglens/pkg/integrations/otsdb/writer"
    29  	prometheuswriter "github.com/siglens/siglens/pkg/integrations/prometheus/ingest"
    30  	"github.com/siglens/siglens/pkg/integrations/splunk"
    31  	"github.com/siglens/siglens/pkg/otlp"
    32  	"github.com/siglens/siglens/pkg/sampledataset"
    33  	serverutils "github.com/siglens/siglens/pkg/server/utils"
    34  	"github.com/valyala/fasthttp"
    35  )
    36  
    37  func processKibanaIngestRequest(ctx *fasthttp.RequestCtx, request map[string]interface{},
    38  	indexNameConverted string, updateArg bool, idVal string, tsNow uint64, myid uint64) error {
    39  	return nil
    40  }
    41  
    42  func esPostBulkHandler() func(ctx *fasthttp.RequestCtx) {
    43  	return func(ctx *fasthttp.RequestCtx) {
    44  		instrumentation.IncrementInt64Counter(instrumentation.POST_REQUESTS_COUNT, 1)
    45  
    46  		if hook := hooks.GlobalHooks.KibanaIngestHandlerHook; hook != nil {
    47  			hook(ctx)
    48  		} else {
    49  			eswriter.ProcessBulkRequest(ctx, 0, processKibanaIngestRequest)
    50  		}
    51  	}
    52  }
    53  
    54  func getHealthHandler() func(ctx *fasthttp.RequestCtx) {
    55  	return func(ctx *fasthttp.RequestCtx) {
    56  		health.ProcessGetHealth(ctx)
    57  	}
    58  }
    59  
    60  func getSafeHealthHandler() func(ctx *fasthttp.RequestCtx) {
    61  	return func(ctx *fasthttp.RequestCtx) {
    62  		health.ProcessSafeHealth(ctx)
    63  	}
    64  }
    65  
    66  func splunkHecIngestHandler() func(ctx *fasthttp.RequestCtx) {
    67  	return func(ctx *fasthttp.RequestCtx) {
    68  		instrumentation.IncrementInt64Counter(instrumentation.POST_REQUESTS_COUNT, 1)
    69  		serverutils.CallWithOrgIdQuery(splunk.ProcessSplunkHecIngestRequest, ctx)
    70  	}
    71  }
    72  
    73  func EsPutIndexHandler() func(ctx *fasthttp.RequestCtx) {
    74  	return func(ctx *fasthttp.RequestCtx) {
    75  		serverutils.CallWithOrgId(eswriter.ProcessPutIndex, ctx)
    76  	}
    77  }
    78  
    79  func otsdbPutMetricsHandler() func(ctx *fasthttp.RequestCtx) {
    80  	return func(ctx *fasthttp.RequestCtx) {
    81  		serverutils.CallWithOrgIdQuery(otsdbwriter.PutMetrics, ctx)
    82  	}
    83  }
    84  
    85  func influxPutMetricsHandler() func(ctx *fasthttp.RequestCtx) {
    86  	return func(ctx *fasthttp.RequestCtx) {
    87  		serverutils.CallWithOrgIdQuery(influxwriter.PutMetrics, ctx)
    88  	}
    89  }
    90  
    91  func esGreetHandler() func(ctx *fasthttp.RequestCtx) {
    92  	return func(ctx *fasthttp.RequestCtx) {
    93  		esutils.ProcessGreetHandler(ctx)
    94  	}
    95  }
    96  
    97  func prometheusPutMetricsHandler() func(ctx *fasthttp.RequestCtx) {
    98  	return func(ctx *fasthttp.RequestCtx) {
    99  		prometheuswriter.PutMetrics(ctx)
   100  	}
   101  }
   102  
   103  func otlpIngestTracesHandler() func(ctx *fasthttp.RequestCtx) {
   104  	return func(ctx *fasthttp.RequestCtx) {
   105  		otlp.ProcessTraceIngest(ctx)
   106  	}
   107  }
   108  
   109  func sampleDatasetBulkHandler() func(ctx *fasthttp.RequestCtx) {
   110  	return func(ctx *fasthttp.RequestCtx) {
   111  		instrumentation.IncrementInt64Counter(instrumentation.POST_REQUESTS_COUNT, 1)
   112  		serverutils.CallWithOrgId(sampledataset.ProcessSyntheicDataRequest, ctx)
   113  	}
   114  }
   115  
   116  func postSetconfigHandler(persistent bool) func(ctx *fasthttp.RequestCtx) {
   117  	return func(ctx *fasthttp.RequestCtx) {
   118  		config.ProcessSetConfig(persistent, ctx)
   119  	}
   120  }
   121  
   122  func getConfigHandler() func(ctx *fasthttp.RequestCtx) {
   123  	return func(ctx *fasthttp.RequestCtx) {
   124  		config.ProcessGetConfigAsJson(ctx)
   125  	}
   126  }
   127  
   128  func getConfigReloadHandler() func(ctx *fasthttp.RequestCtx) {
   129  	return func(ctx *fasthttp.RequestCtx) {
   130  		config.ProcessForceReadConfig(ctx)
   131  	}
   132  }
   133  
   134  func lokiPostBulkHandler() func(ctx *fasthttp.RequestCtx) {
   135  	return func(ctx *fasthttp.RequestCtx) {
   136  		instrumentation.IncrementInt64Counter(instrumentation.POST_REQUESTS_COUNT, 1)
   137  		serverutils.CallWithOrgIdQuery(loki.ProcessLokiLogsIngestRequest, ctx)
   138  	}
   139  }