# Copyright (c)  2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

metricsLabelMapping:
  query:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Queries.*.*"
    name: "siddhi.query.${2}"
    labels:
      app: "${0}"
      type: "query"
      element: "${1}"
      metrics: "${2}"

  sourceMapper:
    match: "io.siddhi.SiddhiApps.*.Siddhi.SourceMappers.*.*"
    name: "siddhi.sourcemapper.${2}"
    labels:
      app: "${0}"
      type: "sourcemapper"
      element: "${1}"
      metrics: "${2}"

  sinkMapper:
    match: "io.siddhi.SiddhiApps.*.Siddhi.SinkMappers.*.*"
    name: "siddhi.sinkmapper.${2}"
    labels:
      app: "${0}"
      type: "sinkmapper"
      element: "${1}"
      metrics: "${2}"

  source:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Sources.*.*"
    name: "siddhi.source.${2}"
    labels:
      app: "${0}"
      type: "source"
      element: "${1}"
      metrics: "${2}"

  stream:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Streams.*.*"
    name: "siddhi.stream.${2}"
    labels:
      app: "${0}"
      type: "stream"
      element: "${1}"
      metrics: "${2}"

  sink:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Sinks.*.*"
    name: "siddhi.sink.${2}"
    labels:
      app: "${0}"
      type: "sink"
      element: "${1}"
      metrics: "${2}"

  onDemandQuery:
    match: "io.siddhi.SiddhiApps.*.Siddhi.OnDemandQueries.*.*"
    name: "siddhi.ondemandquery.${2}"
    labels:
      app: "${0}"
      type: "ondemandquery"
      element: "${1}"
      metrics: "${2}"

  tables:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Tables.*.*"
    name: "siddhi.table.${2}"
    labels:
      app: "${0}"
      type: "table"
      element: "${1}"
      metrics: "${2}"

  windows:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Windows.*.*"
    name: "siddhi.window.${2}"
    labels:
      app: "${0}"
      type: "window"
      element: "${1}"
      metrics: "${2}"

  triggers:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Trigger.*.*"
    name: "siddhi.trigger.${2}"
    labels:
      app: "${0}"
      type: "trigger"
      element: "${1}"
      metrics: "${2}"

  aggregation:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Aggregations.*.*"
    name: "siddhi.aggregation.${2}"
    labels:
      app: "${0}"
      type: "aggregation"
      element: "${1}"
      metrics: "${2}"

  tableOperation:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Tables.*.*.*"
    name: "siddhi.table.${3}"
    labels:
      app: "${0}"
      type: "table"
      element: "${1}"
      operation: "${2}"
      metrics: "${3}"

  aggregationOperation:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Aggregations.*.*.*"
    name: "siddhi.aggregation.${3}"
    labels:
      app: "${0}"
      type: "aggregation"
      element: "${1}"
      operation: "${2}"
      metrics: "${3}"

  windowOperation:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Windows.*.*.*"
    name: "siddhi.window.${3}"
    labels:
      app: "${0}"
      type: "window"
      element: "${1}"
      operation: "${2}"
      metrics: "${3}"

  sinkOperation:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Sinks.*.*.*"
    name: "siddhi.sink.${3}"
    labels:
      app: "${0}"
      type: "sink"
      element: "${1}"
      operation: "${2}"
      metrics: "${3}"

  sourceOperation:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Sources.*.*.*"
    name: "siddhi.source.${3}"
    labels:
      app: "${0}"
      type: "source"
      element: "${1}"
      operation: "${2}"
      metrics: "${3}"

  sinkMapperOperationType:
    match: "io.siddhi.SiddhiApps.*.Siddhi.SinkMappers.*.*.*.*"
    name: "siddhi.sinkmapper.${4}"
    labels:
      app: "${0}"
      type: "sinkmapper"
      element: "${1}"
      operation: "${2}"
      operationType: "${3}"
      metrics: "${4}"

  sourceMapperOperationType:
    match: "io.siddhi.SiddhiApps.*.Siddhi.SourceMappers.*.*.*.*"
    name: "siddhi.sourcemapper.${4}"
    labels:
      app: "${0}"
      type: "sourcemapper"
      element: "${1}"
      operation: "${2}"
      operationType: "${3}"
      metrics: "${4}"

  sinkOperationType:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Sinks.*.*.*.*"
    name: "siddhi.sink.${4}"
    labels:
      app: "${0}"
      type: "sink"
      element: "${1}"
      operation: "${2}"
      operationType: "${3}"
      metrics: "${4}"

