|
| 1 | +package scorekeep; |
| 2 | + |
| 3 | +import com.amazonaws.xray.AWSXRay; |
| 4 | +import com.amazonaws.xray.AWSXRayRecorderBuilder; |
| 5 | +import com.amazonaws.xray.javax.servlet.AWSXRayServletFilter; |
| 6 | +import com.amazonaws.xray.plugins.EC2Plugin; |
| 7 | +import com.amazonaws.xray.strategy.sampling.DefaultSamplingStrategy; |
| 8 | +import org.apache.commons.logging.Log; |
| 9 | +import org.apache.commons.logging.LogFactory; |
| 10 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
| 11 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; |
| 12 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
| 13 | +import org.springframework.context.annotation.Bean; |
| 14 | +import org.springframework.context.annotation.Configuration; |
| 15 | +import org.springframework.context.annotation.Profile; |
| 16 | +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
| 17 | + |
| 18 | +import javax.servlet.Filter; |
| 19 | +import javax.sql.DataSource; |
| 20 | +import java.net.URL; |
| 21 | + |
| 22 | +@Configuration |
| 23 | +@EnableAutoConfiguration |
| 24 | +@EnableJpaRepositories("scorekeep") |
| 25 | +@Profile("pgsql") |
| 26 | +public class RdsWebConfig { |
| 27 | + private static final Log logger = LogFactory.getLog(WebConfig.class); |
| 28 | + |
| 29 | + @Bean |
| 30 | + public Filter TracingFilter() { |
| 31 | + return new AWSXRayServletFilter(); |
| 32 | + } |
| 33 | + |
| 34 | + @Bean |
| 35 | + public Filter SimpleCORSFilter() { |
| 36 | + return new SimpleCORSFilter(); |
| 37 | + } |
| 38 | + |
| 39 | + @Bean |
| 40 | + @ConfigurationProperties(prefix = "spring.datasource") |
| 41 | + public DataSource dataSource() { |
| 42 | + logger.info("Initializing PostgreSQL datasource"); |
| 43 | + return DataSourceBuilder.create() |
| 44 | + .driverClassName("org.postgresql.Driver") |
| 45 | + .url("jdbc:postgresql://" + System.getenv("RDS_HOSTNAME") + ":" + System.getenv("RDS_PORT") + "/ebdb") |
| 46 | + .username(System.getenv("RDS_USERNAME")) |
| 47 | + .password(System.getenv("RDS_PASSWORD")) |
| 48 | + .build(); |
| 49 | + } |
| 50 | + |
| 51 | + @Bean |
| 52 | + public GameHistoryModel gameHistoryModel() { |
| 53 | + return new GameHistoryModel(); |
| 54 | + } |
| 55 | + |
| 56 | + static { |
| 57 | + AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard().withPlugin(new EC2Plugin()); |
| 58 | + |
| 59 | + URL ruleFile = WebConfig.class.getResource("/sampling-rules.json"); |
| 60 | + builder.withSamplingStrategy(new DefaultSamplingStrategy(ruleFile)); |
| 61 | + |
| 62 | + AWSXRay.setGlobalRecorder(builder.build()); |
| 63 | + } |
| 64 | +} |
0 commit comments