Skip to content

Commit

Permalink
Merge pull request #178 from mokkun/custom-publisher-configuration
Browse files Browse the repository at this point in the history
Allow more than one custom Publisher
  • Loading branch information
cdsap authored May 18, 2020
2 parents 281c72c + 9c21da7 commit bd51f39
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 147 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,20 @@ Talaiot will send to the RethinkDb server defined in the configuration the value


#### Custom Publishers
Talaiot allows using custom Publishers defined by the requirements of your environment, in case you are using another implementation.
Check [here](https://github.com/cdsap/Talaiot/wiki/Publishers#custompublisher) how to define a custom publisher
Talaiot allows using custom publishers defined by the requirements of your environment, in case you are using another implementation.

```
talaiot {
publishers {
// You can define one or more custom publishers:
customPublishers(
MyCustomPublisher()
)
}
}
```

Read more about it in the [Publishers wiki page](https://github.com/cdsap/Talaiot/wiki/Publishers#custompublishers)

### Metrics
We can include extra information on the build and task tracked data during the build. This information will be added to the default metrics defined.
Expand Down
25 changes: 21 additions & 4 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,35 @@ dependencies {
talaiot {
logger = LogTracker.Mode.INFO
publishers {
// Publishers that don't require a configuration can be enabled or disabled with a flag.
// By default all publishers are disabled.
timelinePublisher = true
jsonPublisher = false

// Talaiot provides a few pre-defined publishers.
// Declaring a configuration for any of those publishers will enable them.
taskDependencyGraphPublisher {
html = true
gexf = true
}

influxDbPublisher {
dbName = "tracking"
url = "http://localhost:8086"
taskMetricName = "task"
buildMetricName = "build"
}
customPublisher = CustomPublisher()

// You can also define your own custom publishers:
customPublishers(
CustomPublisher(),
HelloPublisher()
)
}

metrics {
// Talaiot provides a few methods to disable a group of metrics at once
// By default all groups are enabled
// Talaiot provides a few methods to disable a group of metrics at once.
// By default all groups are enabled.
performanceMetrics = false
gradleSwitchesMetrics = false
environmentMetrics = false
Expand All @@ -65,13 +77,18 @@ talaiot {
class CustomPublisher : Publisher {
override fun publish(report: ExecutionReport) {
println("[CustomPublisher] : Number of tasks = ${report.tasks?.size}")
println("[CustomPublisher] : HelloMetric = ${report.customProperties.buildProperties["hello"]}")
println("[CustomPublisher] : Kotlin = ${report.customProperties.buildProperties["kotlin"]}")
println("[CustomPublisher] : Java = ${report.customProperties.buildProperties["java"]}")
println("[CustomPublisher] : PID = ${report.customProperties.taskProperties["pid"]}")
}
}

class HelloPublisher : Publisher {
override fun publish(report: ExecutionReport) {
println("[HelloPublisher] : HelloMetric = ${report.customProperties.buildProperties["hello"]}")
}
}

class HelloMetric : SimpleMetric<String>(
provider = { "Hello!" },
assigner = { report, value -> report.customProperties.buildProperties["hello"] = value }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.cdsap.talaiot.configuration


import com.cdsap.talaiot.publisher.Publisher
import com.cdsap.talaiot.publisher.*
import com.cdsap.talaiot.publisher.pushgateway.PushGatewayPublisher
import com.cdsap.talaiot.publisher.rethinkdb.RethinkDbPublisher
import com.cdsap.talaiot.publisher.timeline.TimelinePublisher
import groovy.lang.Closure
import org.gradle.api.Project


/**
* Main configuration for the publishers.
*
* It offers the accessors for Groovy and KTS
*
* ```
* publishers {
* influxDbPublisher {
* }
Expand All @@ -23,107 +26,93 @@ import org.gradle.api.Project
* customDependencies {
* }
* }
* ```
*/
class PublishersConfiguration(
val project: Project
) {
/**
* Access to the configuration of [com.cdsap.talaiot.publisher.InfluxDbPublisher]
*/
var influxDbPublisher: InfluxDbPublisherConfiguration? = null
/**
* Access to the configuration of [com.cdsap.talaiot.publisher.OutputPublisher]
*/
var outputPublisher: OutputPublisherConfiguration? = null
/**
* Access to the configuration of [com.cdsap.talaiot.publisher.PushGatewayPublisher]
*/
var pushGatewayPublisher: PushGatewayPublisherConfiguration? = null
/**
* Access to the configuration of [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher]
*/
var taskDependencyGraphPublisher: TaskDependencyGraphConfiguration? = null
/**
* Flag to enable [com.cdsap.talaiot.publisher.timeline.TimelinePublisher]
*
* Generates an html report with the timeline of task execution
*/
var timelinePublisher: Boolean = false
/**
* Flag to enable [com.cdsap.talaiot.publisher.JsonPublisher]
*
* Generates a json representation of [com.cdsap.talaiot.entities.ExecutionReport]
*/
var jsonPublisher: Boolean = false
/**
* Access to the configuration of [com.cdsap.talaiot.publisher.ElasticSearchPublisher]
*/
internal var elasticSearchPublisher: ElasticSearchPublisherConfiguration? = null
internal var hybridPublisher: HybridPublisherConfiguration? = null
internal var influxDbPublisher: InfluxDbPublisherConfiguration? = null
internal var outputPublisher: OutputPublisherConfiguration? = null
internal var pushGatewayPublisher: PushGatewayPublisherConfiguration? = null
internal var rethinkDbPublisher: RethinkDbPublisherConfiguration? = null
internal var taskDependencyGraphPublisher: TaskDependencyGraphConfiguration? = null

internal var customPublishers: MutableSet<Publisher> = mutableSetOf()

var elasticSearchPublisher: ElasticSearchPublisherConfiguration? = null
/**
* Access to the configuration of [com.cdsap.talaiot.publisher.HybridPublisher]
* Enables a [TimelinePublisher] if set to `true`. Disabled by default.
*/
var timelinePublisher: Boolean = false

var hybridPublisher: HybridPublisherConfiguration? = null
/**
* Access to the configuration of [com.cdsap.talaiot.publisher.RethinkDbPublisher]
* Enables a [JsonPublisher] if set to `true`. Disabled by default.
*/
var rethinkDbPublisher: RethinkDbPublisherConfiguration? = null
var jsonPublisher: Boolean = false

/**
* Definition of a custom Publisher in the PublisherConfiguration. Requires implementation of Publisher.
* Configuration accessor within the [PublishersConfiguration] for the [ElasticSearchPublisher]
*
* Some users of plugin might need to use a custom publisher to push to internal analytics for example.
* @param configuration Configuration block for the [ElasticSearchPublisherConfiguration]
*/
var customPublisher: Publisher? = null
fun elasticSearchPublisher(configuration: ElasticSearchPublisherConfiguration.() -> Unit) {
elasticSearchPublisher = ElasticSearchPublisherConfiguration().also(configuration)
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [ElasticSearchPublisher]
*
* @param configuration Configuration block for the [TaskDependencyGraphConfiguration]
* @param closure closure for the [ElasticSearchPublisherConfiguration]
*/
fun taskDependencyGraphPublisher(configuration: TaskDependencyGraphConfiguration.() -> Unit) {
taskDependencyGraphPublisher = TaskDependencyGraphConfiguration(project).also(configuration)
fun elasticSearchPublisher(closure: Closure<*>) {
elasticSearchPublisher = ElasticSearchPublisherConfiguration()
closure.delegate = elasticSearchPublisher
closure.call()
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.InfluxDbPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [HybridPublisher]
*
* @param configuration Configuration block for the [InfluxDbPublisherConfiguration]
* @param configuration Configuration block for the [HybridPublisherConfiguration]
*/
fun influxDbPublisher(configuration: InfluxDbPublisherConfiguration.() -> Unit) {
influxDbPublisher = InfluxDbPublisherConfiguration().also(configuration)
fun hybridPublisher(configuration: HybridPublisherConfiguration.() -> Unit) {
hybridPublisher = HybridPublisherConfiguration().also(configuration)
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.PushGatewayPublisher]
* Configuration accessor within the [HybridPublisherConfiguration] for the [HybridPublisher]
*
* @param configuration Configuration block for the [PushGatewayPublisherConfiguration]
* @param closure closure for the [HybridPublisherConfiguration]
*/
fun pushGatewayPublisher(configuration: PushGatewayPublisherConfiguration.() -> Unit) {
pushGatewayPublisher = PushGatewayPublisherConfiguration().also(configuration)
fun hybridPublisher(closure: Closure<*>) {
hybridPublisher = HybridPublisherConfiguration()
closure.delegate = hybridPublisher
closure.call()
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.ElasticSearchPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [InfluxDbPublisher]
*
* @param configuration Configuration block for the [ElasticSearchPublisherConfiguration]
* @param configuration Configuration block for the [InfluxDbPublisherConfiguration]
*/
fun elasticSearchPublisher(configuration: ElasticSearchPublisherConfiguration.() -> Unit) {
elasticSearchPublisher = ElasticSearchPublisherConfiguration().also(configuration)
fun influxDbPublisher(configuration: InfluxDbPublisherConfiguration.() -> Unit) {
influxDbPublisher = InfluxDbPublisherConfiguration().also(configuration)
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.HybridPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [InfluxDbPublisher]
*
* @param configuration Configuration block for the [HybridPublisherConfiguration]
* @param closure closure for the [InfluxDbPublisherConfiguration]
*/
fun hybridPublisher(configuration: HybridPublisherConfiguration.() -> Unit) {
hybridPublisher = HybridPublisherConfiguration().also(configuration)
fun influxDbPublisher(closure: Closure<*>) {
influxDbPublisher = InfluxDbPublisherConfiguration()
closure.delegate = influxDbPublisher
closure.call()
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.OutputPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [OutputPublisher]
*
* @param configuration Configuration block for the [OutputPublisherConfiguration]
*/
Expand All @@ -132,100 +121,81 @@ class PublishersConfiguration(
}

/**
* Configuration accessor within the [PublishersConfiguration] for the custom implementation for [Publisher]
*
* Will override another custom publisher instance if present
* Configuration accessor within the [PublishersConfiguration] for the [OutputPublisher]
*
* @param configuration instance of your publisher
*/
fun customPublisher(configuration: Publisher) {
customPublisher = configuration
}

/**
* Configuration accessor within the [RethinkDbPublisherConfiguration] for the custom implementation for [RethinkDbPublisher]
*
* @param configuration instance of your publisher
* @param closure closure for the [OutputPublisherConfiguration]
*/
fun rethinkDbPublisher(configuration: RethinkDbPublisherConfiguration.() -> Unit) {
rethinkDbPublisher = RethinkDbPublisherConfiguration().also(configuration)
fun outputPublisher(closure: Closure<*>) {
outputPublisher = OutputPublisherConfiguration()
closure.delegate = outputPublisher
closure.call()
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.InfluxDbPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [PushGatewayPublisher]
*
* @param closure closure for the [InfluxDbPublisherConfiguration]
* @param configuration Configuration block for the [PushGatewayPublisherConfiguration]
*/
fun influxDbPublisher(closure: Closure<*>) {
influxDbPublisher = InfluxDbPublisherConfiguration()
closure.delegate = influxDbPublisher
closure.call()
fun pushGatewayPublisher(configuration: PushGatewayPublisherConfiguration.() -> Unit) {
pushGatewayPublisher = PushGatewayPublisherConfiguration().also(configuration)
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [PushGatewayPublisher]
*
* @param closure closure for the [TaskDependencyGraphConfiguration]
* @param closure closure for the [PushGatewayPublisherConfiguration]
*/
fun taskDependencyGraphPublisher(closure: Closure<*>) {
taskDependencyGraphPublisher = TaskDependencyGraphConfiguration(project)
closure.delegate = taskDependencyGraphPublisher
fun pushGatewayPublisher(closure: Closure<*>) {
pushGatewayPublisher = PushGatewayPublisherConfiguration()
closure.delegate = pushGatewayPublisher
closure.call()
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.ElasticSearchPublisher]
* Configuration accessor within the [RethinkDbPublisherConfiguration] for the custom implementation for [RethinkDbPublisher]
*
* @param closure closure for the [ElasticSearchPublisherConfiguration]
* @param configuration instance of your publisher
*/
fun elasticSearchPublisher(closure: Closure<*>) {
elasticSearchPublisher = ElasticSearchPublisherConfiguration()
closure.delegate = elasticSearchPublisher
closure.call()
fun rethinkDbPublisher(configuration: RethinkDbPublisherConfiguration.() -> Unit) {
rethinkDbPublisher = RethinkDbPublisherConfiguration().also(configuration)
}

/**
* Configuration accessor within the [HybridPublisherConfiguration] for the [com.cdsap.talaiot.publisher.HybridPublisher]
* Configuration accessor within the [RethinkDbPublisherConfiguration] for the [RethinkDbPublisher]
*
* @param closure closure for the [HybridPublisherConfiguration]
* @param closure closure for the [RethinkDbPublisherConfiguration]
*/
fun hybridPublisher(closure: Closure<*>) {
hybridPublisher = HybridPublisherConfiguration()
closure.delegate = hybridPublisher
fun rethinkDbPublisher(closure: Closure<*>) {
rethinkDbPublisher = RethinkDbPublisherConfiguration()
closure.delegate = rethinkDbPublisher
closure.call()
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.OutputPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [TaskDependencyGraphPublisher]
*
* @param closure closure for the [OutputPublisherConfiguration]
* @param configuration Configuration block for the [TaskDependencyGraphConfiguration]
*/
fun outputPublisher(closure: Closure<*>) {
outputPublisher = OutputPublisherConfiguration()
closure.delegate = outputPublisher
closure.call()
fun taskDependencyGraphPublisher(configuration: TaskDependencyGraphConfiguration.() -> Unit) {
taskDependencyGraphPublisher = TaskDependencyGraphConfiguration(project).also(configuration)
}

/**
* Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.PushGatewayPublisher]
* Configuration accessor within the [PublishersConfiguration] for the [TaskDependencyGraphPublisher]
*
* @param closure closure for the [PushGatewayPublisherConfiguration]
* @param closure closure for the [TaskDependencyGraphConfiguration]
*/
fun pushGatewayPublisher(closure: Closure<*>) {
pushGatewayPublisher = PushGatewayPublisherConfiguration()
closure.delegate = pushGatewayPublisher
fun taskDependencyGraphPublisher(closure: Closure<*>) {
taskDependencyGraphPublisher = TaskDependencyGraphConfiguration(project)
closure.delegate = taskDependencyGraphPublisher
closure.call()
}

/**
* Configuration accessor within the [RethinkDbPublisherConfiguration] for the [com.cdsap.talaiot.publisher.RethinkDbPublisher]
* Adds the given custom publishers into the publisher list.
*
* @param closure closure for the [RethinkDbPublisherConfiguration]
* @param publishers takes N [Publisher]s to be added to the publishers list.
*/
fun rethinkDbPublisher(closure: Closure<*>) {
rethinkDbPublisher = RethinkDbPublisherConfiguration()
closure.delegate = rethinkDbPublisher
closure.call()
fun customPublishers(vararg publishers: Publisher) {
customPublishers.addAll(publishers)
}

}
}
Loading

0 comments on commit bd51f39

Please sign in to comment.