# Total Reads/Writes
  siddhi.io.total.reads:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Total.Reads.*"
    name: "siddhi.total.reads"
    labels:
      app: "${0}"
      type: "${1}"

  siddhi.io.total.writes:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Total.Writes.*"
    name: "siddhi.total.writes"
    labels:
      app: "${0}"
      type: "${1}"

#Siddhi-io-file Metrics

  siddhi.io.file.apps:
    match: "io.siddhi.SiddhiApps.*.Siddhi.File"
    name: "siddhi.file.apps"
    labels:
      app: "${0}"

  siddhi.io.file.sink.event.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.File.Sinks.event.count.(.*).filename.*.*.(.*)"
    name: "siddhi.file.sink.event.count"
    labels:
      app: "${0}"
      file_name: "${1}"
      mode: "${2}"
      stream_name: "${3}"
      file_path: "${4}"

  siddhi.io.file.sink.metrics:
    match: "io.siddhi.SiddhiApps.*.Siddhi.File.Sinks.*.(.*)"
    name: "siddhi.file.sink.${1}"
    labels:
      app: "${0}"
      file_path: "${2}"

  siddhi.io.file.source.event.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.File.Source.Total.Reads.(.*).filename.*.*.(.*)"
    name: "siddhi.file.source.event.count"
    labels:
      app: "${0}"
      file_name: "${1}"
      mode: "${2}"
      stream_name: "${3}"
      file_path: "${4}"

  siddhi.io.file.source.metrics:
    match: "io.siddhi.SiddhiApps.*.Siddhi.File.Source.*.(.*)"
    name: "siddhi.file.source.${1}"
    labels:
      app: "${0}"
      file_path: "${2}"


  siddhi.io.file.archive: # no extension
    match: "io.siddhi.SiddhiApps.*.Siddhi.File.Operations.Archived.*.(.*).time.(.*).source.(.*).destination"
    name: "siddhi.file.archive"
    labels:
      app: "${0}"
      type: "${1}"
      time: "${2}"
      _source: "${3}"
      destination: "${4}"

  siddhi.io.file.copy: #both source and destination does not have extension
    match: "io.siddhi.SiddhiApps.*.Siddhi.File.Operations.Copy.(.*).time.(.*).source.(.*).destination"
    name: "siddhi.file.copy"
    labels:
      app: "${0}"
      time: "${1}"
      _source: "${2}"
      destination: "${3}"

  siddhi.io.file.delete: #source does not have extension
    match: "io.siddhi.SiddhiApps.*.Siddhi.File.Operations.Delete.(.*).time.(.*).source"
    name: "siddhi.file.delete"
    labels:
      app: "${0}"
      time: "${1}"
      _source: "${2}"

  siddhi.io.file.move: #both source and destination does not have extension
    match: "io.siddhi.SiddhiApps.(.*).Siddhi.File.Operations.Move.(.*).time.(.*).source.(.*).destination"
    name: "siddhi.file.move"
    labels:
      app: "${0}"
      time: "${1}"
      _source: "${2}"
      destination: "${3}"

  #Siddhi-io-cdc Metrics

  siddhi.io.cdc.apps:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Cdc"
    name: "siddhi.cdc.apps"
    labels:
      app: "${0}"

  siddhi.io.cdc.source.listening.metrics.events.per.table:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Cdc.Source.Listening.events.per.table.*.(.*)"
    name: "siddhi.cdc.source.listening.mode.events.per.table"
    labels:
      app: "${0}"
      tablename: "${1}"
      db_url: "${2}"

  siddhi.io.cdc.source.listening.event.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Cdc.Source.Listening.event.count.*.(.*).host.*.*.*.(.*)"
    name: "siddhi.cdc.source.listening.mode.event.count"
    labels:
      app: "${0}"
      A_db_type: "${1}"
      B_host: "${2}"
      operation_type: "${3}"
      C_database: "${4}"
      D_tablename: "${5}"
      db_url: "${6}"

  siddhi.io.cdc.source.listening.metrics.last.update:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Cdc.Source.Listening.*.*.(.*)"
    name: "siddhi.cdc.source.listening.mode.${1}"
    labels:
      app: "${0}"
      operation_type: "${2}"
      db_url: "${3}"

  siddhi.io.cdc.source.listening.metrics:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Cdc.Source.Listening.*.(.*)"
    name: "siddhi.cdc.source.listening.mode.${1}"
    labels:
      app: "${0}"
      db_url: "${2}"

  siddhi.io.cdc.source.polling.event.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Cdc.Source.Polling.event.count.*.(.*).host.*.*.(.*)"
    name: "siddhi.cdc.source.polling.mode.event.count"
    labels:
      app: "${0}"
      A_db_type: "${1}"
      B_host: "${2}"
      C_database: "${3}"
      D_tablename: "${4}"
      db_url: "${5}"

  siddhi.io.cdc.source.polling.details.metrics.:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Cdc.Source.Polling.Details.*.*.*.(.*)"
    name: "siddhi.cdc.source.polling.mode.polling.details"
    labels:
      app: "${0}"
      _started_time: "${1}"
      duration: "${2}"
      status: "${3}"
      db_url: "${4}"

  siddhi.io.cdc.source.polling.metrics:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Cdc.Source.Polling.*.(.*)"
    name: "siddhi.cdc.source.polling.mode.${1}"
    labels:
      app: "${0}"
      db_url: "${2}"

