Skip to content

Commit

Permalink
[ACM-10544] Upgrade addon-manager and k8s libs through custom control…
Browse files Browse the repository at this point in the history
…ler-filtered-cache (stolostron#1468)

* Upgrade addon-manager and k8s libs

Signed-off-by: Douglas Camata <[email protected]>

* Fix Grafana deployment file modified by accident

Signed-off-by: Douglas Camata <[email protected]>

---------

Signed-off-by: Douglas Camata <[email protected]>
Signed-off-by: Periklis Tsirakidis <[email protected]>
  • Loading branch information
douglascamata authored and periklis committed Jun 10, 2024
1 parent fc06fb1 commit a3950df
Show file tree
Hide file tree
Showing 52 changed files with 3,423 additions and 880 deletions.
10 changes: 5 additions & 5 deletions collectors/metrics/cmd/metrics-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/common/version"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/util/uuid"

Expand Down Expand Up @@ -211,7 +210,7 @@ func main() {
opt.Identifier,
"The unique identifier for metrics sent with this client.")

//simulation test
// simulation test
cmd.Flags().StringVar(
&opt.SimulatedTimeseriesFile,
"simulated-timeseries-file",
Expand Down Expand Up @@ -292,7 +291,7 @@ func (o *Options) Run() error {

metricsReg := prometheus.NewRegistry()
metricsReg.MustRegister(
version.NewCollector("metrics_collector"),
collectors.NewBuildInfoCollector(),
collectors.NewGoCollector(
collectors.WithGoCollectorRuntimeMetrics(collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")}),
),
Expand Down Expand Up @@ -606,8 +605,9 @@ func serveLastMetrics(l log.Logger, worker *forwarder.Worker) http.Handler {
return
}
families := worker.LastMetrics()
w.Header().Set("Content-Type", string(expfmt.FmtText))
encoder := expfmt.NewEncoder(w, expfmt.FmtText)
protoTextFormat := expfmt.NewFormat(expfmt.TypeProtoText)
w.Header().Set("Content-Type", string(protoTextFormat))
encoder := expfmt.NewEncoder(w, protoTextFormat)
for _, family := range families {
if family == nil {
continue
Expand Down
19 changes: 11 additions & 8 deletions collectors/metrics/pkg/metricsclient/metricsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *Client) RetrievRecordingMetrics(
var v float64
t = int64(r.Value[0].(float64) * 1000)
v, _ = strconv.ParseFloat(r.Value[1].(string), 64)
ls := []labels.Label{}
var ls []labels.Label
for k, v := range r.Metric {
l := &labels.Label{
Name: k,
Expand All @@ -138,7 +138,8 @@ func (c *Client) RetrievRecordingMetrics(
}
vec = append(vec, promql.Sample{
Metric: ls,
Point: promql.Point{T: t, V: v},
T: t,
F: v,
})
}

Expand All @@ -163,7 +164,7 @@ func (c *Client) RetrievRecordingMetrics(
}

protMetric.TimestampMs = proto.Int64(s.T)
protMetric.Untyped.Value = proto.Float64(s.V)
protMetric.Untyped.Value = proto.Float64(s.F)

protMetricFam.Metric = append(protMetricFam.Metric, protMetric)
families = append(families, protMetricFam)
Expand All @@ -182,7 +183,9 @@ func (c *Client) Retrieve(ctx context.Context, req *http.Request) ([]*clientmode
if req.Header == nil {
req.Header = make(http.Header)
}
req.Header.Set("Accept", strings.Join([]string{string(expfmt.FmtProtoDelim), string(expfmt.FmtText)}, " , "))
protoDelimFormat := expfmt.NewFormat(expfmt.TypeProtoDelim)
protoTextFormat := expfmt.NewFormat(expfmt.TypeProtoText)
req.Header.Set("Accept", strings.Join([]string{string(protoDelimFormat), string(protoTextFormat)}, " , "))

ctx, cancel := context.WithTimeout(ctx, c.timeout)
req = req.WithContext(ctx)
Expand Down Expand Up @@ -234,7 +237,7 @@ func (c *Client) Retrieve(ctx context.Context, req *http.Request) ([]*clientmode
// // TODO(saswatamcode): This is no longer used, remove it in the future.
func Read(r io.Reader) ([]*clientmodel.MetricFamily, error) {
decompress := snappy.NewReader(r)
decoder := expfmt.NewDecoder(decompress, expfmt.FmtProtoDelim)
decoder := expfmt.NewDecoder(decompress, expfmt.NewFormat(expfmt.TypeProtoDelim))
families := make([]*clientmodel.MetricFamily, 0, 100)
for {
family := &clientmodel.MetricFamily{}
Expand All @@ -253,7 +256,7 @@ func Read(r io.Reader) ([]*clientmodel.MetricFamily, error) {
func Write(w io.Writer, families []*clientmodel.MetricFamily) error {
// output the filtered set
compress := snappy.NewBufferedWriter(w)
encoder := expfmt.NewEncoder(compress, expfmt.FmtProtoDelim)
encoder := expfmt.NewEncoder(compress, expfmt.NewFormat(expfmt.TypeProtoDelim))
for _, family := range families {
if family == nil {
continue
Expand Down Expand Up @@ -468,7 +471,7 @@ func (c *Client) RemoteWrite(ctx context.Context, req *http.Request,
}
logger.Log(c.logger, logger.Debug, "timeseries number", len(timeseries))

//uncomment here to generate timeseries
// uncomment here to generate timeseries
/*
for i := 0; i < len(families); i++ {
var buff bytes.Buffer
Expand Down Expand Up @@ -530,7 +533,7 @@ func (c *Client) sendRequest(serverURL string, body []byte) error {
return errors.New(msg)
}

//req.Header.Add("THANOS-TENANT", tenantID)
// req.Header.Add("THANOS-TENANT", tenantID)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
Expand Down
5 changes: 3 additions & 2 deletions collectors/metrics/pkg/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

clientmodel "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"

rlogger "github.com/stolostron/multicluster-observability-operator/collectors/metrics/pkg/logger"
)

Expand Down Expand Up @@ -61,9 +62,9 @@ func SimulateMetrics(logger log.Logger) []*clientmodel.MetricFamily {
sb.WriteString(fmt.Sprintf("%f %d", randFloat64(), timestamp))
sb.WriteString("\n")
}
//rlogger.Log(logger, rlogger.Error, "data", sb.String())
// rlogger.Log(logger, rlogger.Error, "data", sb.String())
r := io.NopCloser(bytes.NewReader([]byte(sb.String())))
decoder := expfmt.NewDecoder(r, expfmt.FmtText)
decoder := expfmt.NewDecoder(r, expfmt.NewFormat(expfmt.TypeProtoText))
for {
family := &clientmodel.MetricFamily{}
families = append(families, family)
Expand Down
9 changes: 8 additions & 1 deletion collectors/metrics/pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func New(logger log.Logger) (*StatusReport, error) {
standaloneMode := os.Getenv("STANDALONE") == "true"
var kubeClient client.Client
if testMode {
kubeClient = fake.NewClientBuilder().Build()
s := scheme.Scheme
if err := oav1beta1.AddToScheme(s); err != nil {
return nil, errors.New("failed to add observabilityaddon into scheme")
}
kubeClient = fake.NewClientBuilder().
WithScheme(s).
WithStatusSubresource(&oav1beta1.ObservabilityAddon{}).
Build()
} else if standaloneMode {
kubeClient = nil
} else {
Expand Down
Loading

0 comments on commit a3950df

Please sign in to comment.