Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change advanced metrics socket default location #32

Merged
merged 6 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ func LoadPropertiesFromFile(cfg string) error {

// Get dynamic file, if it doesn't exist create it.
file, err := os.Stat(dynamicCfgPath)

if err != nil {
log.Warnf("Unable to read dynamic config (%s), got the following error: %v", dynamicCfgPath, err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var (
Mode: "aggregation",
},
AdvancedMetrics: AdvancedMetrics{
SocketPath: "/tmp/advanced-metrics.sock",
SocketPath: "/var/run/nginx-agent/advanced-metrics.sock",
AggregationPeriod: time.Second * 10,
PublishingPeriod: time.Second * 30,
TableSizesLimits: advanced_metrics.TableSizesLimits{
Expand Down
8 changes: 4 additions & 4 deletions src/extensions/advanced-metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ need to be provided. nginx-agent.conf snippet for advanced metrics showing defau
server: ...
tls: ...
advanced_metrics:
socket_path: /tmp/acm.sock
socket_path: /var/run/nginx-agent/advanced-metrics.sock
aggregation_period: 1s
publishing_period: 3s
table_sizes_limits:
Expand All @@ -32,7 +32,7 @@ advanced_metrics:
#### Parameter Definitions:</BR>
|Parameter| Description|
| ----------- | ----------- |
socket_path| Full os filepath to the unix socket which Nginx+ andAgent use to comunicate.
socket_path| Full os filepath to the unix socket which Nginx+ and Agent use to communicate.
aggregation_period| Frequency at which data in priority tables are aggregated to conserve space prior to publishing.
publishing_period| Frequency at which data in priority tables is published to Management Plane.
table_sizes_limits|staging_table_max_size| Max number of records allowed within any single aggregation period.staging_table_threshold | When the number of records reaches this threshold, data aggregation starts to keep number of records within the staging_table_max_size limit. **staging_table_threshold &le; staging_table_max_size**.
Expand Down Expand Up @@ -124,9 +124,9 @@ schema.NewSchemaBuilder().

This example defines that advanced metrics is able to receive messages with 5 fields and only 5 fields where:
- 1st is dimension with `dim1` name, this name will be used by `Publisher` to set `MetricsSet.Dimensions.Name` value, and cardinality 100, which means that up to 100 different possible dimensions values will be collected in single `PublishingPeriod`,
- 2nd same as above but this `dim2` dimension additionally specifies CollapsingLevel, which should be a percent more [here](./pkg/shema_builder.go)
- 2nd same as above but this `dim2` dimension additionally specifies CollapsingLevel, which should be a percent more [here](./pkg/schema/schema_builder.go)
- 3th dimension which is integer dimensions, so value of dimensions will be converted into integer and IT'S value will be used as a lookup code, this is optimization which save space in lookup tables and stores its value in key itself rather than keeping string representation of integers
- 4th and 5th are metrics same as with dimenisons this name will be used in `MetricsSet` struct, metrics does not contain any additional options
- 4th and 5th are metrics same as with dimensions this name will be used in `MetricsSet` struct, metrics does not contain any additional options

### Advanced Metrics

Expand Down
3 changes: 2 additions & 1 deletion src/extensions/advanced-metrics/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"errors"
"fmt"
"golang.org/x/sync/errgroup"
"net"
"os"
"sync"

log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)

//go:generate mockgen -source reader.go -destination mocks/reader_mock.go -package mocks
Expand Down Expand Up @@ -151,6 +151,7 @@ func (r *Reader) runWorker(ctx context.Context, connection net.Conn, id int) {

func (r *Reader) checkSocketAndCleanup() error {
log.Info("Checking availability of unix socket")

if _, err := os.Stat(r.address); err == nil {
err = os.Remove(r.address)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (p *PriorityTable) shouldCollapseSamples() bool {
func (p *PriorityTable) collapseSample(sample *sample.Sample, currentCollapseLevel limits.CollapsingLevel) {
for _, dim := range p.schema.Dimensions() {
if dim.ShouldCollapse(currentCollapseLevel) {
sample.Key().SetKeyPart(lookup.LookupAggrCode, dim.KeyBitSize, dim.KeyBitPositionInCompoudKey)
sample.Key().SetKeyPart(lookup.LookupAggrCode, dim.KeyBitSize, dim.KeyBitPositionInCompoundKey)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/extensions/advanced-metrics/tables/schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ type Field struct {
// MaxDimensionSetSize specifies max unique dimension which will be stored in staging table
// if max size will be reaches all new unique dimensions will be transformed to AGGR value
type DimensionField struct {
KeyBitSize int
KeyBitPositionInCompoudKey int
MaxDimensionSetSize uint32
Transform *DimensionTransformFunction
CollapsingLevel *limits.CollapsingLevel
KeyBitSize int
KeyBitPositionInCompoundKey int
MaxDimensionSetSize uint32
Transform *DimensionTransformFunction
CollapsingLevel *limits.CollapsingLevel
}

type FieldOption func(f *Field)
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/advanced-metrics/tables/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewSchema(fields ...*Field) *Schema {
if f.Type == FieldTypeDimension {
dims = append(dims, f)

f.KeyBitPositionInCompoudKey = keyBits
f.KeyBitPositionInCompoundKey = keyBits
keyBits += f.KeyBitSize
f.index = dimensionIndex
dimensionIndex++
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/advanced_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (m *AdvancedMetrics) run() {
if err != nil {
log.Error("App centric metric plugin failed to change socket permissions")
}
commonDimmensions := append(m.commonDims.ToDimensions(), &proto.Dimension{
commonDimensions := append(m.commonDims.ToDimensions(), &proto.Dimension{
Name: aggregationDurationDimension,
Value: strconv.Itoa(int(m.cfg.PublishingPeriod.Seconds())),
})
Expand All @@ -199,7 +199,7 @@ func (m *AdvancedMetrics) run() {
return
}
now := types.TimestampNow()
m.pipeline.Process(core.NewMessage(core.CommMetrics, []core.Payload{toMetricReport(mr, now, commonDimmensions)}))
m.pipeline.Process(core.NewMessage(core.CommMetrics, []core.Payload{toMetricReport(mr, now, commonDimensions)}))
case <-m.pipeline.Context().Done():
return
}
Expand All @@ -223,7 +223,7 @@ func enableWritePermissionForSocket(path string) error {
}
}

func toMetricReport(set []*publisher.MetricSet, now *types.Timestamp, commonDimmensions []*proto.Dimension) *proto.MetricsReport {
func toMetricReport(set []*publisher.MetricSet, now *types.Timestamp, commonDimensions []*proto.Dimension) *proto.MetricsReport {
mr := &proto.MetricsReport{
Meta: &proto.Metadata{Timestamp: now},
Type: proto.MetricsReport_INSTANCE,
Expand All @@ -234,7 +234,7 @@ func toMetricReport(set []*publisher.MetricSet, now *types.Timestamp, commonDimm
statsEntity := proto.StatsEntity{
Timestamp: now,
Simplemetrics: make([]*proto.SimpleMetric, 0, len(s.Metrics)*4),
Dimensions: commonDimmensions,
Dimensions: commonDimensions,
}

isStreamMetric := false
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/advanced_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestAppCentricMetric_toMetricReport(t *testing.T) {
}, report)
}

func TestAppCenticMetricClose(t *testing.T) {
func TestAppCentricMetricClose(t *testing.T) {
env := tutils.GetMockEnv()
pluginUnderTest := NewAdvancedMetrics(env, &config.Config{})

Expand All @@ -201,7 +201,7 @@ func TestAppCenticMetricClose(t *testing.T) {
env.AssertExpectations(t)
}

func TestAppCenticMetricSubscriptions(t *testing.T) {
func TestAppCentricMetricSubscriptions(t *testing.T) {
pluginUnderTest := NewAdvancedMetrics(tutils.GetMockEnv(), &config.Config{})
assert.Equal(t, []string{}, pluginUnderTest.Subscriptions())
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.