2023-06-20 07:55:12 +02:00
|
|
|
package vlinsert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2024-11-05 16:52:35 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/datadog"
|
2023-06-20 07:55:12 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/elasticsearch"
|
2024-10-27 20:36:33 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/journald"
|
2023-06-21 15:31:28 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/jsonline"
|
2023-07-20 10:10:55 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/loki"
|
2024-09-03 20:12:05 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/opentelemetry"
|
2024-06-17 12:13:18 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/syslog"
|
2023-06-20 07:55:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Init initializes vlinsert
|
|
|
|
func Init() {
|
2024-06-17 12:13:18 +02:00
|
|
|
syslog.MustInit()
|
2023-06-20 07:55:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop stops vlinsert
|
|
|
|
func Stop() {
|
2024-06-17 12:13:18 +02:00
|
|
|
syslog.MustStop()
|
2023-06-20 07:55:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// RequestHandler handles insert requests for VictoriaLogs
|
|
|
|
func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
|
|
|
|
path := r.URL.Path
|
2024-11-05 16:52:35 +01:00
|
|
|
|
2023-06-20 07:55:12 +02:00
|
|
|
if !strings.HasPrefix(path, "/insert/") {
|
2023-06-22 04:52:48 +02:00
|
|
|
// Skip requests, which do not start with /insert/, since these aren't our requests.
|
2023-06-20 07:55:12 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
path = strings.TrimPrefix(path, "/insert")
|
|
|
|
path = strings.ReplaceAll(path, "//", "/")
|
|
|
|
|
2023-06-22 04:39:22 +02:00
|
|
|
if path == "/jsonline" {
|
2024-06-17 12:13:18 +02:00
|
|
|
jsonline.RequestHandler(w, r)
|
|
|
|
return true
|
2023-06-22 04:39:22 +02:00
|
|
|
}
|
2023-06-20 07:55:12 +02:00
|
|
|
switch {
|
|
|
|
case strings.HasPrefix(path, "/elasticsearch/"):
|
|
|
|
path = strings.TrimPrefix(path, "/elasticsearch")
|
|
|
|
return elasticsearch.RequestHandler(path, w, r)
|
2023-07-20 10:10:55 +02:00
|
|
|
case strings.HasPrefix(path, "/loki/"):
|
|
|
|
path = strings.TrimPrefix(path, "/loki")
|
|
|
|
return loki.RequestHandler(path, w, r)
|
2024-09-03 20:12:05 +02:00
|
|
|
case strings.HasPrefix(path, "/opentelemetry/"):
|
|
|
|
path = strings.TrimPrefix(path, "/opentelemetry")
|
|
|
|
return opentelemetry.RequestHandler(path, w, r)
|
2024-10-27 20:36:33 +01:00
|
|
|
case strings.HasPrefix(path, "/journald/"):
|
|
|
|
path = strings.TrimPrefix(path, "/journald")
|
|
|
|
return journald.RequestHandler(path, w, r)
|
2024-11-05 16:52:35 +01:00
|
|
|
case strings.HasPrefix(path, "/datadog/"):
|
|
|
|
path = strings.TrimPrefix(path, "/datadog")
|
|
|
|
return datadog.RequestHandler(path, w, r)
|
2023-06-20 07:55:12 +02:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|