mirror of
				https://github.com/ohwgiles/laminar.git
				synced 2025-06-13 12:54:29 +00:00 
			
		
		
		
	only compress logs larger than a certain size
this fixes an issue where empty or very small logs resulted in a larger compressed log, which was truncated and cannot be decompressed
This commit is contained in:
		
							parent
							
								
									3068180f8e
								
							
						
					
					
						commit
						66b62f70f3
					
				@ -29,6 +29,8 @@
 | 
				
			|||||||
#include <boost/filesystem.hpp>
 | 
					#include <boost/filesystem.hpp>
 | 
				
			||||||
namespace fs = boost::filesystem;
 | 
					namespace fs = boost::filesystem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define COMPRESS_LOG_MIN_SIZE 1024
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <rapidjson/stringbuffer.h>
 | 
					#include <rapidjson/stringbuffer.h>
 | 
				
			||||||
#include <rapidjson/writer.h>
 | 
					#include <rapidjson/writer.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -139,14 +141,18 @@ void Laminar::sendStatus(LaminarClient* client) {
 | 
				
			|||||||
        } else { // it must be finished, fetch it from the database
 | 
					        } else { // it must be finished, fetch it from the database
 | 
				
			||||||
            db->stmt("SELECT output, outputLen FROM builds WHERE name = ? AND number = ?")
 | 
					            db->stmt("SELECT output, outputLen FROM builds WHERE name = ? AND number = ?")
 | 
				
			||||||
              .bind(client->scope.job, client->scope.num)
 | 
					              .bind(client->scope.job, client->scope.num)
 | 
				
			||||||
              .fetch<str,int>([=](str zipped, unsigned long sz) {
 | 
					              .fetch<str,int>([=](str maybeZipped, unsigned long sz) {
 | 
				
			||||||
                std::string log(sz+1,'\0');
 | 
					                std::string log(sz+1,'\0');
 | 
				
			||||||
                int res = ::uncompress((unsigned char*)&log[0], &sz,
 | 
					                if(sz < COMPRESS_LOG_MIN_SIZE) {
 | 
				
			||||||
                        (unsigned char*)zipped.data(), zipped.size());
 | 
					                    int res = ::uncompress((unsigned char*)&log[0], &sz,
 | 
				
			||||||
                if(res == Z_OK)
 | 
					                         (unsigned char*)maybeZipped.data(), maybeZipped.size());
 | 
				
			||||||
                    client->sendMessage(log);
 | 
					                    if(res == Z_OK)
 | 
				
			||||||
                else
 | 
					                        client->sendMessage(log);
 | 
				
			||||||
                    LLOG(ERROR, "Failed to uncompress log", res);
 | 
					                    else
 | 
				
			||||||
 | 
					                        LLOG(ERROR, "Failed to uncompress log");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    client->sendMessage(maybeZipped);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
@ -680,17 +686,22 @@ void Laminar::runFinished(Run * r) {
 | 
				
			|||||||
    time_t completedAt = time(0);
 | 
					    time_t completedAt = time(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // compress log
 | 
					    // compress log
 | 
				
			||||||
    std::string zipped(r->log.size(), '\0');
 | 
					    std::string maybeZipped = r->log;
 | 
				
			||||||
    size_t logsize = r->log.length();
 | 
					    size_t logsize = r->log.length();
 | 
				
			||||||
    size_t zippedSize = zipped.size();
 | 
					    if(r->log.length() >= COMPRESS_LOG_MIN_SIZE) {
 | 
				
			||||||
    ::compress((unsigned char*)&zipped[0], &zippedSize,
 | 
					        std::string zipped(r->log.size(), '\0');
 | 
				
			||||||
            (unsigned char*)&r->log[0], logsize);
 | 
					        size_t zippedSize = zipped.size();
 | 
				
			||||||
    zipped.resize(zippedSize);
 | 
					        if(::compress((unsigned char*)&zipped[0], &zippedSize,
 | 
				
			||||||
 | 
					            (unsigned char*)&r->log[0], logsize) == Z_OK) {
 | 
				
			||||||
 | 
					            zipped.resize(zippedSize);
 | 
				
			||||||
 | 
					            std::swap(maybeZipped, zipped);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string reason = r->reason();
 | 
					    std::string reason = r->reason();
 | 
				
			||||||
    db->stmt("INSERT INTO builds VALUES(?,?,?,?,?,?,?,?,?,?,?,?)")
 | 
					    db->stmt("INSERT INTO builds VALUES(?,?,?,?,?,?,?,?,?,?,?,?)")
 | 
				
			||||||
     .bind(r->name, r->build, node->name, r->queuedAt, r->startedAt, completedAt, int(r->result),
 | 
					     .bind(r->name, r->build, node->name, r->queuedAt, r->startedAt, completedAt, int(r->result),
 | 
				
			||||||
           zipped, logsize, r->parentName, r->parentBuild, reason)
 | 
					           maybeZipped, logsize, r->parentName, r->parentBuild, reason)
 | 
				
			||||||
     .exec();
 | 
					     .exec();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // notify clients
 | 
					    // notify clients
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user