<commit_before>angular.module(PKG.name + '.feature.flows')
  .controller('FlowsRunDetailStatusController', function($state, $scope, MyDataSource, myHelpers, FlowDiagramData, $timeout, MyMetricsQueryHelper, myFlowsApi) {
    var dataSrc = new MyDataSource($scope),
        basePath = '/apps/' + $state.params.appId + '/flows/' + $state.params.programId;

    this.data = {};

    FlowDiagramData.fetchData($state.params.appId, $state.params.programId)
      .then(function(data) {
        this.data = data;
        pollMetrics.bind(this)();
      }.bind(this));

    function generateStreamMetricsPath(streamName) {
      var streamTags = {
        namespace: $state.params.namespace,
        stream: streamName
      };
      return '/metrics/query?metric=system.collect.events&aggregate=true&' + MyMetricsQueryHelper.tagsToParams(streamTags);
    }

    function generateFlowletMetricsPath(flowletName) {
      var flowletTags = {
        namespace: $state.params.namespace,
        app: $state.params.appId,
        flow: $state.params.programId,
        run: $scope.RunsController.runs.selected.runid,
        flowlet: flowletName
      };
      return '/metrics/query?metric=system.process.events.processed&aggregate=true&' + MyMetricsQueryHelper.tagsToParams(flowletTags);
    }

    function pollMetrics() {
      var nodes = this.data.nodes;
      this.data.instances = {};
      // Requesting Metrics data
      angular.forEach(nodes, function (node) {
        if (node.type !== 'STREAM' && !$scope.RunsController.runs.length) {
          return;
        }
        dataSrc.poll({
          _cdapPath: (node.type === 'STREAM' ? generateStreamMetricsPath(node.name): generateFlowletMetricsPath(node.name)),
          method: 'POST'
        }, function (data) {
          this.data.metrics[node.name] = myHelpers.objectQuery(data, 'series' , 0, 'data', 0, 'value') || 0;
        }.bind(this));

        // Polling for Flowlet Instance
        if (node.type !== 'STREAM') {
          var params = {
            namespace: $state.params.namespace,
            appId: $state.params.appId,
            flowId: $state.params.programId,
            flowletId: node.name,
            scope: $scope
          };
          myFlowsApi.pollFlowletInstance(params)
            .$promise
            .then(function (res) {
              this.data.instances[node.name] = res.instances;
            }.bind(this));
        }

      }.bind(this));
    }

    this.flowletClick = function(node) {
      $scope.RunsController.selectTab($scope.RunsController.tabs[1], node);
    };
  });
<commit_msg>fix flows metrics polling interval<commit_after>angular.module(PKG.name + '.feature.flows')
  .controller('FlowsRunDetailStatusController', function($state, $scope, MyDataSource, myHelpers, FlowDiagramData, $timeout, MyMetricsQueryHelper, myFlowsApi) {
    var dataSrc = new MyDataSource($scope),
        basePath = '/apps/' + $state.params.appId + '/flows/' + $state.params.programId;

    this.data = {};

    FlowDiagramData.fetchData($state.params.appId, $state.params.programId)
      .then(function(data) {
        this.data = data;
        pollMetrics.bind(this)();
      }.bind(this));

    function generateStreamMetricsPath(streamName) {
      var streamTags = {
        namespace: $state.params.namespace,
        stream: streamName
      };
      return '/metrics/query?metric=system.collect.events&aggregate=true&' + MyMetricsQueryHelper.tagsToParams(streamTags);
    }

    function generateFlowletMetricsPath(flowletName) {
      var flowletTags = {
        namespace: $state.params.namespace,
        app: $state.params.appId,
        flow: $state.params.programId,
        run: $scope.RunsController.runs.selected.runid,
        flowlet: flowletName
      };
      return '/metrics/query?metric=system.process.events.processed&aggregate=true&' + MyMetricsQueryHelper.tagsToParams(flowletTags);
    }

    function pollMetrics() {
      var nodes = this.data.nodes;
      this.data.instances = {};
      // Requesting Metrics data
      angular.forEach(nodes, function (node) {
        if (node.type !== 'STREAM' && !$scope.RunsController.runs.length) {
          return;
        }
        dataSrc.poll({
          _cdapPath: (node.type === 'STREAM' ? generateStreamMetricsPath(node.name): generateFlowletMetricsPath(node.name)),
          method: 'POST',
          interval: 2000
        }, function (data) {
          this.data.metrics[node.name] = myHelpers.objectQuery(data, 'series' , 0, 'data', 0, 'value') || 0;
        }.bind(this));

        // Polling for Flowlet Instance
        if (node.type !== 'STREAM') {
          var params = {
            namespace: $state.params.namespace,
            appId: $state.params.appId,
            flowId: $state.params.programId,
            flowletId: node.name,
            scope: $scope
          };
          myFlowsApi.pollFlowletInstance(params)
            .$promise
            .then(function (res) {
              this.data.instances[node.name] = res.instances;
            }.bind(this));
        }

      }.bind(this));
    }

    this.flowletClick = function(node) {
      $scope.RunsController.selectTab($scope.RunsController.tabs[1], node);
    };
  });

{'fraction_non_alphanumeric': 0.13571017826336976, 'fraction_numerical': 0.0023001725129384704, 'mean_word_length': 2.528059499661934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4045122', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1535, 'n_words': 252}