Skip to content
Snippets Groups Projects
Select Git revision
  • 4e07ddf52652445024a78a04dd70bc34d6be4d19
  • main default protected
  • fix/36615b-branch-reuse-no-cache
  • renovate/main-redis-5.x
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • chore/punycode
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • gh-readonly-queue/next/pr-35009-9d5e583b7d7251148ab0d11ee8dd38149618d162
  • 41.38.2
  • 41.38.1
  • 41.38.0
  • 41.37.12
  • 41.37.11
  • 41.37.10
  • 41.37.9
  • 41.37.8
  • 41.37.7
  • 41.37.6
  • 41.37.5
  • 41.37.4
  • 41.37.3
  • 41.37.2
  • 41.37.1
  • 41.37.0
  • 41.36.2
  • 41.36.1
  • 41.36.0
  • 41.35.2
41 results

self-hosted-configuration.md

Blame
  • prometheus_client.go 3.49 KiB
    // Copyright 2019 The prometheus-operator Authors
    //
    // 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.
    
    package e2e
    
    import (
    	"bytes"
    	"context"
    	"encoding/json"
    	"fmt"
    
    	"k8s.io/client-go/kubernetes"
    
    	"github.com/Jeffail/gabs"
    	promv1 "github.com/prometheus/client_golang/api/prometheus/v1"
    )
    
    type prometheusClient struct {
    	kubeClient kubernetes.Interface
    }
    
    func newPrometheusClient(kubeClient kubernetes.Interface) *prometheusClient {
    	return &prometheusClient{kubeClient}
    }
    
    // Response hold API response in a form similar to apiResponse struct from prometheus/client_golang
    // https://github.com/prometheus/client_golang/blob/master/api/prometheus/v1/api.go
    type Response struct {
    	Status string          `json:"status"`
    	Data   json.RawMessage `json:"data"`
    }
    
    // apiRequest makes a request against specified Prometheus API endpoint
    func (c *prometheusClient) apiRequest(endpoint string, selector string, query string) (Response, error) {
    	req := c.kubeClient.CoreV1().RESTClient().Get().
    		Namespace("monitoring").
    		Resource("pods").
    		SubResource("proxy").
    		Name("prometheus-k8s-0:9090").
    		Suffix(endpoint).Param(selector, query)
    
    	var data Response
    	b, err := req.DoRaw(context.Background())
    	if err != nil {
    		return data, err
    	}
    
    	r := bytes.NewReader(b)
    	decoder := json.NewDecoder(r)
    	err = decoder.Decode(&data)
    	if err != nil {
    		return data, err
    	}
    
    	if data.Status != "success" {
    		return data, fmt.Errorf("status of returned response was not successful; status: %s", data.Status)
    	}
    
    	return data, err