-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add extended runtime test * fix build constraints * format * linter * add handle testing on windows * add ci target for extended test, see what happens * rename test key * increase default time * add check * use shorter period settings * add apache tests * first pass at derivatives * add test * use derivatives * make notice * change time * try to fix notice * add log line to watcher * add NaN check * add more debug data * fix math * fix calc errors * fix test build * cleanup * docs, cleanup * use spigot, fixup errors * use spigot, cef, elastic-agent events for fetching pids * oops * fighting with notice * fix ticker, tinker with other things * docs * improve docs * fix gomod * update notice * fix notice * refactor, use epr for package versions * linter * fix linter * fixes for HTTP helpers * use hard-coded versions * fix ctx * fighting with logs * name changes, fighting with logs * add tests, check logs * fix ci issues * clean up * oops * cleanup, rename a few tings * fix tags
- Loading branch information
1 parent
4509b55
commit b5fdc6d
Showing
16 changed files
with
1,627 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package tools | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
const eprProd = "https://epr.elastic.co" | ||
|
||
// / PackageSearchResult contains basic info on a package returned by a search | ||
type PackageSearchResult struct { | ||
Name string `json:"name"` | ||
Version string `json:"version"` | ||
Release string `json:"release"` | ||
Path string `json:"path"` | ||
} | ||
|
||
// GetLatestPackageRelease returns the version string of the latest package release | ||
func GetLatestPackageRelease(ctx context.Context, packageName string) (string, error) { | ||
endpoint := fmt.Sprintf("%s/search?package=%s&all=false", eprProd, packageName) | ||
req, err := http.NewRequestWithContext(ctx, "GET", endpoint, nil) | ||
if err != nil { | ||
return "", fmt.Errorf("error creating HTTP request: %w", err) | ||
} | ||
resp, err := http.DefaultClient.Do(req) //nolint:gosec,nolintlint // it's a test | ||
//create body before we check for errors, easier to format error strings that way | ||
body, errRead := io.ReadAll(resp.Body) | ||
if errRead != nil { | ||
return "", fmt.Errorf("error reading body of HTTP resp: %w", err) | ||
} | ||
resp.Body.Close() | ||
if err != nil { | ||
return "", fmt.Errorf("failed to create search request for EPR (%s): %w", body, err) | ||
} | ||
if resp.StatusCode >= 300 { | ||
return "", fmt.Errorf("bad status code in response from EPR: %d - %s", resp.StatusCode, resp.Status) | ||
} | ||
|
||
parsedResp := []PackageSearchResult{} | ||
err = json.Unmarshal(body, &parsedResp) | ||
if err != nil { | ||
return "", fmt.Errorf("error parsing search response: %w", err) | ||
} | ||
// if we set &all=false, we'll get at most one result | ||
if len(parsedResp) < 1 { | ||
return "", fmt.Errorf("no packages matching '%s' found", packageName) | ||
} | ||
|
||
return parsedResp[0].Version, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package tools | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/sajari/regression" | ||
) | ||
|
||
// Slope is a slim wrapper around a regression library for calculating rate of change over time in tests. | ||
type Slope struct { | ||
handler *regression.Regression | ||
} | ||
|
||
func NewSlope(label string) Slope { | ||
handler := new(regression.Regression) | ||
handler.SetObserved(label) | ||
handler.SetVar(0, "time") | ||
return Slope{handler: handler} | ||
} | ||
|
||
// add a datapoint and timestamp to the calculaton. | ||
func (slope Slope) AddDatapoint(count float64, timeSinceStart time.Duration) { | ||
slope.handler.Train(regression.DataPoint(count, []float64{timeSinceStart.Seconds()})) | ||
} | ||
|
||
// Run the regression on the supplied data | ||
func (slope Slope) Run() error { | ||
return slope.handler.Run() | ||
} | ||
|
||
// return the slope of the regression | ||
func (slope Slope) GetSlope() float64 { | ||
return slope.handler.GetCoeffs()[1] | ||
} | ||
|
||
// Formula returns a string representation of the regression formula | ||
func (slope Slope) Formula() string { | ||
return slope.handler.Formula | ||
} | ||
|
||
// Debug returns a string representation of the regression, including all datapoints | ||
func (slope Slope) Debug() string { | ||
return slope.handler.String() | ||
} |
Oops, something went wrong.