Include server version in logging tags
This commit is contained in:
		
							parent
							
								
									117de2382d
								
							
						
					
					
						commit
						76f5a71727
					
				| 
						 | 
				
			
			@ -518,6 +518,19 @@
 | 
			
		|||
        </executions>
 | 
			
		||||
      </plugin>
 | 
			
		||||
 | 
			
		||||
      <plugin>
 | 
			
		||||
        <groupId>org.codehaus.mojo</groupId>
 | 
			
		||||
        <artifactId>templating-maven-plugin</artifactId>
 | 
			
		||||
        <version>1.0.0</version>
 | 
			
		||||
        <executions>
 | 
			
		||||
          <execution>
 | 
			
		||||
            <id>filter-src</id>
 | 
			
		||||
            <goals>
 | 
			
		||||
              <goal>filter-sources</goal>
 | 
			
		||||
            </goals>
 | 
			
		||||
          </execution>
 | 
			
		||||
        </executions>
 | 
			
		||||
      </plugin>
 | 
			
		||||
    </plugins>
 | 
			
		||||
  </build>
 | 
			
		||||
</project>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2013-2021 Signal Messenger, LLC
 | 
			
		||||
 * SPDX-License-Identifier: AGPL-3.0-only
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package org.whispersystems.textsecuregcm;
 | 
			
		||||
 | 
			
		||||
public class WhisperServerVersion {
 | 
			
		||||
 | 
			
		||||
  private static final String VERSION = "${project.version}";
 | 
			
		||||
 | 
			
		||||
  public static String getServerVersion() {
 | 
			
		||||
    return VERSION;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -197,6 +197,7 @@ import org.whispersystems.textsecuregcm.workers.CertificateCommand;
 | 
			
		|||
import org.whispersystems.textsecuregcm.workers.DeleteUserCommand;
 | 
			
		||||
import org.whispersystems.textsecuregcm.workers.GetRedisCommandStatsCommand;
 | 
			
		||||
import org.whispersystems.textsecuregcm.workers.GetRedisSlowlogCommand;
 | 
			
		||||
import org.whispersystems.textsecuregcm.workers.ServerVersionCommand;
 | 
			
		||||
import org.whispersystems.textsecuregcm.workers.SetCrawlerAccelerationTask;
 | 
			
		||||
import org.whispersystems.textsecuregcm.workers.SetRequestLoggingEnabledTask;
 | 
			
		||||
import org.whispersystems.textsecuregcm.workers.VacuumCommand;
 | 
			
		||||
| 
						 | 
				
			
			@ -214,6 +215,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
 | 
			
		|||
    bootstrap.addCommand(new ZkParamsCommand());
 | 
			
		||||
    bootstrap.addCommand(new GetRedisSlowlogCommand());
 | 
			
		||||
    bootstrap.addCommand(new GetRedisCommandStatsCommand());
 | 
			
		||||
    bootstrap.addCommand(new ServerVersionCommand());
 | 
			
		||||
 | 
			
		||||
    bootstrap.addBundle(new NameableMigrationsBundle<WhisperServerConfiguration>("accountdb", "accountsdb.xml") {
 | 
			
		||||
      @Override
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,7 @@ import java.time.Duration;
 | 
			
		|||
import javax.validation.constraints.NotEmpty;
 | 
			
		||||
import net.logstash.logback.appender.LogstashTcpSocketAppender;
 | 
			
		||||
import net.logstash.logback.encoder.LogstashEncoder;
 | 
			
		||||
import org.whispersystems.textsecuregcm.WhisperServerVersion;
 | 
			
		||||
 | 
			
		||||
@JsonTypeName("logstashtcpsocket")
 | 
			
		||||
public class LogstashTcpSocketAppenderFactory extends AbstractAppenderFactory<ILoggingEvent> {
 | 
			
		||||
| 
						 | 
				
			
			@ -83,7 +84,8 @@ public class LogstashTcpSocketAppenderFactory extends AbstractAppenderFactory<IL
 | 
			
		|||
    }
 | 
			
		||||
    customFieldsNode.set("service", TextNode.valueOf("chat"));
 | 
			
		||||
    customFieldsNode.set("ddsource", TextNode.valueOf("logstash"));
 | 
			
		||||
    customFieldsNode.set("ddtags", TextNode.valueOf("env:" + environment));
 | 
			
		||||
    customFieldsNode.set("ddtags", TextNode.valueOf("env:" + environment + ",version:" + WhisperServerVersion.getServerVersion()));
 | 
			
		||||
 | 
			
		||||
    encoder.setCustomFields(customFieldsNode.toString());
 | 
			
		||||
    final LayoutWrappingEncoder<ILoggingEvent> prefix = new LayoutWrappingEncoder<>();
 | 
			
		||||
    final PatternLayout layout = new PatternLayout();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2013-2021 Signal Messenger, LLC
 | 
			
		||||
 * SPDX-License-Identifier: AGPL-3.0-only
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package org.whispersystems.textsecuregcm.workers;
 | 
			
		||||
 | 
			
		||||
import io.dropwizard.cli.Command;
 | 
			
		||||
import io.dropwizard.setup.Bootstrap;
 | 
			
		||||
import net.sourceforge.argparse4j.inf.Namespace;
 | 
			
		||||
import net.sourceforge.argparse4j.inf.Subparser;
 | 
			
		||||
import org.whispersystems.textsecuregcm.WhisperServerVersion;
 | 
			
		||||
 | 
			
		||||
public class ServerVersionCommand extends Command {
 | 
			
		||||
 | 
			
		||||
  public ServerVersionCommand() {
 | 
			
		||||
    super("version", "Print the version of the service");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void configure(final Subparser subparser) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception {
 | 
			
		||||
    System.out.println(WhisperServerVersion.getServerVersion());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue