Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
08b093b
feat(logs): start working on log subscription, very much a WIP
christeredvartsen Oct 1, 2025
20fdd11
feat(wip): dummy log impl
sechmann Oct 1, 2025
e8a6954
feat: working mvp log subscription
sechmann Oct 6, 2025
17fe144
feat: add Duration scalar and adjust log types
christeredvartsen Oct 9, 2025
3f4b158
test(log): generate mock for querier
christeredvartsen Oct 9, 2025
fba4edf
refactor: rename package and fix failing tests
christeredvartsen Oct 9, 2025
abd8317
docs(logstreamer): alignment
christeredvartsen Oct 9, 2025
b6b0204
feat: simplify log subscription filter
christeredvartsen Oct 10, 2025
639b3fe
refactor: replace custom SSE transport
christeredvartsen Oct 10, 2025
f9f3e10
refactor: rename variable back to the original
christeredvartsen Oct 10, 2025
3b6a873
fix: more specific types in graph, default
sechmann Oct 10, 2025
24869ba
fix: rename remaining initial batch type/field
sechmann Oct 10, 2025
a3c1183
fix: remove debug print and fix field name
sechmann Oct 10, 2025
c8ebe69
fix: fmt
sechmann Oct 10, 2025
2a4669c
fix: rename field in graphql schema as well
sechmann Oct 10, 2025
f2ce826
chore: go mod tidy
christeredvartsen Oct 10, 2025
a208aef
docs(local): develop logging locally
sechmann Oct 13, 2025
60d14f5
docs(local): move logging docs to readme
sechmann Oct 13, 2025
e2bbed0
refactor: rename field
christeredvartsen Oct 15, 2025
d9dd543
feat: cluster/tenant/local Loki URLs
christeredvartsen Oct 15, 2025
17ed4f8
fix: incorrect Loki-host generation
christeredvartsen Oct 16, 2025
7bf3111
fix(loki): prevent closing channel while in use
sechmann Oct 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .configs/gqlgen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ autobind:
- "github.com/nais/api/internal/github/repository"
- "github.com/nais/api/internal/graph/model"
- "github.com/nais/api/internal/issue"
- "github.com/nais/api/internal/loki"
- "github.com/nais/api/internal/kubernetes/event/pubsublog"
- "github.com/nais/api/internal/persistence"
- "github.com/nais/api/internal/persistence/bigquery"
Expand Down Expand Up @@ -104,6 +105,10 @@ models:
model:
- github.com/nais/api/internal/graph/scalar.Date

Duration:
model:
- github.com/nais/api/internal/graph/scalar.Duration

Time:
model:
- github.com/nais/api/internal/graph/scalar.Time
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ Locally, most external services are replaced with fake clients, and the Kubernet
The test suite uses [testcontainers](https://testcontainers.com/), and if you are using Colima you might need to follow
the guidelines in the [testcontainers documentation](https://golang.testcontainers.org/system_requirements/using_colima/).

### Local development of logging API

To develop the logging API with real data:

```bash
TENANT_NAME="nav.no"
MANAGEMENT_CONTEXT="nav-management-v2"
narc jita grant k8s-admin "$TENANT_NAME" --duration 1h --reason "port forward for loki local testing"
kubectl --context "$MANAGEMENT_CONTEXT" --namespace nais-system port-forward svc/loki-query-frontend 3100 &
LOGGING_LOKI_ADDRESS="http://127.0.0.1:3100" mise run local && kill %%
```

## Development practices

Check practices used in this project here: [docs/practices.md](docs/practices.md)
Expand Down
119 changes: 113 additions & 6 deletions go.mod

Large diffs are not rendered by default.

519 changes: 497 additions & 22 deletions go.sum

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions internal/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/nais/api/internal/kubernetes/watchers"
"github.com/nais/api/internal/leaderelection"
"github.com/nais/api/internal/logger"
"github.com/nais/api/internal/loki"
"github.com/nais/api/internal/persistence/sqlinstance"
"github.com/nais/api/internal/servicemaintenance"
"github.com/nais/api/internal/thirdparty/aiven"
Expand Down Expand Up @@ -267,6 +268,16 @@ func run(ctx context.Context, cfg *Config, log logrus.FieldLogger) error {
}
}

var lokiClientOpts []loki.OptionFunc
if addr, ok := os.LookupEnv("LOGGING_LOKI_ADDRESS"); ok {
lokiClientOpts = append(lokiClientOpts, loki.WithLocalLoki(addr))
}

lokiClient, err := loki.NewClient(cfg.K8s.AllClusterNames(), cfg.Tenant, log.WithField("subsystem", "loki_client"), lokiClientOpts...)
if err != nil {
return fmt.Errorf("create loki client: %w", err)
}

// HTTP server
wg.Go(func() error {
return runHttpServer(
Expand All @@ -290,6 +301,7 @@ func run(ctx context.Context, cfg *Config, log logrus.FieldLogger) error {
cfg.Unleash.BifrostApiUrl,
cfg.Logging.DefaultLogDestinations(),
notifier,
lokiClient,
log.WithField("subsystem", "http"),
)
})
Expand Down
5 changes: 5 additions & 0 deletions internal/cmd/api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
apik8s "github.com/nais/api/internal/kubernetes"
"github.com/nais/api/internal/kubernetes/watcher"
"github.com/nais/api/internal/kubernetes/watchers"
"github.com/nais/api/internal/loki"
"github.com/nais/api/internal/persistence/bigquery"
"github.com/nais/api/internal/persistence/bucket"
"github.com/nais/api/internal/persistence/kafkatopic"
Expand Down Expand Up @@ -88,6 +89,7 @@ func runHttpServer(
bifrostAPIURL string,
defaultLogDestinations []logging.SupportedLogDestination,
notifier *notify.Notifier,
lokiClient loki.Client,
log logrus.FieldLogger,
) error {
router := chi.NewRouter()
Expand All @@ -112,6 +114,7 @@ func runHttpServer(
bifrostAPIURL,
defaultLogDestinations,
notifier,
lokiClient,
log,
)
if err != nil {
Expand Down Expand Up @@ -208,6 +211,7 @@ func ConfigureGraph(
bifrostAPIURL string,
defaultLogDestinations []logging.SupportedLogDestination,
notifier *notify.Notifier,
lokiClient loki.Client,
log logrus.FieldLogger,
) (func(http.Handler) http.Handler, error) {
searcher, err := search.New(ctx, pool, log.WithField("subsystem", "search_bleve"))
Expand Down Expand Up @@ -302,6 +306,7 @@ func ConfigureGraph(
ctx = database.NewLoaderContext(ctx, pool)
ctx = issue.NewContext(ctx, pool)
ctx = team.NewLoaderContext(ctx, pool, watchers.NamespaceWatcher)
ctx = loki.NewLoaderContext(ctx, lokiClient)
ctx = user.NewLoaderContext(ctx, pool)
ctx = usersync.NewLoaderContext(ctx, pool)
ctx = cost.NewLoaderContext(ctx, pool, costOpts...)
Expand Down
Loading