#siddhi-store-rdbms
  siddhi.store.rdbms.apps:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Store.RDBMS"
    name: "siddhi.store.rdbms.apps"
    labels:
      app: "${0}"

  siddhi.store.rdbms.total.resutls.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Store.RDBMS.Write.Count.*.(.*).host.*.*.(.*)"
    name: "siddhi.store.rdbms.total.writes"
    labels:
      app: "${0}"
      A_db_type: "${1}"
      B_shortenUrl: "${2}"
      C_database: "${3}"
      D_tablename: "${4}"
      db_url: "${5}"

  siddhi.store.rdbms.metrics:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Store.RDBMS.*.(.*)"
    name: "siddhi.store.rdbms.${1}"
    labels:
      app: "${0}"
      db_url: "${2}"

  #Siddhi-io-kafka Metrics
  siddhi.io.kafka.apps:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Source"
    name: "siddhi.kafka.apps"
    labels:
      app: "${0}"

  siddhi.io.kafka.source.current.offset:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Source.Current.Offset.*.partition.*.groupId.*.stream_id.*"
    name: "siddhi.kafka.source.current.offset"
    labels:
      app: "${0}"
      topic: "${1}"
      partition: "${2}"
      group_id: "${3}"
      stream_id: "${4}"

  siddhi.io.kafka.source.read.count.per.stream:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Source.Reads.Per.Stream.*.stream_id.*.partition.*.groupId.*"
    name: "siddhi.kafka.source.read.count.per.stream"
    labels:
      app: "${0}"
      topic: "${1}"
      stream_id: "${2}"
      partition: "${3}"
      group_id: "${4}"

  siddhi.io.kafka.source.error.count.per.stream:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Source.Errors.Per.Stream.*.stream_id.*.groupId.*.errorString.(.*)"
    name: "siddhi.kafka.source.error.count.per.stream"
    labels:
      app: "${0}"
      topic: "${1}"
      stream_id: "${2}"
      group_id: "${3}"
      error_string: "${4}"

  siddhi.io.kafka.source.per.stream.misc:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Source.Per.Stream.*.groupId.*.streamId.*.*"
    name: "siddhi.kafka.source.per.stream.${4}"
    labels:
      app: "${0}"
      topic: "${1}"
      group_id: "${2}"
      stream_id: "${3}"

  siddhi.io.kafka.source.per.stream.with.partition.misc:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Source.Per.Stream.*.partition.*.groupId.*.streamId.*.*"
    name: "siddhi.kafka.source.per.stream.with.partition.${5}"
    labels:
      app: "${0}"
      topic: "${1}"
      partition: "${2}"
      group_id: "${3}"
      stream_id: "${4}"

