- Use Google Distroless images for all services (Go & Node.js). - Standardize documentation with [PROJECT-NAME].md. - Add .dockerignore and .gitignore to all projects. - Remove docker-compose.yml in favor of docker run instructions. - Fix Go version and dependency issues in observability, repo-integrations, and security-governance. - Add Podman support (fully qualified image names). - Update Dashboard to use Node.js static server for Distroless compatibility.
78 lines
No EOL
1.9 KiB
Go
78 lines
No EOL
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/lab/observability-core/internal/alerter"
|
|
"github.com/lab/observability-core/internal/collector"
|
|
"github.com/lab/observability-core/internal/config"
|
|
"github.com/lab/observability-core/internal/db"
|
|
)
|
|
|
|
type application struct {
|
|
config *config.Config
|
|
queries *db.Queries
|
|
}
|
|
|
|
func main() {
|
|
cfg := config.Load()
|
|
|
|
pool, err := pgxpool.New(context.Background(), cfg.DatabaseURL)
|
|
if err != nil {
|
|
log.Fatalf("Unable to connect to database: %v\n", err)
|
|
}
|
|
defer pool.Close()
|
|
|
|
queries := db.New(pool)
|
|
|
|
app := &application{
|
|
config: cfg,
|
|
queries: queries,
|
|
}
|
|
|
|
coll := collector.New(queries)
|
|
coll.Start()
|
|
|
|
alert := alerter.New(queries)
|
|
alert.Start()
|
|
|
|
r := chi.NewRouter()
|
|
r.Use(middleware.Logger)
|
|
r.Use(middleware.Recoverer)
|
|
|
|
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("Observability Core"))
|
|
})
|
|
|
|
r.Post("/targets", app.createTargetHandler)
|
|
r.Post("/checks", app.createCheckHandler)
|
|
r.Get("/metrics", app.getMetricsHandler)
|
|
r.Get("/incidents", app.getIncidentsHandler)
|
|
|
|
log.Printf("Starting server on port %s", cfg.Port)
|
|
if err := http.ListenAndServe(fmt.Sprintf(":%s", cfg.Port), r); err != nil {
|
|
log.Fatalf("Could not start server: %s\n", err)
|
|
}
|
|
}
|
|
|
|
func (app *application) createTargetHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
func (app *application) createCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
func (app *application) getMetricsHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
}
|
|
|
|
func (app *application) getIncidentsHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
} |