Skip to content

Commit

Permalink
fix: Incorrect conversion between integer types
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Vasquez <[email protected]>
  • Loading branch information
rafvasq committed Nov 1, 2023
1 parent 693291a commit 516a6d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion internal/envconfig/envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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,
Expand Down Expand Up @@ -46,6 +46,17 @@ func GetEnvInt(key string, defaultValue int, log logr.Logger) int {
return defaultValue
}

func GetEnvInt32(key string, defaultValue int32, log logr.Logger) int32 {
if strVal, found := os.LookupEnv(key); found {
if valueInt, err := strconv.ParseInt(strVal, 10, 32); err != nil {
log.Error(err, "Environment variable must be an int32", "env_var", key, "value", strVal)
} else {
return int32(valueInt)
}
}
return defaultValue
}

func GetEnvFloat(key string, defaultValue float64, log logr.Logger) float64 {
if strVal, found := os.LookupEnv(key); found {
val, err := strconv.ParseFloat(strVal, 64)
Expand Down
6 changes: 3 additions & 3 deletions model-mesh-torchserve-adapter/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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,
Expand Down Expand Up @@ -81,8 +81,8 @@ func GetAdapterConfigurationFromEnv(log logr.Logger) (*AdapterConfiguration, err
return nil, fmt.Errorf("Could not construct torchserve model store path: %w", err)
}

adapterConfig.RequestBatchSize = int32(GetEnvInt(requestBatchSize, defaultRequestBatchSize, log))
adapterConfig.MaxBatchDelaySecs = int32(GetEnvInt(maxBatchDelaySecs, defaultMaxBatchDelaySecs, log))
adapterConfig.RequestBatchSize = GetEnvInt32(requestBatchSize, defaultRequestBatchSize, log)
adapterConfig.MaxBatchDelaySecs = GetEnvInt32(maxBatchDelaySecs, defaultMaxBatchDelaySecs, log)

if adapterConfig.TorchServeContainerMemReqBytes < 0 {
return nil, fmt.Errorf("%s environment variable must be set to a positive integer, found value %v",
Expand Down

0 comments on commit 516a6d2

Please sign in to comment.