Skip to content

Commit

Permalink
Merge pull request #108 from davidmogar/metrics
Browse files Browse the repository at this point in the history
Add new function to send metric messages
  • Loading branch information
johnbieren authored Dec 20, 2021
2 parents 0cb9aee + 7748607 commit e2851e2
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 0 deletions.
14 changes: 14 additions & 0 deletions resources/msgBus-Metrics-Error-Content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"code": {
"value": 0,
"type": "java.math.BigInteger",
"description": "Error code.",
"required": true
},
"message": {
"value": null,
"type": "java.lang.String",
"description": "Error message.",
"required": false
}
}
44 changes: 44 additions & 0 deletions resources/msgBus-Metrics-ExternalCall-Content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"service": {
"value": {},
"type": "groovy.lang.Closure",
"description": "The service content Map.",
"required": true
},
"source": {
"value": null,
"type": "java.lang.String",
"description": "Tool/component making the request (eg. midstream, rhprod, service, ...).",
"required": true
},
"success": {
"value": true,
"type": "java.lang.Boolean",
"description": "Whether the call succeeded or not.",
"required": true
},
"error": {
"value": null,
"type": "groovy.lang.Closure",
"description": "The error content Map.",
"required": false
},
"start": {
"value": null,
"type": "java.lang.String",
"description": "Time at which the request started. (ISO-8601).",
"required": true
},
"end": {
"value": null,
"type": "java.lang.String",
"description": "Time at which the final answer was collected (last call or retry with a proper answer) (ISO-8601).",
"required": true
},
"retryData": {
"value": {},
"type": "groovy.lang.Closure",
"description": "The retryData content Map.",
"required": true
}
}
26 changes: 26 additions & 0 deletions resources/msgBus-Metrics-Pipeline-Content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": {
"value": null,
"type": "java.lang.String",
"description": "Unique identification string. Useful for constructing tree of rebuilds of the same artifact in the Web UI. Note that it is up to the CI system to implement. Replaces thread_id from previous versions of the spec. The value must be unique among all systems reporting on the artifact; it is advised to prefix it with a unique string, e.g. the name of the CI system, etc.",
"required": true
},
"name": {
"value": null,
"type": "java.lang.String",
"description": "A human readable name of the pipeline.",
"required": true
},
"jenkinsUrl": {
"value": null,
"type": "java.lang.String",
"description": "The jenkins URL.",
"required": true
},
"productId": {
"value": null,
"type": "java.lang.String",
"description": "The product id.",
"required": false
}
}
14 changes: 14 additions & 0 deletions resources/msgBus-Metrics-RetryData-Content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"configuration": {
"value": {},
"type": "groovy.lang.Closure",
"description": "The RetryDataConfiguration content Map.",
"required": false
},
"iterations": {
"value": 0,
"type": "java.math.BigInteger",
"description": "Number of iterations (ie. number of retries plus 1 for the first call).",
"required": true
}
}
32 changes: 32 additions & 0 deletions resources/msgBus-Metrics-RetryDataConfiguration-Content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"initialRetryInterval": {
"value": 0,
"type": "java.math.BigInteger",
"description": "Initial retry interval (first retry interval) in seconds.",
"required": false
},
"maxElapsedTime": {
"value": 0,
"type": "java.math.BigInteger",
"description": "Maximum number of seconds for the whole retry process.",
"required": false
},
"maxInterval": {
"value": 0,
"type": "java.math.BigInteger",
"description": "Maximum number of seconds between retries.",
"required": false
},
"maxRetries": {
"value": 0,
"type": "java.math.BigInteger",
"description": "Maximum number of retries.",
"required": false
},
"timeout": {
"value": 0,
"type": "java.math.BigInteger",
"description": "Timeout used for each call to the external service.",
"required": false
}
}
26 changes: 26 additions & 0 deletions resources/msgBus-Metrics-Service-Content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": {
"value": null,
"type": "java.lang.String",
"description": "Name of the external service.",
"required": true
},
"type": {
"value": null,
"type": "java.lang.String",
"description": "Type of call (ie. cli or http).",
"required": true
},
"server": {
"value": null,
"type": "java.lang.String",
"description": "Server contacted in case of not targeting the prod server.",
"required": false
},
"endpoint": {
"value": null,
"type": "java.lang.String",
"description": "Either http endpoint or cli subcommand.",
"required": false
}
}
20 changes: 20 additions & 0 deletions resources/msgBusMetricsMsg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"externalCall": {
"value": {},
"type": "groovy.lang.Closure",
"description": "The externalCall content Map.",
"required": true
},
"generated_at": {
"value": null,
"type": "java.lang.String",
"description": "Timestamp of message creation (ISO-8601).",
"required": true
},
"pipeline": {
"value": {},
"type": "groovy.lang.Closure",
"description": "The pipeline content Map.",
"required": true
}
}
26 changes: 26 additions & 0 deletions vars/msgBusMetricsErrorContent.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.centos.contra.pipeline.Utils

/**
* Defines the error content of an external call metrics message
* This will merge parameters with the defaults and will validate each parameter
* @param parameters
* @return HashMap
*/
def call(Map parameters = [:]) {

def utils = new Utils()

def defaults = readJSON text: libraryResource('msgBus-Metrics-Error-Content.json')

return { Map runtimeArgs = [:] ->
parameters = utils.mapMergeQuotes([parameters, runtimeArgs])
try {
mergedMessage = utils.mergeBusMessage(parameters, defaults)
} catch(e) {
throw new Exception("Creating closure for external call metric error content failed: " + e)
}

// sendCIMessage expects String arguments
return utils.getMapStringColon(mergedMessage)
}
}
29 changes: 29 additions & 0 deletions vars/msgBusMetricsExternalCallContent.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import org.centos.contra.pipeline.Utils

