Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multiple handler using property #6

Merged
merged 5 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/wiki/Home/Concepts.drawio
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<mxfile host="www.draw.io" modified="2019-09-22T17:50:03.465Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36" etag="uizNME9ICfU3oy_90uSI" version="11.3.0" type="device" pages="1"><diagram id="wvHNQMgyaNsvq5nBhGJc" name="Page-1">7Vlbb9sgGP01kbaHTb47eWwuW7u1WqW06vZIbWp7ImBhnMT99QMbxzG4UZcmcdvtoSocwwecY04+8MCeLNZfKUjjKxJCNLCMcD2wpwPLMh3T4v8EUlSI7xgVENEklI0aYJ48QgnWzfIkhFmrISMEsSRtgwHBGAashQFKyard7IGg9qgpiKAGzAOAdPQuCVlcoUPLb/BzmERxPbLpjaonC1A3livJYhCS1RZkzwb2hBLCqtJiPYFIkFfzUvX78sTTzcQoxOw5HX58c4t0Zoyuw1s3vL1aztZXN588OTdW1AuGIV+/rBLKYhIRDNCsQceU5DiEIqrBa02bS0JSDpoc/A0ZK6SYIGeEQzFbIPm0GlMM9ORSJJSRnAZwx/zrVwLQCLId7dwN4fxNhWQBGS14PwoRYMmyPQ8gX5lo065hlRcksX9Bsoy7BCiXI13gNGcc+sD/yo2TMMiLHweWh/gyxveUlyJWcrUfoqjaaCYEWInx5ikoqV3x8bv0WULK4Hq3QjqjdQfTrbrIbW8Zchesmk1kDiUWb20g3ziSCJYmQk38hJtW0DtjlqEwZuuMjToIc45FmN+HNXCyaPFT9i8rv0Tls1tXp+vth9NC1g5oKfZbsBR7p6Vc4AeUr6fjl1jKKzMQ2+rbQJwOyiuaX4mBmKM2Y57Tr4HUKdw/5yDuMx1k2GtSYv5XZ6c6oz7VcbuzFYjhNSUBzDJCezccp87p6ozF7bBot8NxhsdynKHG2ndYzBmh8BzgEMH+OfMchbOuvNjq4Mw7FmcjjbMpYOBVk9aZC5yUtPpWY4s13U1xeCYuIHgNEyzcMwRZvKFtj/OwTtAWAV0brcae7VlyhGuSYNbwP2rT71gKrZXlyk7bNxC745hqnMqStTilQptFv0A0PWl+x6LZ/oFUUwOdXDY98X7HsrlDRTZ7T9nUQKYa6Niy6SnMO5ZtaBxINjXQyWXzNNnkzYKiHf85Z22NKMySR3BfNhA5eyrmWM7aHQ/cKUfEeSCrjgaiA0BJhHkZwQcRSuQISQDQmYSZOFOMM55ZJDi6KQ8Y/BB+oMs2W2FZPys7HW+Lan2HSyh8jfanE/03Tb3jqi+4Tr1/Uur1U4PIfsV3Icu4BEVHAvymBfDU3/MOAbruifYQgFeb71uVQzVfCe3ZHw==</diagram></mxfile>
<mxfile host="www.draw.io" modified="2019-10-12T06:14:11.784Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36" etag="bCDYipjau9U8NzYG4sm9" version="12.1.0" type="device" pages="1"><diagram id="wvHNQMgyaNsvq5nBhGJc" name="Page-1">7Vlbb9sgGP01kbaHTb7EcfLYXNZ2a7RKabXtkcbUZiJgYXJxf/3AxrENbpaluTXaQ1U4/ridAycfdssdzFbXDMTRmAYQtxwrWLXcYctxbNt3xD+JpDniO50cCBkKVFAJTNALVKCl0DkKYFIL5JRijuI6OKWEwCmvYYAxuqyHPVNcHzUGITSAyRRgE/2BAh7laNfxS/wGojAqRrY7vfzJDBTBaiVJBAK6rEDuqOUOGKU8L81WA4gleQUvebsvrzxdT4xBwrdp8P2rl8Yjq3cfPHrB43gxWo0fPikxEp4WC4aBWL+qUsYjGlIC8KhE+4zOSQBlr5aolTF3lMYCtAX4G3KeKjHBnFMBRXyG1VNz5moxCZ2zKdww3WIHABZCviHOy+PkWioDKF6uIZ1BzlIRwCAGHC3qWgO1ZcJ1XMmqKChi/4Fk1e8C4Lka6ZbEcy6gD+IvOziIQ1H82HI6WKyr/8REKeQZV7shmqqlZlKApRxvEoOM66UYf0t9FpBxuNrI6PrgKwnUsXcsdQqW5SGyuwqLKgfItw4kgmOIUBKv0zcWI6LpgJJswezkbDqWxqZrstlrILN9KDL9U9iG4I+lP1X7rPJLVj57RXW4qj4cpqq2u92479Ju3I12c0ue8Xw17L/Fbs7MXFzn1ObSbqC8oLnBXBA7Y3NxvRObS5H6Xbq7eFu6S/es3MW2/6tTjeudlTpec5YDCbxndAqThJ7ecNpFLlhkMw2GY3sNjtM9lON0Dda+wXTCKYM3gAT4DEy609Y4a8qnnQbOOofirGdwNgQcnDVpjXnCUUmzzVuI6aYkuJIvLkSNUCLdMwBJtKZtG4r+akYVApoOWoFt7VlqhHuKCC/579XpbzsarbkHq0bVNxeb+7H1fnKPNvrJFFov+g2imQn1BYvm+ntSTe/o6LKZSfkFy+Z1NdncHWXTO7L1jg4tm5nCXLBsXWtPsukdHV22jiGbeuugaSd+u3ldIwYT9AKesgCZs8dyjtmsvX7LGwpE3geS/GogGwCMQiLKGD7LrmRCgKYAXymYyztFPxGZBSLhQ3bBEBf0Pd2VXY1lZTKV3dJu2C269e0vofAN2l9P9N819W1P3+Am9f5RqTdvDTL7ld+THOsOpA0J8LsWoKP/njcI0PSeaAcBRLX8LpY7VPl10R39AQ==</diagram></mxfile>
Binary file modified docs/wiki/Home/Concepts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.graphene.writer

