| 
									
										
										
										
											2019-11-06 16:45:17 +01:00
										 |  |  | import ./make-test-python.nix ({ lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2019-06-27 18:11:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   name = "loki"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   meta = with lib.maintainers; { | 
					
						
							|  |  |  |     maintainers = [ willibutz ]; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   machine = { ... }: { | 
					
						
							|  |  |  |     services.loki = { | 
					
						
							|  |  |  |       enable = true; | 
					
						
							|  |  |  |       configFile = "${pkgs.grafana-loki.src}/cmd/loki/loki-local-config.yaml"; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-11-02 23:35:34 +01:00
										 |  |  |     services.promtail = { | 
					
						
							|  |  |  |       enable = true; | 
					
						
							|  |  |  |       configuration = { | 
					
						
							|  |  |  |         server = { | 
					
						
							|  |  |  |           http_listen_port = 9080; | 
					
						
							|  |  |  |           grpc_listen_port = 0; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         clients = [ { url = "http://localhost:3100/loki/api/v1/push"; } ]; | 
					
						
							|  |  |  |         scrape_configs = [ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             job_name = "system"; | 
					
						
							|  |  |  |             static_configs = [ | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 targets = [ "localhost" ]; | 
					
						
							|  |  |  |                 labels = { | 
					
						
							|  |  |  |                   job = "varlogs"; | 
					
						
							|  |  |  |                   __path__ = "/var/log/*log"; | 
					
						
							|  |  |  |                 }; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2019-06-27 18:11:09 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = ''
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:45:17 +01:00
										 |  |  |     machine.start | 
					
						
							|  |  |  |     machine.wait_for_unit("loki.service") | 
					
						
							|  |  |  |     machine.wait_for_unit("promtail.service") | 
					
						
							|  |  |  |     machine.wait_for_open_port(3100) | 
					
						
							|  |  |  |     machine.wait_for_open_port(9080) | 
					
						
							|  |  |  |     machine.succeed("echo 'Loki Ingestion Test' > /var/log/testlog") | 
					
						
							| 
									
										
										
										
											2020-11-10 10:36:53 +01:00
										 |  |  |     # should not have access to journal unless specified | 
					
						
							| 
									
										
										
										
											2020-12-28 00:37:13 +01:00
										 |  |  |     machine.fail( | 
					
						
							|  |  |  |         "systemctl show --property=SupplementaryGroups promtail | grep -q systemd-journal" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-11-06 16:45:17 +01:00
										 |  |  |     machine.wait_until_succeeds( | 
					
						
							|  |  |  |         "${pkgs.grafana-loki}/bin/logcli --addr='http://localhost:3100' query --no-labels '{job=\"varlogs\",filename=\"/var/log/testlog\"}' | grep -q 'Loki Ingestion Test'" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-06-27 18:11:09 +02:00
										 |  |  |   '';
 | 
					
						
							|  |  |  | }) |