Skip to content

Commit

Permalink
Merge pull request #5 from IBM/dev
Browse files Browse the repository at this point in the history
 update git repo, add parser source, fix some issues
  • Loading branch information
sunya-ch authored Jul 4, 2022
2 parents e09ed07 + 41131c9 commit b424c14
Show file tree
Hide file tree
Showing 51 changed files with 2,480 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bin
testbin
_all-built-manifests.yaml
all-built-manifests.yaml
iteration/node-tuning
iteration/node-tuning-test
*.log
transfer.sh
kubectl
Expand Down
8 changes: 4 additions & 4 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
projectName: cpe-operator
repo: github.ibm.com/CognitiveAdvisor/cpe-operator
repo: github.com/IBM/cpe-operator
resources:
- api:
crdVersion: v1
Expand All @@ -14,7 +14,7 @@ resources:
domain: cogadvisor.io
group: cpe
kind: Benchmark
path: github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1
path: github.com/IBM/cpe-operator/api/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -23,7 +23,7 @@ resources:
domain: cogadvisor.io
group: cpe
kind: BenchmarkOperator
path: github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1
path: github.com/IBM/cpe-operator/api/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -32,6 +32,6 @@ resources:
domain: cogadvisor.io
group: cpe
kind: EvaluationConfig
path: github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1
path: github.com/IBM/cpe-operator/api/v1
version: v1
version: "3"
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ CPE operator is a project that originally implements the AutoDECK framework. Aut
```
7. Clone, Build and Push parser to the registry
```bash
git clone https://github.ibm.com/CognitiveAdvisor/cpe-parser.git # internal location
# git clone https://github.com/IBM/cpe-operator.git # soon to be provided
cd cpe-parser
chmod +x build_push.sh
# If you want to deploy to different registry, need to set target IMAGE_REGISTRY and VERSION
Expand Down
2 changes: 1 addition & 1 deletion controllers/benchmark_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

cpev1 "github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1"
cpev1 "github.com/IBM/cpe-operator/api/v1"
)

// BenchmarkReconciler reconciles a Benchmark object
Expand Down
2 changes: 1 addition & 1 deletion controllers/benchmarkoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

cpev1 "github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1"
cpev1 "github.com/IBM/cpe-operator/api/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion controllers/build_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"k8s.io/client-go/tools/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

cpev1 "github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1"
cpev1 "github.com/IBM/cpe-operator/api/v1"
)

const NO_BUILD_RESOURCE_ERROR = "the server could not find the requested resource"
Expand Down
2 changes: 1 addition & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"sort"
"strings"

cpev1 "github.com/IBM/cpe-operator/api/v1"
"github.com/go-logr/logr"
cpev1 "github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down
2 changes: 1 addition & 1 deletion controllers/iteration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"strconv"
"strings"

cpev1 "github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1"
cpev1 "github.com/IBM/cpe-operator/api/v1"
)

type IterationKeyType int
Expand Down
2 changes: 1 addition & 1 deletion controllers/job_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"k8s.io/client-go/tools/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

cpev1 "github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1"
cpev1 "github.com/IBM/cpe-operator/api/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

cpev1 "github.ibm.com/CognitiveAdvisor/cpe-operator/api/v1"
cpev1 "github.com/IBM/cpe-operator/api/v1"
//+kubebuilder:scaffold:imports
)

Expand Down
14 changes: 14 additions & 0 deletions cpe-parser/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.16

WORKDIR /go/src/cpe-parser
COPY parser parser
COPY common common
COPY main.go main.go
COPY api.go api.go
COPY go.mod go.mod
RUN go mod tidy
RUN go get -d -v ./...
RUN go install -v ./...

CMD ["cpe-parser"]

109 changes: 109 additions & 0 deletions cpe-parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# CPE Parser Module
- [x] Implement app-specific parser
`func ParseValue(body []byte) (map[string][]float64, error)`
- [x] Implement common work to [read log from cos](common/cos.go) and [push to Prometheus's PushGateway](common/pusher.go)
- create three stat gauge per a key from values: [key]_min_val, [key]_max_val, [key]_avg_val
- group by benchmark name
- push to PushGatewayURL
- [x] Implement REST API to receive request to read and push log metric
- [x] Docker Image and Kubernetes YAML with Secret Environments

## Build and Push image
```bash
export IMAGE_REGISTRY=[your image regirstry]
export VERSION=[your image tag]
chmod +x build_push.sh
./build_push.sh
```

## Set environments and Deploy
Pre-deploy Requirements:
- deploy secret key for image pull: $PULL_SECRET [[read more](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/)]
- deploy secret key for S3 cloud object storage: $COS_SECRET
```yaml
apiVersion: v1
kind: Secret
metadata:
name: cpe-cos-key
type: Opaque
stringData:
rawBucketName: [bucketName]
apiKey: [apiKey]
serviceInstanceID: [instance ID]
authEndpoint: [authentication endpoint]
serviceEndpoint: [service endpoint]
```
- deploy prometheus push gateway [[read more](https://github.com/prometheus/pushgateway)]
Deployment Steps:
1. set all environments
```bash
export PARSER_NAMESPACE=[parser namespace]
export IMAGE_REGISTRY=[your image regirstry] # if not set yet
export VERSION=[your image tag] # if not set yet
export PUSHGATEWAY_URL=[pushgateway service].[service namespace]:[service port]
export PULL_SECRET=[image pull secret name]
export COS_SECRET=[storage secret name]
```
2. replace the template
```bash
envsubst < deploy_template.yaml > deploy.yaml
```
3. deploy
```bash
kubectl create -f deploy.yaml
```

Service Point: `http://cpe-parser.cpe-operator-system:80`

## Add new parser

1. Create new parser struct with BaseParser abstraction and put in parser folder (see [example](parser/default.go))
```go
package parser
type CustomParser struct {
*BaseParser
}
func NewCustomParser() *CustomParser {
newParser := &CustomParser{}
abs := &BaseParser{
Parser: newParser,
}
newParser.BaseParser = abs
return newParser
}
func (p *CustomParser) ParseValue(body []byte) (map[string]interface{}, error) {
values := make(map[string]interface{})
// values can be float64, []float64, []parser.ValueWithLabels, or []parser.ValuesWithLabels
// Put your parsing code here where body is log bytes
return values, nil
}
func (p *CustomParser) GetPerformanceValue(values map[string]interface{}) (string, float64) {
// Put your performance key,value extraction here
// values = return values from ParseValue function
return performanceKey, performanceValue
}
```
2. add your parser to following code in api.go
```go
// add parser key -> module map here
var codaitParser parser.Parser = parser.NewCodaitParser()
var defaultParser parser.Parser = parser.NewDefaultParser()
var newParser parser.Parser = parser.NewCustomParser()
var parserMap map[string]parser.Parser = map[string]parser.Parser{
"codait": codaitParser,
"default": defaultParser,
"customKey": customParser,
}
```
3. rebuild and push
```bash
./build_push.sh
```
Loading

0 comments on commit b424c14

Please sign in to comment.