<!--
  Licensed 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. See accompanying LICENSE file.
-->

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

    <description>Kylin Metrics Related Configuration (SystemCube)</description>

    <!-- A Reservoir which don't staged metrics message at all, emit it in no time. Maybe good for debug purpose.-->
    <bean id="instantReservoir" class="org.apache.kylin.metrics.lib.impl.InstantReservoir"/>

    <!-- A Reservoir which staged metrics message in memory, and emit them in fixed rate. -->
    <bean id="blockingReservoir" class="org.apache.kylin.metrics.lib.impl.BlockingReservoir">
        <!-- minReportSize, only if currently count of staged message exceed minReportSize, will Reservoir try to write message-->
        <constructor-arg index="0">
            <value>100</value>
        </constructor-arg>

        <!-- maxReportSize, max size of report in one time -->
        <constructor-arg index="1">
            <value>500</value>
        </constructor-arg>

        <!-- maxReportTime, max duration(in minute) between two report action-->
        <constructor-arg index="2">
            <value>10</value>
        </constructor-arg>

        <!-- maxQueueSize, max queue size of records in BlockingReservoir;
            set zero or a negative number if you prefer a unbounded LinkedBlockingQueue -->
        <constructor-arg index="3">
            <value>500000</value>
        </constructor-arg>
    </bean>

    <bean id="hiveSink" class="org.apache.kylin.metrics.lib.impl.hive.HiveSink"/>

    <bean id="kafkaSink" class="org.apache.kylin.metrics.lib.impl.kafka.KafkaSink"/>

    <bean id="initMetricsManager" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="org.apache.kylin.metrics.MetricsManager"/>
        <property name="targetMethod" value="initMetricsManager"/>
        <property name="arguments">
            <list>
                <ref bean="hiveSink"/>
                <map key-type="org.apache.kylin.metrics.lib.ActiveReservoir" value-type="java.util.List">
                    <!--
                    <entry key-ref="instantReservoir">
                        <list>
                            <bean class="org.apache.kylin.common.util.Pair">
                                <property name="first"
                                          value="org.apache.kylin.metrics.lib.impl.kafka.KafkaReservoirReporter"/>
                                <property name="second">
                                    <props>
                                        <prop key="bootstrap.servers">sandbox:9092</prop>
                                    </props>
                                </property>
                            </bean>
                        </list>
                    </entry>
                    -->
                    <entry key-ref="blockingReservoir">
                        <list>
                            <bean class="org.apache.kylin.common.util.Pair">
                                <property name="first"
                                          value="org.apache.kylin.metrics.lib.impl.hive.HiveReservoirReporter"/>
                                <property name="second">
                                    <props>
                                        <prop key="kylin.hive.producer.close-file-every-append">true</prop>
                                    </props>
                                </property>
                            </bean>
                        </list>
                    </entry>
                </map>
            </list>
        </property>
    </bean>

</beans>