import com.graphene.writer.config.GrapheneWriterConfiguration
import com.graphene.writer.store.key.ElasticsearchKeyStoreProperties
import com.graphene.writer.config.StatsConfiguration
import com.graphene.writer.store.data.CassandraDataStoreProperties
import com.graphene.writer.config.CarbonConfiguration
import com.graphene.writer.config.StatsProperty
import com.graphene.writer.store.data.CassandraDataStoreHandlerProperty
import com.graphene.writer.input.graphite.property.CarbonProperty
import com.graphene.writer.blacklist.BlacklistConfiguration
import com.graphene.writer.input.graphite.property.GraphiteInputProperty
import com.graphene.writer.store.data.StoreDataProperty
import com.graphene.writer.store.key.model.SimpleKeyStoreHandlerProperty
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
Expand All @@ -20,10 +22,12 @@ import org.springframework.scheduling.annotation.EnableAsync
@EnableConfigurationProperties(
BlacklistConfiguration::class,
GrapheneWriterConfiguration::class,
CarbonConfiguration::class,
ElasticsearchKeyStoreProperties::class,
StatsConfiguration::class,
CassandraDataStoreProperties::class
CarbonProperty::class,
StatsProperty::class,
CassandraDataStoreHandlerProperty::class,
GraphiteInputProperty::class,
StoreDataProperty::class,
SimpleKeyStoreHandlerProperty::class
)
class GrapheneWriterApplication

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package com.graphene.writer.config

