Missing custom labels from Alloy in Loki

I have a Loki listening for logs.

Here is an excerpt from the nginx config:

	log_format main escape=json '{'
      .............
	'}';

	access_log /var/log/nginx/access.log main;

I parse the logs and add labels using Alloy.
I don’t have errors from Alloy.

local.file_match "applogs" {
  path_targets = [
    {
      __address__ = "localhost",
      __path__ = "/var/log/nginx/access.log",
      job = "nginx",
      instance = "localhost",
    },
  ]
}

loki.source.file "local_files" {
  targets = local.file_match.applogs.targets
  tail_from_end = true

  forward_to = [
	loki.process.add_new_label.receiver,
  ]
}

loki.process "add_new_label" {
	stage.labels {
		values = {
			test = "test",
		}
	}
	stage.structured_metadata {
		values={
			test1="test1",
		}
	}

  forward_to = [
    loki.write.grafana_loki.receiver,
  ]
}


loki.write "grafana_loki" {
  endpoint {
    url = "http://loki:3100/loki/api/v1/push"
  }
}

Checking labels via the API also doesn’t lead to anything.

root@yqhkujvybp:/# curl -s ‘``http://localhost:3100/loki/api/v1/labels``’
{“status”:“success”,“data”:[“filename”,“instance”,“job”,“service_name”]}

I would be grateful for any help!

The scope is too wide, it’s hard to tell what exactly the issue is. I would recommend first to make sure your logs are actually landing in Loki. Maybe try to remove all customized parsing blocks first.

The logs are displayed in grafana.

One thing to note, stage.labels is a reference, for example in your config:

stage.labels {
		values = {
			test = "test",
		}
	}

"test" needs to be a reference to another field that’s either pre-existing or a processed field from a previous step. If you just want to test, use static_labels instead. See loki.process | Grafana Alloy documentation