From a520a94af5615b7a2db3c48420ecc1d72f2b6645 Mon Sep 17 00:00:00 2001 From: Ashish Gaurav Date: Mon, 27 Mar 2023 06:14:04 +0530 Subject: [PATCH 1/2] fix mon_folder variable not used and disable cgo Took 51 minutes --- libs/gen.go | 5 +++-- libs/{ => graph}/graph.go | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) rename libs/{ => graph}/graph.go (81%) diff --git a/libs/gen.go b/libs/gen.go index b9a6d56..c8158ec 100644 --- a/libs/gen.go +++ b/libs/gen.go @@ -87,7 +87,8 @@ func GenTerraform(slosMv map[string]*SLOMultiVerse, c GenConf) (string, error) { panic(err) } - makeOSLODepGraph(slosMv, c) + //to be moved to conditional compilation later + //graph.MakeOSLODepGraph(slosMv, c) return genTerraformForAlpha(slosAlpha, c) } @@ -275,7 +276,7 @@ func SetupOutDir(c GenConf) error { {Path: filepath.Join(c.OutDir, ViewsFolder), Vars: nil}, {Path: filepath.Join(c.OutDir, MonitorsFolder), Vars: []string{VarNameMonRootFolder}}, {Path: filepath.Join(c.OutDir, DashboardsFolder), Vars: []string{VarNameDashRootFolder}}, - {Path: filepath.Join(c.OutDir, NativeSLOFolder), Vars: []string{VarNameNativeSLORootFolder}}, + {Path: filepath.Join(c.OutDir, NativeSLOFolder), Vars: []string{VarNameNativeSLORootFolder, VarNameSLOMonitorRootFolder}}, } } diff --git a/libs/graph.go b/libs/graph/graph.go similarity index 81% rename from libs/graph.go rename to libs/graph/graph.go index e8ba4bf..088427e 100644 --- a/libs/graph.go +++ b/libs/graph/graph.go @@ -1,32 +1,33 @@ -package libs +package graph import ( + "github.com/OpenSLO/slogen/libs" "github.com/goccy/go-graphviz/cgraph" "github.com/goccy/go-graphviz" ) -func makeOSLODepGraph(confs map[string]*SLOMultiVerse, c GenConf) *graphviz.Graphviz { +func MakeOSLODepGraph(confs map[string]*libs.SLOMultiVerse, c libs.GenConf) *graphviz.Graphviz { g := graphviz.New() graph, err := g.Graph() if err != nil { - log.Fatal(err) + libs.Log().Fatal(err) } defer func() { if err := graph.Close(); err != nil { - log.Fatal(err) + libs.Log().Fatal(err) } g.Close() }() err = createNodes(graph, confs) if err != nil { - log.Errorw("error generating slo graph nodes", "err", err) + libs.Log().Errorw("error generating slo graph nodes", "err", err) } err = createEdges(graph, confs) if err != nil { - log.Errorw("error generating slo graph edges", "err", err) + libs.Log().Errorw("error generating slo graph edges", "err", err) } filePath := c.OutDir + "/" + "slo-dep-graph.png" @@ -36,7 +37,7 @@ func makeOSLODepGraph(confs map[string]*SLOMultiVerse, c GenConf) *graphviz.Grap return g } -func createNodes(graph *cgraph.Graph, confs map[string]*SLOMultiVerse) error { +func createNodes(graph *cgraph.Graph, confs map[string]*libs.SLOMultiVerse) error { var err error for _, v := range confs { @@ -70,7 +71,7 @@ func createNodes(graph *cgraph.Graph, confs map[string]*SLOMultiVerse) error { } if err != nil { - log.Errorw("error generating slo graph", "err", err) + libs.Log().Errorw("error generating slo graph", "err", err) return err } //node. @@ -79,7 +80,7 @@ func createNodes(graph *cgraph.Graph, confs map[string]*SLOMultiVerse) error { return nil } -func createEdges(graph *cgraph.Graph, confs map[string]*SLOMultiVerse) error { +func createEdges(graph *cgraph.Graph, confs map[string]*libs.SLOMultiVerse) error { for _, v := range confs { From a833fbfda37011446ae95973143002b2fa9339d1 Mon Sep 17 00:00:00 2001 From: Ashish Gaurav Date: Mon, 27 Mar 2023 06:14:54 +0530 Subject: [PATCH 2/2] disable cgo in goreleaser and add version info as build flags --- .goreleaser.yml | 16 ++++++++++++---- main.go | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 0a4874b..255f467 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -8,18 +8,26 @@ before: - go generate ./... builds: - env: - - CGO_ENABLED=1 + - CGO_ENABLED=0 goos: + - linux - darwin goarch: + - "386" - amd64 - arm - arm64 + - ppc64 + goarm: + - "7" ignore: - - goos: linux - goarch: arm64 - - goos: linux + - goos: windows goarch: arm + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + ldflags: + - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser archives: - replacements: darwin: Darwin diff --git a/main.go b/main.go index 51f097d..d27c2ed 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ 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 + 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, @@ -16,10 +16,44 @@ limitations under the License. package main import ( + "fmt" "github.com/OpenSLO/slogen/cmd" + "runtime" + "runtime/debug" +) + +// nolint: gochecknoglobals +var ( + version = "dev" + commit = "" + date = "" + builtBy = "" ) func main() { + + fmt.Printf("\nrunning version: %s\n\n-------------------\n\n", + buildVersion(version, commit, date, builtBy), + ) + cmd.Execute() +} + +func buildVersion(version, commit, date, builtBy string) string { + result := version + if commit != "" { + result = fmt.Sprintf("%s\ncommit: %s", result, commit) + } + if date != "" { + result = fmt.Sprintf("%s\nbuilt at: %s", result, date) + } + if builtBy != "" { + result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy) + } + result = fmt.Sprintf("%s\ngoos: %s\ngoarch: %s", result, runtime.GOOS, runtime.GOARCH) + if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" { + result = fmt.Sprintf("%s\nmodule version: %s, checksum: %s", result, info.Main.Version, info.Main.Sum) + } + return result }