## Kafka Sink Metrics

  siddhi.io.kafka.sink.write.count.per.stream:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Sink.Writes.Per.Stream.*.stream_id.*.partition.*"
    name: "siddhi.kafka.sink.write.count.per.stream"
    labels:
      app: "${0}"
      topic: "${1}"
      stream_id: "${2}"
      partition: "${3}"

  siddhi.io.kafka.sink.error.count.per.stream:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Sink.Errors.Per.Stream.*.stream_id.*.partition.*.errorString.(.*)"
    name: "siddhi.kafka.sink.error.count.per.stream"
    labels:
      app: "${0}"
      topic: "${1}"
      stream_id: "${2}"
      partition: "${3}"
      error_string: "${4}"

  siddhi.io.kafka.sink.error.count.without.partition:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Sink.Errors.Without.Partition.*.stream_id.*.errorString.(.*)"
    name: "siddhi.kafka.sink.error.count.without.partition"
    labels:
      app: "${0}"
      topic: "${1}"
      stream_id: "${2}"
      error_string: "${3}"

  siddhi.io.kafka.sink.per.stream.misc:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Sink.Per.Stream.*.partition.*.streamId.*.*"
    name: "siddhi.kafka.sink.per.stream.${4}"
    labels:
      app: "${0}"
      topic: "${1}"
      partition: "${2}"
      stream_id: "${3}"

  siddhi.io.kafka.sink.current.offset:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Kafka.Sink.Current.Offset.*.partition.*.streamId.*"
    name: "siddhi.kafka.sink.current.offset"
    labels:
      app: "${0}"
      topic: "${1}"
      partition: "${2}"
      stream_id: "${3}"

  # Siddhi-io-http Metrics
  siddhi.io.http.apps:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http"
    name: "siddhi.http.apps"
    labels:
      app: "${0}"

  # Http Source
  siddhi.io.http.source.event.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Source.Total.Reads.*.(.*)"
    name: "siddhi.http.source.event.count"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.source.error.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Source.Total.Errors.*.(.*)"
    name: "siddhi.http.source.error.count"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.source.status:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Source.Endpoint.Status.*.(.*)"
    name: "siddhi.http.source.status"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.source.request.size:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Source.Total.Request.Size.*.(.*)"
    name: "siddhi.http.source.request.size"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.source.last.event.time:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Source.Last.Event.Time.*.(.*)"
    name: "siddhi.http.source.last.event.time"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  # Http Sink
  siddhi.io.http.sink.event.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Sink.Total.Writes.*.(.*)"
    name: "siddhi.http.sink.event.count"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.sink.error.count:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Sink.Total.Errors.*.(.*)"
    name: "siddhi.http.sink.error.count"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.sink.status:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Sink.Endpoint.Status.*.(.*)"
    name: "siddhi.http.sink.status"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.sink.request.size:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Sink.Total.Request.Size.*.(.*)"
    name: "siddhi.http.sink.request.size"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.sink.average.latency:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Sink.Average.Latency.*.(.*)"
    name: "siddhi.http.sink.average.latency"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"

  siddhi.io.http.sink.last.event.time:
    match: "io.siddhi.SiddhiApps.*.Siddhi.Http.Sink.Last.Event.Time.*.(.*)"
    name: "siddhi.http.sink.last.event.time"
    labels:
      app: "${0}"
      stream_name: "${1}"
      url: "${2}"
