Skip to content

Commit

Permalink
Add metric type (#1775)
Browse files Browse the repository at this point in the history
* Add metric type

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

* update

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>

---------

Signed-off-by: Kavitha Conjeevaram Mohan <[email protected]>
  • Loading branch information
kavithacm authored Dec 19, 2023
1 parent 8b5576a commit 65262bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ import org.opensearch.observability.util.logger
* "application_id": "KE1Ie34BbsTr-CsB4G6Y",
* "user_configs": "{\"dataConfig\":\"{}\",\"layoutConfig\": \"{}\"}",
* "sub_type": "metric",
* "metric_type": "OpenTelemetryMetric",
* "units_of_measure: "hours (h)",
* "labels": [
* {"label":"avg"},
* {"label":"count"},
* ]
* }
* }</pre>
*/
Expand All @@ -65,6 +67,7 @@ internal data class SavedVisualization(
val applicationId: String? = null,
val userConfigs: String? = null,
val subType: String?,
val metricType: String? = null,
val unitsOfMeasure: String? = null,
val selectedLabels: SelectedLabels? = null,
) : BaseObjectData {
Expand All @@ -81,6 +84,7 @@ internal data class SavedVisualization(
private const val APPLICATION_ID_TAG = "application_id"
private const val USER_CONFIGS_TAG = "user_configs"
private const val SUB_TYPE_TAG = "sub_type"
private const val METRIC_TYPE_TAG = "metric_type"
private const val UNITS_OF_MEASURE_TAG = "units_of_measure"
private const val SELECTED_LABELS_TAG = "selected_labels"

Expand Down Expand Up @@ -111,6 +115,7 @@ internal data class SavedVisualization(
var applicationId: String? = null
var userConfigs: String? = null
var subType: String? = null
var metricType: String? = null
var unitsOfMeasure: String? = null
var selectedLabels: SelectedLabels? = null
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser)
Expand All @@ -128,6 +133,7 @@ internal data class SavedVisualization(
APPLICATION_ID_TAG -> applicationId = parser.text()
USER_CONFIGS_TAG -> userConfigs = parser.text()
SUB_TYPE_TAG -> subType = parser.text()
METRIC_TYPE_TAG -> metricType = parser.text()
UNITS_OF_MEASURE_TAG -> unitsOfMeasure = parser.text()
SELECTED_LABELS_TAG -> selectedLabels = SelectedLabels.parse(parser)
else -> {
Expand All @@ -147,8 +153,9 @@ internal data class SavedVisualization(
applicationId,
userConfigs,
subType,
metricType,
unitsOfMeasure,
selectedLabels
selectedLabels,
)
}
}
Expand Down Expand Up @@ -177,6 +184,7 @@ internal data class SavedVisualization(
applicationId = input.readOptionalString(),
userConfigs = input.readOptionalString(),
subType = input.readString(),
metricType = input.readOptionalString(),
unitsOfMeasure = input.readOptionalString(),
selectedLabels = input.readOptionalWriteable(SelectedLabels.reader),
)
Expand All @@ -195,6 +203,7 @@ internal data class SavedVisualization(
output.writeOptionalString(applicationId)
output.writeOptionalString(userConfigs)
output.writeString(subType)
output.writeOptionalString(metricType)
output.writeOptionalString(unitsOfMeasure)
output.writeOptionalWriteable(selectedLabels)
}
Expand All @@ -215,6 +224,7 @@ internal data class SavedVisualization(
.fieldIfNotNull(APPLICATION_ID_TAG, applicationId)
.fieldIfNotNull(USER_CONFIGS_TAG, userConfigs)
.fieldIfNotNull(SUB_TYPE_TAG, subType)
.fieldIfNotNull(METRIC_TYPE_TAG, metricType)
.fieldIfNotNull(UNITS_OF_MEASURE_TAG, unitsOfMeasure)
.fieldIfNotNull(SELECTED_LABELS_TAG, selectedLabels)
return builder.endObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal class SavedVisualizationTests {
"KE1Ie34BbsTr-CsB4G6Y",
"{\"dataConfig\":\"{}\",\"layoutConfig\":\"{}\"}",
"metric",
"OpenTelemetryMetric",
"hours (h)"
)

Expand All @@ -58,7 +59,8 @@ internal class SavedVisualizationTests {
"\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"" +
"| fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]}," +
"\"application_id\":\"KE1Ie34BbsTr-CsB4G6Y\",\"user_configs\":\"{\\\"dataConfig\\\":\\\"{}\\\"," +
"\\\"layoutConfig\\\":\\\"{}\\\"}\",\"sub_type\":\"metric\",\"units_of_measure\":\"hours (h)\"}"
"\\\"layoutConfig\\\":\\\"{}\\\"}\",\"sub_type\":\"metric\",\"metric_type\":\"OpenTelemetryMetric\"," +
"\"units_of_measure\":\"hours (h)\"}"

val recreatedObject = createObjectFromJsonString(jsonString) { SavedVisualization.parse(it) }
assertEquals(sampleSavedVisualization, recreatedObject)
Expand All @@ -82,7 +84,8 @@ internal class SavedVisualizationTests {
"\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"|" +
" fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]}," +
"\"application_id\":\"KE1Ie34BbsTr-CsB4G6Y\",\"user_configs\":\"{\\\"dataConfig\\\":\\\"{}\\\"," +
"\\\"layoutConfig\\\":\\\"{}\\\"}\",\"sub_type\":\"metric\",\"units_of_measure\":\"hours (h)\"}"
"\\\"layoutConfig\\\":\\\"{}\\\"}\",\"sub_type\":\"metric\",\"metric_type\":\"OpenTelemetryMetric\"," +
"\"units_of_measure\":\"hours (h)\"}"

val recreatedObject = createObjectFromJsonString(jsonString) { SavedVisualization.parse(it) }
assertEquals(sampleSavedVisualization, recreatedObject)
Expand Down

0 comments on commit 65262bb

Please sign in to comment.