Skip to content

Commit

Permalink
Refactor path for configuration file, option(s) and Docker image (#94)
Browse files Browse the repository at this point in the history
Signed-off-by: Arrobo, Gabriel <gabriel.arrobo@intel.com>
  • Loading branch information
gab-arrobo authored Nov 2, 2024
1 parent 44a9ed6 commit 7d14ddd
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 101 deletions.
42 changes: 13 additions & 29 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# SPDX-FileCopyrightText: 2022-present Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0


# This file contains all available configuration options
# with their default values.
# options for analysis running
Expand All @@ -27,19 +25,6 @@ run:
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- "api_.*\\.go$"
- "model_.*\\.go$"
- "routers.go"
- "client.go"
- "configuration.go"
- "nas.go"
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand All @@ -55,7 +40,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number
# print lines of code with issue, default is true
print-issued-lines: true
# print linter name in the end of issue text, default is true
Expand Down Expand Up @@ -138,10 +123,14 @@ linters-settings:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gomnd:
settings:
mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks:
- argument
- case
- condition
- operation
- return
- assign
gomodguard:
allowed:
modules: # List of allowed modules
Expand All @@ -159,8 +148,6 @@ linters-settings:
# version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
govet:
# report about shadowed variables
check-shadowing: true
# settings per analyzer
settings:
printf: # analyzer name, run `go tool vet help` to see all analyzers
Expand Down Expand Up @@ -208,8 +195,6 @@ linters-settings:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gci:
local-prefixes: "bitbucket.org"
misspell:
#locale: US
ignore-words:
Expand All @@ -230,9 +215,8 @@ linters:
- lll
- godox
#- gomnd
#- goconst
- goconst
# - gocognit
# - maligned
# - nestif
# - gomodguard
- nakedret
Expand All @@ -246,9 +230,9 @@ linters:
- dogsled
# - bodyclose
- asciicheck
#- stylecheck
# - unparam
#- wsl
# - stylecheck
# - unparam
# - wsl

#disable-all: false
fast: true
Expand Down
13 changes: 3 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

FROM golang:1.23.2-bookworm AS builder

LABEL maintainer="Aether SD-Core <dev@aetherproject.org>"

WORKDIR $GOPATH/src/metricfunc
COPY . .
RUN make all

FROM alpine:3.20 AS metricfunc

LABEL description="Aether open source 5G Core Network" \
LABEL maintainer="Aether SD-Core <dev@lists.aetherproject.org>" \
description="Aether open source 5G Core Network" \
version="Stage 3"

ARG DEBUG_TOOLS
Expand All @@ -23,11 +22,5 @@ RUN if [ "$DEBUG_TOOLS" = "true" ]; then \
apk update && apk add --no-cache -U vim strace net-tools curl netcat-openbsd bind-tools tcpdump; \
fi

# Set working dir
WORKDIR /metricfunc/bin

# Copy executable
COPY --from=builder /go/src/metricfunc/bin/* .

#Image default directory
WORKDIR /metricfunc
COPY --from=builder /go/src/metricfunc/bin/* /usr/local/bin/.
62 changes: 42 additions & 20 deletions api/apiserver/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,44 @@ import (
)

func GetSubscriberSummary(c *gin.Context) {

subId := c.Params.ByName("imsi")
sub, _ := metricdata.GetSubscriber(subId)
sub, err := metricdata.GetSubscriber(subId)
if err != nil {
logger.ApiSrvLog.Errorf("get subscriber error: %+v", err)
}

if sub != nil {
resBody, err := openapi.Serialize(sub, "application/json")
if err != nil {
logger.ApiSrvLog.Errorf("json marshal error: %+v", err)
}

_, err = c.Writer.Write(resBody)
if err != nil {
logger.ApiSrvLog.Errorf("json Marshal error %s", err.Error())
logger.ApiSrvLog.Errorf("write data error: %+v", err)
}

c.Writer.Write(resBody)
c.Status(http.StatusOK)
return
}

logger.ApiSrvLog.Errorf("subscriber data not found, imsi [%s] ", subId)
logger.ApiSrvLog.Errorf("subscriber data not found, imsi [%s]", subId)
c.JSON(http.StatusNotFound, gin.H{})
}

func GetSubscriberAll(c *gin.Context) {

subs := metricdata.GetSubscriberAll()
if len(subs) != 0 {
resBody, err := openapi.Serialize(subs, "application/json")
if err != nil {
logger.ApiSrvLog.Errorf("json marshal error %+v", err)
}

_, err = c.Writer.Write(resBody)
if err != nil {
logger.ApiSrvLog.Errorf("json Marshal error %s", err.Error())
logger.ApiSrvLog.Errorf("write data error: %+v", err)
}

c.Writer.Write(resBody)
c.Status(http.StatusOK)
return
}
Expand All @@ -60,16 +68,19 @@ func GetNfStatus(c *gin.Context) {
nfs := metricdata.GetNfStatusbyNfType(nfType)
if len(nfs) != 0 {
resBody, err := openapi.Serialize(nfs, "application/json")
if err != nil {
logger.ApiSrvLog.Errorf("json marshal error: %+v", err)
}

_, err = c.Writer.Write(resBody)
if err != nil {
logger.ApiSrvLog.Errorf("json Marshal error %s", err.Error())
logger.ApiSrvLog.Errorf("write data error: %+v", err)
}

c.Writer.Write(resBody)
c.Status(http.StatusOK)
return
}
logger.ApiSrvLog.Errorf("no nfs data not found ")
logger.ApiSrvLog.Errorln("no nfs data not found")
c.JSON(http.StatusNotFound, gin.H{})
}

Expand All @@ -78,21 +89,24 @@ func GetNfStatusAll(c *gin.Context) {

if len(nfs) != 0 {
resBody, err := openapi.Serialize(nfs, "application/json")
if err != nil {
logger.ApiSrvLog.Errorf("json marshal error %+v", err)
}

_, err = c.Writer.Write(resBody)
if err != nil {
logger.ApiSrvLog.Errorf("json Marshal error %s", err.Error())
logger.ApiSrvLog.Errorf("write data error: %+v", err)
}
c.Writer.Write(resBody)

c.Status(http.StatusOK)
return
}
logger.ApiSrvLog.Errorf("no nfs data not found ")
logger.ApiSrvLog.Errorln("no nfs data not found")
c.JSON(http.StatusNotFound, gin.H{})
}

// Gives summary stats for any service
func GetNfServiceStatsSummary(c *gin.Context) {

}

// Gives detail stats of any service
Expand All @@ -102,13 +116,18 @@ func GetNfServiceStatsDetail(c *gin.Context) {
if svcStats, err := metricdata.GetNfServiceStatsDetail(nfType); err == nil {
resBody, err := openapi.Serialize(svcStats, "application/json")
if err != nil {
logger.ApiSrvLog.Errorf("json Marshal error %s", err.Error())
logger.ApiSrvLog.Errorf("json marshal error: %+v", err)
}

_, err = c.Writer.Write(resBody)
if err != nil {
logger.ApiSrvLog.Errorf("write data error: %+v", err)
}
c.Writer.Write(resBody)

c.Status(http.StatusOK)
return
}
logger.ApiSrvLog.Errorf("no nf service statistics data not found ")
logger.ApiSrvLog.Errorln("no nf service statistics data not found")
c.JSON(http.StatusNotFound, gin.H{})
}

Expand All @@ -119,11 +138,14 @@ func GetNfServiceStatsAll(c *gin.Context) {
func PushTestIPs(c *gin.Context) {
requestBody, err := c.GetRawData()
if err != nil {
logger.ApiSrvLog.Errorf("get requestbody error %s", err.Error())
logger.ApiSrvLog.Errorf("get requestbody error: %+v", err)
return
}
var rogueIPs controller.RogueIPs
json.Unmarshal(requestBody, &rogueIPs)
err = json.Unmarshal(requestBody, &rogueIPs)
if err != nil {
logger.ApiSrvLog.Errorf("json unmarshal error: %+v", err)
}

logger.ApiSrvLog.Infoln("Test RogueIPs: ", rogueIPs)
controller.RogueChannel <- rogueIPs
Expand Down
Loading

0 comments on commit 7d14ddd

Please sign in to comment.