Skip to content

Commit

Permalink
add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed May 5, 2020
1 parent f25a6ae commit a7015c7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cmd/autoupdate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/blang/semver"

"github.com/cdnjs/tools/compress"
"github.com/cdnjs/tools/metrics"
"github.com/cdnjs/tools/packages"
"github.com/cdnjs/tools/util"
)
Expand Down Expand Up @@ -131,7 +132,6 @@ func compressNewVersion(ctx context.Context, version newVersionToCommit) {
// jpeg
{
files := filterByExt(files, compress.JpegExt)
util.Debugf(ctx, "found %d jpeg to compress\n", len(files))
for _, file := range files {
absfile := path.Join(version.versionPath, file)
compress.CompressJpeg(ctx, absfile)
Expand All @@ -144,7 +144,6 @@ func compressNewVersion(ctx context.Context, version newVersionToCommit) {
_, err := os.Stat(path.Join(version.pckg.Path(), ".donotoptimizepng"))
if os.IsNotExist(err) {
files := filterByExt(files, compress.PngExt)
util.Debugf(ctx, "found %d png to compress\n", len(files))
for _, file := range files {
absfile := path.Join(version.versionPath, file)
compress.CompressPng(ctx, absfile)
Expand All @@ -154,7 +153,6 @@ func compressNewVersion(ctx context.Context, version newVersionToCommit) {
// js
{
files := filterByExt(files, compress.JsExt)
util.Debugf(ctx, "found %d js to compress\n", len(files))
for _, file := range files {
absfile := path.Join(version.versionPath, file)
compress.CompressJs(ctx, absfile)
Expand All @@ -163,7 +161,6 @@ func compressNewVersion(ctx context.Context, version newVersionToCommit) {
// css
{
files := filterByExt(files, compress.CssExt)
util.Debugf(ctx, "found %d css to compress\n", len(files))
for _, file := range files {
absfile := path.Join(version.versionPath, file)
compress.CompressCss(ctx, absfile)
Expand Down Expand Up @@ -193,6 +190,8 @@ func commitNewVersions(ctx context.Context, newVersionsToCommit []newVersionToCo
packages.GitCommit(ctx, CDNJS_PATH, commitMsg)

log(ctx, LogNewVersionCommit{Version: newVersionToCommit.newVersion})

metrics.ReportNewVersion()
}
}

Expand Down
25 changes: 25 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package metrics

import (
"fmt"
"net/http"
"strings"

"github.com/cdnjs/tools/util"
)

const (
BASE_URL = "https://metrics.cdnjs.com"
METRIC_NEW_VERSION = "new_version"
)

func reportMetric(metricType string) {
token := util.GetEnv("METRICS_TOKEN")
body := strings.NewReader("")
_, err := http.Post(fmt.Sprintf("%s/%s?token=%s", BASE_URL, metricType, token), "text/plain", body)
util.Check(err)
}

func ReportNewVersion() {
reportMetric(METRIC_NEW_VERSION)
}

0 comments on commit a7015c7

Please sign in to comment.