<commit_before>import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable, of, forkJoin, Subscription } from 'rxjs';
import {
  tap,
  map,
  concatMap,
  concat,
  mergeMap,
  concatAll,
  mergeAll,
  merge,
  combineAll,
  reduce,
  timeout,
} from 'rxjs/operators';
import { Router, ActivatedRoute } from '@angular/router';
import {
  NamespaceService,
  ExponentialBackoff,
  ToolbarButton,
  Condition,
  ConfirmDialogService,
  DIALOG_RESP,
  SnackBarService,
  SnackType,
} from 'kubeflow';
import { MWABackendService } from 'src/app/services/backend.service';
import { isEqual } from 'lodash';
import { generateDeleteConfig } from '../index/config';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { InferenceServiceK8s } from 'src/app/types/kfserving/v1beta1';
import {
  InferenceServiceOwnedObjects,
  ComponentOwnedObjects,
} from 'src/app/types/backend';

@Component({
  selector: 'app-server-info',
  templateUrl: './server-info.component.html',
  styleUrls: ['./server-info.component.scss'],
})
export class ServerInfoComponent implements OnInit, OnDestroy {
  public serverName: string;
  public namespace: string;
  public serverInfoLoaded = false;
  public inferenceService: InferenceServiceK8s;
  public ownedObjects: InferenceServiceOwnedObjects = {};
  public grafanaFound = true;

  public buttonsConfig: ToolbarButton[] = [
    new ToolbarButton({
      text: 'DELETE',
      icon: 'delete',
      fn: () => {
        this.deleteInferenceService();
      },
    }),
  ];

  private poller = new ExponentialBackoff({
    interval: 4000,
    maxInterval: 4001,
    retries: 1,
  });
  private pollingSub = new Subscription();

  constructor(
    private http: HttpClient,
    private route: ActivatedRoute,
    private router: Router,
    private ns: NamespaceService,
    private backend: MWABackendService,
    private confirmDialog: ConfirmDialogService,
    private snack: SnackBarService,
  ) {}

  ngOnInit() {
    this.route.params.subscribe(params => {
      console.log(`Using namespace: ${params.namespace}`);
      this.ns.updateSelectedNamespace(params.namespace);

      this.serverName = params.name;
      this.namespace = params.namespace;

      this.pollingSub = this.poller.start().subscribe(() => {
        this.getBackendObjects();
      });
    });

    // don't show a METRICS tab if Grafana is not exposed
    this.http
      .head(environment.grafanaPrefix)
      .pipe(timeout(1000))
      .subscribe({
        next: () => {
          this.grafanaFound = true;
        },
        error: () => {
          this.grafanaFound = false;
        },
      });<commit_msg>fix(web-app): Fix Grafana detection due to HEAD request (#1541)<commit_after>import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable, of, forkJoin, Subscription } from 'rxjs';
import {
  tap,
  map,
  concatMap,
  concat,
  mergeMap,
  concatAll,
  mergeAll,
  merge,
  combineAll,
  reduce,
  timeout,
} from 'rxjs/operators';
import { Router, ActivatedRoute } from '@angular/router';
import {
  NamespaceService,
  ExponentialBackoff,
  ToolbarButton,
  Condition,
  ConfirmDialogService,
  DIALOG_RESP,
  SnackBarService,
  SnackType,
} from 'kubeflow';
import { MWABackendService } from 'src/app/services/backend.service';
import { isEqual } from 'lodash';
import { generateDeleteConfig } from '../index/config';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { InferenceServiceK8s } from 'src/app/types/kfserving/v1beta1';
import {
  InferenceServiceOwnedObjects,
  ComponentOwnedObjects,
} from 'src/app/types/backend';

@Component({
  selector: 'app-server-info',
  templateUrl: './server-info.component.html',
  styleUrls: ['./server-info.component.scss'],
})
export class ServerInfoComponent implements OnInit, OnDestroy {
  public serverName: string;
  public namespace: string;
  public serverInfoLoaded = false;
  public inferenceService: InferenceServiceK8s;
  public ownedObjects: InferenceServiceOwnedObjects = {};
  public grafanaFound = true;

  public buttonsConfig: ToolbarButton[] = [
    new ToolbarButton({
      text: 'DELETE',
      icon: 'delete',
      fn: () => {
        this.deleteInferenceService();
      },
    }),
  ];

  private poller = new ExponentialBackoff({
    interval: 4000,
    maxInterval: 4001,
    retries: 1,
  });
  private pollingSub = new Subscription();

  constructor(
    private http: HttpClient,
    private route: ActivatedRoute,
    private router: Router,
    private ns: NamespaceService,
    private backend: MWABackendService,
    private confirmDialog: ConfirmDialogService,
    private snack: SnackBarService,
  ) {}

  ngOnInit() {
    this.route.params.subscribe(params => {
      console.log(`Using namespace: ${params.namespace}`);
      this.ns.updateSelectedNamespace(params.namespace);

      this.serverName = params.name;
      this.namespace = params.namespace;

      this.pollingSub = this.poller.start().subscribe(() => {
        this.getBackendObjects();
      });
    });

    // don't show a METRICS tab if Grafana is not exposed
    console.log('Checking if Grafana endpoint is exposed');
    const grafanaApi = environment.grafanaPrefix + '/api/search';

    this.http
      .get(grafanaApi)
      .pipe(timeout(1000))
      .subscribe({
        next: resp => {
          if (!Array.isArray(resp)) {
            console.log(
              'Response from the Grafana endpoint was not as expected.',
            );
            this.grafanaFound = false;
            return;
          }

          console.log('Grafana endpoint detected. Will expose a metrics tab.');
          this.grafanaFound = true;
        },
        error: () => {
          console.log('Could not detect a Grafana endpoint..');
          this.grafanaFound = false;
        },
      });
{'fraction_non_alphanumeric': 0.11956887841023914, 'fraction_numerical': 0.006399461098012799, 'mean_word_length': 3.254297994269341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4670526', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1770, 'n_words': 414}