/**
* Defines the external call content of a metrics message
* This will merge parameters with the defaults and will validate each parameter
* @param parameters
* @return HashMap
*/
def call(Map parameters = [:]) {

def utils = new Utils()

def defaults = readJSON text: libraryResource('msgBus-Metrics-ExternalCall-Content.json')

return { Map runtimeArgs = [:] ->
parameters['service'] = parameters['service'] ?: msgBusMetricsServiceContent()()
parameters['retryData'] = parameters['retryData'] ?: msgBusMetricsRetryDataContent()()

parameters = utils.mapMergeQuotes([parameters, runtimeArgs])
try {
mergedMessage = utils.mergeBusMessage(parameters, defaults)
} catch(e) {
throw new Exception("Creating closure for external call content failed: " + e)
}

// sendCIMessage expects String arguments
return utils.getMapStringColon(mergedMessage)
}
}
30 changes: 30 additions & 0 deletions vars/msgBusMetricsMsg.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import org.centos.contra.pipeline.Utils

/**
* Defines the metrics message
* This will merge parameters with the defaults and will validate each parameter
* @param parameters
* @return HashMap
*/
def call(Map parameters = [:]) {

def utils = new Utils()

def defaults = readJSON text: libraryResource('msgBusMetricsMsg.json')

return { Map runtimeArgs = [:] ->
parameters['externalCall'] = parameters['externalCall'] ?: msgBusMetricsExternalCallContent()()
parameters['generated_at'] = parameters['generated_at'] ?: java.time.Instant.now().toString()
parameters['pipeline'] = parameters['pipeline'] ?: msgBusMetricsPipelineContent()()

parameters = utils.mapMergeQuotes([parameters, runtimeArgs])
try {
mergedMessage = utils.mergeBusMessage(parameters, defaults)
} catch(e) {
throw new Exception("Creating the metrics message failed: " + e)
}

// sendCIMessage expects String arguments
return utils.getMapStringColon(mergedMessage)
}
}
26 changes: 26 additions & 0 deletions vars/msgBusMetricsPipelineContent.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.centos.contra.pipeline.Utils

/**
* Defines the pipeline content of a metrics message
* This will merge parameters with the defaults and will validate each parameter
* @param parameters
* @return HashMap
*/
def call(Map parameters = [:]) {

def utils = new Utils()

def defaults = readJSON text: libraryResource('msgBus-Metrics-Pipeline-Content.json')

return { Map runtimeArgs = [:] ->
parameters = utils.mapMergeQuotes([parameters, runtimeArgs])
try {
mergedMessage = utils.mergeBusMessage(parameters, defaults)
} catch(e) {
throw new Exception("Creating closure for metric pipeline content failed: " + e)
}

// sendCIMessage expects String arguments
return utils.getMapStringColon(mergedMessage)
}
}
26 changes: 26 additions & 0 deletions vars/msgBusMetricsRetryDataConfigurationContent.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.centos.contra.pipeline.Utils

/**
* Defines the configuration content of a retry closure in an external call metrics message
* This will merge parameters with the defaults and will validate each parameter
* @param parameters
* @return HashMap
*/
def call(Map parameters = [:]) {

def utils = new Utils()

def defaults = readJSON text: libraryResource('msgBus-Metrics-RetryDataConfiguration-Content.json')

return { Map runtimeArgs = [:] ->
parameters = utils.mapMergeQuotes([parameters, runtimeArgs])
try {
mergedMessage = utils.mergeBusMessage(parameters, defaults)
} catch(e) {
throw new Exception("Creating the retry configuration closure for retry metrics message failed: " + e)
}

// sendCIMessage expects String arguments
return utils.getMapStringColon(mergedMessage)
}
}
26 changes: 26 additions & 0 deletions vars/msgBusMetricsRetryDataContent.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.centos.contra.pipeline.Utils

/**
* Defines the retry content of a retry metrics message
* This will merge parameters with the defaults and will validate each parameter
* @param parameters
* @return HashMap
*/
def call(Map parameters = [:]) {

def utils = new Utils()

def defaults = readJSON text: libraryResource('msgBus-Metrics-RetryData-Content.json')

return { Map runtimeArgs = [:] ->
parameters = utils.mapMergeQuotes([parameters, runtimeArgs])
try {
mergedMessage = utils.mergeBusMessage(parameters, defaults)
} catch(e) {
throw new Exception("Creating retryData closure for metrics message failed: " + e)
}

// sendCIMessage expects String arguments
return utils.getMapStringColon(mergedMessage)
}
}
26 changes: 26 additions & 0 deletions vars/msgBusMetricsServiceContent.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.centos.contra.pipeline.Utils

/**
* Defines the service content of an external call metrics message
* This will merge parameters with the defaults and will validate each parameter
* @param parameters
* @return HashMap
*/
def call(Map parameters = [:]) {

def utils = new Utils()

def defaults = readJSON text: libraryResource('msgBus-Metrics-Service-Content.json')

return { Map runtimeArgs = [:] ->
parameters = utils.mapMergeQuotes([parameters, runtimeArgs])
try {
mergedMessage = utils.mergeBusMessage(parameters, defaults)
} catch(e) {
throw new Exception("Creating closure for external call metric service content failed: " + e)
}

// sendCIMessage expects String arguments
return utils.getMapStringColon(mergedMessage)
}
}
Loading

0 comments on commit e2851e2

Please sign in to comment.