<commit_before>package com.peterphi.servicemanager.service.rest.impl;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.peterphi.servicemanager.service.db.entity.ServiceInstanceEntity;
import com.peterphi.servicemanager.service.logging.LogLineTableEntity;
import com.peterphi.servicemanager.service.logging.hub.LoggingService;
import com.peterphi.std.guice.common.logging.logreport.LogLine;
import com.peterphi.std.guice.common.logging.logreport.LogReport;
import com.peterphi.std.guice.common.logging.rest.iface.ServiceManagerLoggingRestService;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;

import java.util.ArrayList;
import java.util.List;

@Singleton
public class ServiceManagerLoggingRestServiceImpl implements ServiceManagerLoggingRestService
{
	private static final Logger log = Logger.getLogger(ServiceManagerLoggingRestServiceImpl.class);

	@Inject
	LoggingService service;

	@Inject
	ServiceIdCache cache;


	@Override
	public void report(final LogReport logs)
	{
		if (log.isTraceEnabled())
			log.trace("Received " + logs.getLines().length + " log lines to store");

		try
		{
			final ServiceInstanceEntity serviceInstance = cache.get(logs.getServiceId());

			// Make sure that all store calls are for the same partition (date + instance id)
			// This is technically only a requirement for Azure but it's a guarantee other
			// stores can use effectively (e.g. writing to datestamped log files)
			String partitionKey = null;
			List<LogLineTableEntity> pending = new ArrayList<>();
			for (LogLine line : logs.getLines())
			{
				LogLineTableEntity entity = convert(serviceInstance, line);

				if (partitionKey == null)
				{
					// First entry in a new partition
					partitionKey = entity.getPartitionKey();
				}
				else if (!partitionKey.equals(entity.getPartitionKey()))
				{
					// Flush all the lines up til now and then start a new list
					service.store(pending);
					pending.clear();
					partitionKey = entity.getPartitionKey();
				}
			}

			// Make sure we flush any remaining data to the storage system
			service.store(pending);
		}
		catch (Throwable t)
		{
			log.error("Error saving logs", t);
			throw t;<commit_msg>Bugfix: logs weren't actually being stored<commit_after>package com.peterphi.servicemanager.service.rest.impl;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.peterphi.servicemanager.service.db.entity.ServiceInstanceEntity;
import com.peterphi.servicemanager.service.logging.LogLineTableEntity;
import com.peterphi.servicemanager.service.logging.hub.LoggingService;
import com.peterphi.std.guice.common.logging.logreport.LogLine;
import com.peterphi.std.guice.common.logging.logreport.LogReport;
import com.peterphi.std.guice.common.logging.rest.iface.ServiceManagerLoggingRestService;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;

import java.util.ArrayList;
import java.util.List;

@Singleton
public class ServiceManagerLoggingRestServiceImpl implements ServiceManagerLoggingRestService
{
	private static final Logger log = Logger.getLogger(ServiceManagerLoggingRestServiceImpl.class);

	@Inject
	LoggingService service;

	@Inject
	ServiceIdCache cache;


	@Override
	public void report(final LogReport logs)
	{
		if (log.isTraceEnabled())
			log.trace("Received " + logs.getLines().length + " log lines to store");

		try
		{
			final ServiceInstanceEntity serviceInstance = cache.get(logs.getServiceId());

			// Make sure that all store calls are for the same partition (date + instance id)
			// This is technically only a requirement for Azure but it's a guarantee other
			// stores can use effectively (e.g. writing to datestamped log files)
			String partitionKey = null;
			List<LogLineTableEntity> pending = new ArrayList<>();
			for (LogLine line : logs.getLines())
			{
				LogLineTableEntity entity = convert(serviceInstance, line);

				if (partitionKey == null)
				{
					// First entry in a new partition
					partitionKey = entity.getPartitionKey();
				}
				else if (!partitionKey.equals(entity.getPartitionKey()))
				{
					// Flush all the lines up til now and then start a new list
					service.store(pending);

					pending = new ArrayList<>();
					partitionKey = entity.getPartitionKey();
				}

				pending.add(entity);
			}

			// Make sure we flush any remaining data to the storage system
			service.store(pending);
		}
		catch (Throwable t)
		{
			log.error("Error saving logs", t);
			throw t;
{'fraction_non_alphanumeric': 0.09710467706013363, 'fraction_numerical': 0.00044543429844097997, 'mean_word_length': 4.258782201405152, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3443195', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1302, 'n_words': 341}