import com.graphene.writer.store.data.CassandraDataStoreProperties
import com.graphene.writer.store.key.ElasticsearchKeyStoreProperties
import com.graphene.writer.store.data.CassandraDataStoreHandlerProperty
import org.springframework.boot.context.properties.ConfigurationProperties

/**
* @author Andrei Ivanov
*/
@ConfigurationProperties(prefix = "graphene.writer")
class GrapheneWriterConfiguration(
var carbon: CarbonConfiguration,
var cassandraDataStore: CassandraDataStoreProperties,
var elasticsearchKeyStore: ElasticsearchKeyStoreProperties,
var stats: StatsConfiguration
var cassandraDataStoreHandlerProperty: CassandraDataStoreHandlerProperty,
var statsProperty: StatsProperty
) {

override fun toString(): String {
return "GrapheneWriterConfiguration{" +
"carbon=" + carbon +
", cassandraDataStore=" + cassandraDataStore +
", elasticsearchKeyStore=" + elasticsearchKeyStore +
", stats=" + stats +
", cassandraDataStoreHandlerProperty=" + cassandraDataStoreHandlerProperty +
", statsProperty=" + statsProperty +
'}'.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.net.UnknownHostException
* @author Andrei Ivanov
*/
@ConfigurationProperties(prefix = "graphene.writer.stats")
class StatsConfiguration {
class StatsProperty {

var interval: Int = 0
var tenant: String? = null
Expand All @@ -33,7 +33,7 @@ class StatsConfiguration {
}

override fun toString(): String {
return "StatsConfiguration{" +
return "StatsProperty{" +
"interval=" + interval +
", tenant='" + tenant + '\''.toString() +
", hostname='" + hostname + '\''.toString() +
Expand All @@ -43,6 +43,6 @@ class StatsConfiguration {

companion object {

private val logger = LoggerFactory.getLogger(StatsConfiguration::class.java)
private val logger = LoggerFactory.getLogger(StatsProperty::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.graphene.writer.event

import com.graphene.writer.config.StatsConfiguration
import com.graphene.writer.config.StatsProperty
import com.graphene.writer.util.NamedThreadFactory
import org.apache.log4j.Logger
import org.joda.time.DateTime
Expand All @@ -22,7 +22,7 @@ import javax.annotation.PostConstruct
@Component
@ManagedResource("com.graphene.writer.stats:name=GrapheneStats,type=GrapheneWriterEventListener")
class GrapheneWriterEventListener(
private val statsConfiguration: StatsConfiguration
private val statsProperty: StatsProperty
) {

private val logger = Logger.getLogger(GrapheneWriterEventListener::class.java)
Expand All @@ -49,7 +49,7 @@ class GrapheneWriterEventListener(
@PostConstruct
fun init() {
this.scheduler = Executors.newScheduledThreadPool(1, NamedThreadFactory(SCHEDULER_NAME))
this.scheduler.scheduleAtFixedRate({ flush() }, 60 - System.currentTimeMillis() / 1000L % 60, statsConfiguration.interval.toLong(), TimeUnit.SECONDS)
this.scheduler.scheduleAtFixedRate({ flush() }, 60 - System.currentTimeMillis() / 1000L % 60, statsProperty.interval.toLong(), TimeUnit.SECONDS)
}

private fun getStatsRecord(tenant: String): StatsRecord {
Expand Down Expand Up @@ -78,13 +78,13 @@ class GrapheneWriterEventListener(
}

private fun doFlush(stats: Map<String, StatsRecord>, storeSuccess: Long, storeError: Long, timestamp: Long) {
logger.debug("Flushing stats for $timestamp")
logger.debug("Flushing statsProperty for $timestamp")

var totalReceived: Long = 0
var totalWritten: Long = 0

if (statsConfiguration.isLog) {
logger.info("Graphene stats:")
if (statsProperty.isLog) {
logger.info("Graphene statsProperty:")
logger.info("=========================================================================")
logger.info("Tenant\t\tmetrics_received\t\twrite_count")
logger.info("=========================================================================")
Expand All @@ -97,7 +97,7 @@ class GrapheneWriterEventListener(

lastMetricsReceivedPerTenant[tenant] = statsRecord.getMetricsReceived()

if (statsConfiguration.isLog) {
if (statsProperty.isLog) {
logger.info(tenant + "\t\t" + statsRecord.metricsReceived + "\t\t" + statsRecord.getMetricsWritten())
}
}
Expand All @@ -107,7 +107,7 @@ class GrapheneWriterEventListener(
lastStoreSuccess = storeSuccess
lastStoreError = storeError

if (statsConfiguration.isLog) {
if (statsProperty.isLog) {
logger.info("total\t\t$totalReceived\t\t$totalWritten")
logger.info("=========================================================================")
logger.info("store.success:\t\t$storeSuccess")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package com.graphene.writer.input
* @since 1.0.0
* @author dark
*/
interface Codec<T> {
interface MetricConverter<T> {

fun encode(metric: T): GrapheneMetric
fun convert(metric: T): GrapheneMetric

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.graphene.writer.input.graphite

import com.graphene.writer.input.graphite.property.GraphiteInputProperty
import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.*
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.SocketChannel
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder
import io.netty.handler.codec.Delimiters
import com.graphene.writer.config.GrapheneWriterConfiguration
import org.apache.log4j.Logger
import org.springframework.stereotype.Component

Expand All @@ -20,7 +20,7 @@ import javax.annotation.PreDestroy
*/
@Component
class CarbonServer(
private val configuration: GrapheneWriterConfiguration,
private val property: GraphiteInputProperty,
private val carbonServerHandler: CarbonServerHandler
) {

Expand Down Expand Up @@ -52,7 +52,7 @@ class CarbonServer(
})

// Start the server.
b.bind(configuration.carbon.bind, configuration.carbon.port).sync()
b.bind(property.carbon.bind, property.carbon.port).sync()
}

@PreDestroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import io.netty.util.CharsetUtil
import com.graphene.writer.domain.Metric
import com.graphene.writer.config.GrapheneWriterConfiguration
import com.graphene.writer.config.Rollup
import com.graphene.writer.input.graphite.property.CarbonProperty
import org.apache.log4j.Logger
import org.springframework.stereotype.Component
import javax.annotation.PostConstruct
Expand All @@ -20,19 +20,19 @@ import javax.annotation.PostConstruct
@Component
@ChannelHandler.Sharable
class CarbonServerHandler(
private val configuration: GrapheneWriterConfiguration,
private val grapheneProcessor: GrapheneProcessor
private val carbonProperty: CarbonProperty,
private val grapheneProcessor: GrapheneProcessor
) : ChannelInboundHandlerAdapter() {

private val logger = Logger.getLogger(CarbonServerHandler::class.java)

private lateinit var rollup: Rollup
private lateinit var graphiteCodec: GraphiteCodec
private lateinit var graphiteCodec: GraphiteMetricConverter

@PostConstruct
fun init() {
this.rollup = configuration.carbon.baseRollup!!
this.graphiteCodec = GraphiteCodec()
this.rollup = carbonProperty.baseRollup!!
this.graphiteCodec = GraphiteMetricConverter()
}

@Throws(Exception::class)
Expand All @@ -46,7 +46,7 @@ class CarbonServerHandler(
}

if (CharMatcher.ASCII.matchesAllOf(metric.path) && CharMatcher.ASCII.matchesAllOf(metric.tenant)) {
grapheneProcessor.process(graphiteCodec.encode(GraphiteMetric(metric.path, metric.value, normalizeTimestamp(metric.timestamp))))
grapheneProcessor.process(graphiteCodec.convert(GraphiteMetric(metric.path, metric.value, normalizeTimestamp(metric.timestamp))))
} else {
logger.warn("Non ASCII characters received, discarding: $metric")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.graphene.writer.input.graphite

import com.graphene.writer.input.Codec
import com.graphene.writer.input.MetricConverter
import com.graphene.writer.input.GrapheneMetric
import net.iponweb.disthene.reader.utils.MetricRule
import java.util.*

class GraphiteCodec : Codec<GraphiteMetric> {
class GraphiteMetricConverter : MetricConverter<GraphiteMetric> {

override fun encode(metric: GraphiteMetric): GrapheneMetric {
override fun convert(metric: GraphiteMetric): GrapheneMetric {
return GrapheneMetric(
Collections.emptyMap(),
convertTags(metric),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.graphene.writer.config
package com.graphene.writer.input.graphite.property

import com.graphene.writer.config.Rollup
import org.slf4j.LoggerFactory
import org.springframework.boot.context.properties.ConfigurationProperties

import javax.annotation.PostConstruct
import java.util.ArrayList

/**
* @author Andrei Ivanov
*/
@ConfigurationProperties(prefix = "graphene.writer.carbon")
class CarbonConfiguration {
@ConfigurationProperties(prefix = "graphene.writer.input.graphite.carbon")
class CarbonProperty {

var bind: String? = null
var port: Int = 0
Expand All @@ -20,15 +20,14 @@ class CarbonConfiguration {
field = rollups.subList(1, rollups.size)
}
var baseRollup: Rollup? = null
private set

@PostConstruct
fun init() {
logger.info("Load Graphene carbon configuration : {}", toString())
}

override fun toString(): String {
return "CarbonConfiguration{" +
return "CarbonProperty{" +
"bind='" + bind + '\''.toString() +
", port=" + port +
", rollups=" + this.rollups +
Expand All @@ -38,6 +37,6 @@ class CarbonConfiguration {

companion object {

private val logger = LoggerFactory.getLogger(CarbonConfiguration::class.java)
private val logger = LoggerFactory.getLogger(CarbonProperty::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.graphene.writer.input.graphite.property

import org.slf4j.LoggerFactory
import org.springframework.boot.context.properties.ConfigurationProperties
import javax.annotation.PostConstruct

@ConfigurationProperties(prefix = "graphene.writer.input.graphite")
class GraphiteInputProperty(
var carbon: CarbonProperty
) {

@PostConstruct
fun init() {
logger.info("Load Graphene graphite input configuration : {}", toString())
}

override fun toString(): String {
return "GraphiteInputProperty{carbon=$carbon}"
}

companion object {

private val logger = LoggerFactory.getLogger(GraphiteInputProperty::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.graphene.writer.store

import com.graphene.writer.store.key.ElasticsearchKeyStoreProperties
import com.graphene.writer.store.data.CassandraDataStoreProperties
import com.graphene.writer.input.graphite.property.CarbonProperty
import com.graphene.writer.store.data.CassandraDataStoreHandler
import com.graphene.writer.store.data.CassandraDataStoreHandlerProperty
import com.graphene.writer.store.data.CassandraFactory
import com.graphene.writer.store.key.ElasticsearchFactory
import com.graphene.writer.config.CarbonConfiguration
import com.graphene.writer.store.key.SimpleKeyStoreHandler
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

Expand All @@ -15,25 +12,14 @@ class GrapheneStoreConfig {

@Bean
fun cassandraDataStoreHandler(
carbonConfiguration: CarbonConfiguration,
properties: CassandraDataStoreProperties
carbonProperty: CarbonProperty,
handlerProperty: CassandraDataStoreHandlerProperty
): StoreHandler {

return CassandraDataStoreHandler(
carbonConfiguration,
properties,
carbonProperty,
handlerProperty,
CassandraFactory()
)
}

@Bean
fun elasticsearchKeyStoreHandler(
properties: ElasticsearchKeyStoreProperties
): StoreHandler {

return SimpleKeyStoreHandler(
ElasticsearchFactory(properties),
properties
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ interface StoreHandler {
fun handle(grapheneMetric: GrapheneMetric)

}

interface KeyStoreHandler : StoreHandler

interface DataStoreHandler : StoreHandler
Loading